Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

typed-function

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typed-function - npm Package Versions

234

4.2.1

Diff

Changelog

Source

2024-06-05, version 4.2.1

  • Fix a bug in the new override option of method addConversion.
josdejong
published 4.2.0 •

Changelog

Source

2024-06-05, version 4.2.0

  • Extend methods addConversion and addConversions with a new option { override: boolean } to allow overriding an existing conversion.
josdejong
published 4.1.1 •

Changelog

Source

2023-09-13, version 4.1.1

  • Fix #168: add a "license": "MIT" field to the package.json file.
josdejong
published 4.1.0 •

Changelog

Source

2022-08-23, version 4.1.0

  • Publish an UMD version of the library, like in v3.0.0. It is still necessary. The UMD version can be used in CommonJS applications and in the browser.
josdejong
published 4.0.0 •

Changelog

Source

2022-08-22, version 4.0.0

!!! BE CAREFUL: BREAKING CHANGES !!!

  • Breaking change: the code is converted into ES modules, and the library now outputs ES modules only instead of an UMD module.
    • If you're using typed-function inside and ES modules project, all will just keep working like before:
      import typed from 'typed-function'
      
    • If you're using typed-function in a CommonJS project, you'll have to import the library using a dynamic import:
      const typed = (await import('typed-function')).default
      
    • If you're importing typed-function straight into a browser page, you can load it as a module there:
      <script type="module">
        import typed from 'typed-function/lib/esm/typed-function.mjs'
      </script>
      
josdejong
published 3.0.1 •

Changelog

Source

2022-08-16, version 3.0.1

  • Fix #157: typed() can enter infinite loop when there is both referToSelf
    and referTo functions involved (#158). Thanks @gwhitney.
  • Fix #155: typed.addType() fails if there is no Object type (#159). Thanks @gwhitney.
josdejong
published 3.0.0 •

Changelog

Source

2022-05-12, version 3.0.0

!!! BE CAREFUL: BREAKING CHANGES !!!

Breaking changes:

  • Fix #14: conversions now have preference over any. Thanks @gwhitney.

  • The properties typed.types and typed.conversions have been removed. Instead of adding and removing types and conversions with those arrays, use the methods addType, addTypes, addConversion, addConversions, removeConversion, clear, clearConversions.

  • The this variable is no longer bound to the typed function itself but is unbound. Instead, use typed.referTo(...) and typed.referToSelf(...).

    By default, all function bodies will be scanned against the deprecated usage pattern of this, and an error will be thrown when encountered. To disable this validation step, set typed.warnAgainstDeprecatedThis = false.

    Example:

    // old:
    const square = typed({
      'number': x => x * x,
      'string': x => this(parseFloat(x))
    })
    
    // new:
    const square = typed({
      'number': x => x * x,
      'string': typed.referToSelf(function (self) {
        // using self is not optimal, if possible,  
        // refer to a specific signature instead, 
        // see next example
        return x => self(parseFloat(x))
      })
    })
    
    // optimized new:
    const square = typed({
      'number': x => x * x,
      'string': typed.referTo('number', function (squareNumber) {
        return x => sqrtNumber(parseFloat(x))
      })
    })
    
  • The property typed.ignore is removed. If you need it, see if you can create a new typed instance without the types that you want to ignore, or filter the signatures passed to typed() by hand.

  • Drop official support for Nodejs 12.

Non-breaking changes:

  • Implemented new static functions, Thanks @gwhitney:
    • typed.referTo(...string, callback: (resolvedFunctions: ...function) => function)
    • typed.referToSelf(callback: (self) => function)
    • typed.isTypedFunction(entity: any): boolean
    • typed.resolve(fn: typed-function, argList: Array<any>): signature-object
    • typed.findSignature(fn: typed-function, signature: string | Array, options: object) : signature-object
    • typed.addType(type: {name: string, test: function, ignored?: boolean} [, beforeObjectTest=true]): void
    • typed.addTypes(types: TypeDef[] [, before = 'any']): void
    • typed.clear(): void
    • typed.addConversions(conversions: ConversionDef[]): void
    • typed.removeConversion(conversion: ConversionDef): void
    • typed.clearConversions(): void
  • Refactored the typed constructor to be more flexible, accepting a combination of multiple typed functions or objects. And internally refactored the constructor to not use typed-function itself (#142). Thanks @gwhitney.
  • Extended the benchmark script and added counting of creation of typed functions (#146).
  • Fixes and extensions to typed.find() now correctly handling cases with rest or any parameters and matches requiring conversions; adds an options argument to control whether matches with conversions are allowed. Thanks @gwhitney.
  • Fix to typed.convert(): Will now find a conversion even in presence of overlapping types.
  • Reports all matching types in runtime errors, not just the first one.
  • Improved documentation. Thanks @gwhitney.
josdejong
published 2.1.0 •

Changelog

Source

2022-03-11, version 2.1.0

  • Implemented configurable callbacks typed.createError and typed.onMismatch. Thanks @gwhitney.
josdejong
published 2.0.0 •

Changelog

Source

2020-07-03, version 2.0.0

  • Drop official support for node.js 6 and 8, though no breaking changes at this point.
  • Implemented support for recursion using the this keyword. Thanks @nickewing.
josdejong
published 1.1.1 •

Changelog

Source

2019-08-22, version 1.1.1

  • Fix #15: passing null to an Object parameter throws wrong error.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc