{"library":"should-type-adaptors","title":"Should.js Type Adaptors","description":"The `should-type-adaptors` library (current stable version 1.1.0) provides low-level utility functions specifically designed to enhance the `should.js` BDD-style assertion library. Its core purpose is to enable consistent deep comparison, property traversal, and accurate type inspection across diverse JavaScript data structures, particularly those that might deviate from standard object or array behaviors. The library allows for the registration of custom type adaptors, facilitating intelligent handling of complex, custom, or \"adapted\" types during `should.js` assertions. Maintained as part of the `should.js` ecosystem, its latest updates were for dependency management, suggesting it is in a maintenance state rather than active development. Its key differentiator is offering an extensible mechanism for `should.js` to correctly interpret and assert against non-standard or complex type structures.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install should-type-adaptors"],"cli":null},"imports":["import { addTypeAdaptor } from 'should-type-adaptors';","import { convert } from 'should-type-adaptors';","import { isAdapted } from 'should-type-adaptors';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import should from 'should';\nimport { addTypeAdaptor } from 'should-type-adaptors';\n\n// Define a custom class\nclass MyCustomType {\n  constructor(id, value) {\n    this.customId = id;\n    this.data = value;\n  }\n\n  // A method that might be important for comparison\n  getFormattedData() {\n    return `ID: ${this.customId}, Data: ${this.data}`;\n  }\n}\n\n// Register a type adaptor for MyCustomType to define how 'should.js' should compare it\n// This adaptor tells should.js to use 'getFormattedData' for deep comparisons.\naddTypeAdaptor(MyCustomType, {\n  valueOf: (instance) => instance.getFormattedData(),\n  // You can also define custom 'eql' or 'inspect' methods here\n  // eql: (a, b) => a.customId === b.customId && a.data === b.data,\n  // inspect: (instance, level) => `MyCustomType { id: ${instance.customId}, data: '${instance.data}' }`\n});\n\nconst instance1 = new MyCustomType(1, 'hello');\nconst instance2 = new MyCustomType(1, 'hello');\nconst instance3 = new MyCustomType(2, 'world');\n\n// Now should.js can compare custom types based on their adapted value\nshould(instance1).eql(instance2); // This assertion will pass because valueOf makes them deeply equal\nshould(instance1).not.eql(instance3); // This assertion will pass\n\nconsole.log('Assertions passed successfully!');\n\n// Example of direct usage of convert (less common)\n// import { convert } from 'should-type-adaptors';\n// const convertedValue = convert(instance1); // Will be 'ID: 1, Data: hello'\n// console.log(convertedValue);","lang":"typescript","description":"This quickstart demonstrates how to register a custom type adaptor for a user-defined class (`MyCustomType`) with `should-type-adaptors`. It configures `should.js` to use a custom `valueOf` method for deep comparisons, enabling robust assertions on complex objects. This is typically how `should-type-adaptors` extends `should.js`'s capabilities.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}