{"id":12023,"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.","status":"maintenance","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/shouldjs/type-adaptors","tags":["javascript","shouldjs","type"],"install":[{"cmd":"npm install should-type-adaptors","lang":"bash","label":"npm"},{"cmd":"yarn add should-type-adaptors","lang":"bash","label":"yarn"},{"cmd":"pnpm add should-type-adaptors","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primarily designed for CommonJS (`require`), but bundlers can often handle ESM import. Explicit `require` is safer for older Node.js environments.","wrong":"const { addTypeAdaptor } = require('should-type-adaptors');","symbol":"addTypeAdaptor","correct":"import { addTypeAdaptor } from 'should-type-adaptors';"},{"note":"Used for converting values using registered adaptors. Less common for direct user invocation than `addTypeAdaptor`.","wrong":"const { convert } = require('should-type-adaptors');","symbol":"convert","correct":"import { convert } from 'should-type-adaptors';"},{"note":"Checks if a specific type has an adaptor registered. Like `convert`, it's a utility for deeper integration, not typical end-user assertion.","wrong":"const { isAdapted } = require('should-type-adaptors');","symbol":"isAdapted","correct":"import { isAdapted } from 'should-type-adaptors';"}],"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."},"warnings":[{"fix":"Focus on integrating `should-type-adaptors` with `should.js` via `should.use()` or by directly calling its utility functions to augment existing assertion behavior, rather than using its exports as standalone assertion methods.","message":"This package (`should-type-adaptors`) is a low-level utility for `should.js` and is not typically used for direct assertions. Its functions are primarily intended to extend or modify how `should.js` processes different data types during its own assertion logic.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For compatibility across all Node.js environments, use `const { addTypeAdaptor } = require('should-type-adaptors');` or ensure your project's build setup correctly transpiles or handles CommonJS modules when using ESM `import`.","message":"The package's `package.json` does not specify `\"type\": \"module\"`, indicating it is primarily a CommonJS module. While modern bundlers can often handle ESM imports, direct usage in Node.js without specific configuration might require `require()`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Evaluate if the functionality is still required or if `should.js` itself (or other `should.js` plugins) has incorporated similar capabilities. Be prepared for minimal future feature development or breaking changes in upstream `should.js` that might not be immediately reflected here.","message":"The `should-type-adaptors` package has seen infrequent updates, with its last commit related to dependency updates in late 2019. While it remains functional within the `should.js` ecosystem, active development on this specific utility has significantly slowed.","severity":"deprecated","affected_versions":"<=1.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[],"ecosystem":"npm"}