typed-function
Advanced tools
Changelog
2024-06-05, version 4.2.1
override
option of method addConversion
.Changelog
2024-06-05, version 4.2.0
addConversion
and addConversions
with a new option
{ override: boolean }
to allow overriding an existing conversion.Changelog
2023-09-13, version 4.1.1
"license": "MIT"
field to the package.json
file.Changelog
2022-08-23, version 4.1.0
Changelog
2022-08-22, version 4.0.0
!!! BE CAREFUL: BREAKING CHANGES !!!
typed-function
inside and ES modules project,
all will just keep working like before:
import typed from 'typed-function'
typed-function
in a CommonJS project, you'll have to
import the library using a dynamic import:
const typed = (await import('typed-function')).default
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>
Changelog
2022-08-16, version 3.0.1
typed()
can enter infinite loop when there is both referToSelf
referTo
functions involved (#158). Thanks @gwhitney.typed.addType()
fails if there is no Object
type (#159).
Thanks @gwhitney.Changelog
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:
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
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.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.typed.convert()
: Will now find a conversion even in presence of
overlapping types.Changelog
2022-03-11, version 2.1.0
typed.createError
and typed.onMismatch
.
Thanks @gwhitney.Changelog
2020-07-03, version 2.0.0
this
keyword. Thanks @nickewing.