- Fix a bug in the new
override
option of methodaddConversion
.
- Extend methods
addConversion
andaddConversions
with a new option{ override: boolean }
to allow overriding an existing conversion.
- Fix #168: add a
"license": "MIT"
field to thepackage.json
file.
- 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.
!!! 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>
- If you're using
- Fix #157:
typed()
can enter infinite loop when there is bothreferToSelf
andreferTo
functions involved (#158). Thanks @gwhitney. - Fix #155:
typed.addType()
fails if there is noObject
type (#159). Thanks @gwhitney.
!!! BE CAREFUL: BREAKING CHANGES !!!
Breaking changes:
-
Fix #14: conversions now have preference over
any
. Thanks @gwhitney. -
The properties
typed.types
andtyped.conversions
have been removed. Instead of adding and removing types and conversions with those arrays, use the methodsaddType
,addTypes
,addConversion
,addConversions
,removeConversion
,clear
,clearConversions
. -
The
this
variable is no longer bound to the typed function itself but is unbound. Instead, usetyped.referTo(...)
andtyped.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, settyped.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 newtyped
instance without the types that you want to ignore, or filter the signatures passed totyped()
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 orany
parameters and matches requiring conversions; adds anoptions
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.
- Implemented configurable callbacks
typed.createError
andtyped.onMismatch
. Thanks @gwhitney.
- 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.
- Fix #15: passing
null
to anObject
parameter throws wrong error.
- Implemented support for creating typed functions from a plain function
having a property
signature
. - Implemented providing a name when merging multiple typed functions.
- By default,
addType
will insert new types before theObject
test since theObject
test also matches arrays and classes. - Upgraded
devDependencies
.
- Dropped usage of ES6 feature
Array.find
, so typed-function is directly usable on any ES5 compatible JavaScript engine (like IE11).
- Fixed typed-function not working on browsers that don't allow
setting the
name
property of a function.
- Upgraded dev dependencies.
Version 1.0.0 is rewritten from scratch. The API is the same, though generated error messages may differ slightly.
Version 1.0.0 no longer uses eval
under the hood to achieve good
performance. This reduces security risks and makes typed-functions
easier to debug.
Type Object
is no longer treated specially from other types. This
means that the test for Object
must not give false positives for
types like Array
, Date
, or class instances.
In version 1.0.0, support for browsers like IE9, IE10 is dropped, though typed-function can still work when using es5 and es6 polyfills.
- Fixed the field
data.actual
in aTypeError
message containing the type index instead of the actual type of the argument.
- Fixed a security issue allowing to execute arbitrary JavaScript code via a specially prepared function name of a typed function. Thanks Masato Kinugawa.
- Fixed the use of multi-layered use of
any
type. See #8.
- Typed functions can only inherit names from other typed functions and no longer from regular JavaScript functions since these names are unreliable: they can be manipulated by minifiers and browsers.
- Reverted the fix of v0.10.2 until the introduced issue with variable arguments is fixed too. Added unit test for the latter case.
- Fixed support for using
any
multiple times in a single signture. Thanks @luke-gumbley.
- Fixed functions
addType
andaddConversion
not being robust against replaced arraystyped.types
andtyped.conversions
.
- Dropped support for the following construction signatures in order to simplify
the API:
typed(signature: string, fn: function)
typed(name: string, signature: string, fn: function)
- Implemented convenience methods
typed.addType
andtyped.addConversion
. - Changed the casing of the type
'function'
to'Function'
. Breaking change. typed.types
is now an ordered Array containing objects{name: string, test: function}
. Breaking change.- List with expected types in error messages no longer includes converted types.
typed.types
is now an ordered Array containing objects{type: string, test: function}
instead of an object. Breaking change.typed-function
now allows merging typed functions with duplicate signatures when they point to the same function.
- Function
typed.find
now throws an error instead of returningnull
when a signature is not found. - Fixed: the attached signatures no longer contains signatures with conversions.
- Fixed function
typed.convert
not handling the case where the value already has the requested type. Thanks @rjbaucells.
- Implemented option
typed.ignore
to ignore/filter signatures of a typed function.
- Implemented function
create
to create a new instance of typed-function. - Implemented a utility function
convert(value, type)
(#1). - Implemented a simple
typed.find
function to find the implementation of a specific function signature. - Extended the error messages to denote the function name, like
"Too many arguments in function foo (...)"
.
- Performance improvements.
- Fixed generated internal Signature and Param objects not being cleaned up after the typed function has been generated.
- Fixed a bug sometimes not ordering the handling of any type arguments last.
- Fixed a bug sometimes not choosing the signature with the lowest number of conversions.
- Large code refactoring.
- Fixed bugs related to any type parameters.
- Removed the configuration option
minify
(it's not clear yet whether minifying really improves the performance). - Internal code simplifications.
- Bug fixes.
- Implemented support for merging typed functions.
- Typed functions inherit the name of the function in case of one signature.
- Fixed a bug where a regular argument was not matched when there was a signature with variable arguments too.
- Slightly changed the error messages.
- Introduced new constructor options, create a typed function as
typed([name,] signature, fn)
ortyped([name,] signatures)
. - Support for multiple types per parameter like
number | string, number'
. - Support for variable parameters like
sting, ...number'
. - Changed any type notation
'*'
to'any'
. - Implemented detailed error messages.
- Implemented option
typed.config.minify
.
- Renamed module to
typed-function
.
- Implemented support for any type arguments (denoted with
*
).
- Implemented support for named functions.
- Implemented support for type conversions.
- Implemented support for custom types.
- Library packaged as UMD, usable with CommonJS (node.js), AMD, and browser globals.
- Implemented support for functions with zero, one, or multiple arguments.
- First release (no functionality yet)