Releases: perfective/ts.common
v0.11.0
Fixed ES modules imports
@perfective/common can now be imported from regular .js/.mjs ESM files.
Added wrappers for most of the Math functions (#20)
Unlike the standard Math functions, the following functions throw an Exception for invalid inputs:
absolute()arccos(),arccosh()arcsin(),arcsinh()arctan(),arctan2(),arctanh()cos(),cosh()sin(),sinh()tan(),tanh()rounded(),roundedUp(),roundedDown(),roundedToFloat32(),truncated()power(),powerOf()squareRoot(),cubeRoot(),l2norm()exp(),expm1()log(),log10(),log1p(),log2()sign()with theSignnominal type
Replacing NaN with null is a redundant idea, because it’s trivial to use library functions with Maybe instead:
maybe(x).to(Math.acos).that(isNumber)Meanwhile, throwing an exception gives library users an option to track invalid inputs.
In this case, the Result monad can be used:
result(x).onto(resultFrom(arccos))Added more nominal types for numbers
- Added the
Infinity,PositiveInfinity, andNegativeInfinitynominal types with theisInfinity()type guard. - Added the
FiniteNumbernominal type with theisFinite()type guard (#18) andassertIsFinite()assertion. - Added the
PositiveNumber,NonPositiveNumber,NegativeNumber,NonNegativeNumbernominal types. - Added the
assertIsNonNegativeNumber()type guard.
Introduced assertion functions
- Added the
assertIsNotNaN()(#53) andassertIsNonNegativeNumber()functions. - Added the
typeException()function.
v0.10.0
Read the release announcement in the Perfective blog.
@perfective/common/result
- Added the
Result.that()filter method. - Added the
Result.which()type-guard method. - Added the
Result.when()filter method. - Added the
Result.or()fold method. - Added the
Result.otherwise()recovery method.- Deprecated the
recovery()function.
- Deprecated the
- [Breaking] Changed the
resultFrom()to usetry-catchinstead of theT | Errorunion type. This makes the function behavior safer and allows wider usage.
New @perfective/common/date package
- Added functions for the
Dateclass:- Added
date(),now(), andepoch()Dateconstructors. - Added
isValid()/isInvalid()Datepredicates.
- Added
- Added
Timestamptype.- Added
timestamp()constructor.
- Added
Restructured Roadmap
ROADMAP.adoc now contains all built-in objects with their properties and methods. Some of the methods and properties already have a matching Perfective function, and some are marked as prohibited (e.g. eval) or not supported.
The Roadmap will document minimum support to tag @perfective/common v1.0.
Breaking changes
- Dropped Node.js v16.x support, as it is no longer supported.
- Removed deprecated functions and types:
@perfective/common/array:arrayFromArrayLike(),arrayFromIterable(),flatten().
@perfective/common/match:Match.that(),Match.to();Statement,StatementEntry,statements();When.then().
@perfective/common/maybe:Maybe.lift()/lift(),Maybe.run()/run();Nullable,Nil,Only/Solum,nullable(),nil(),only()/solum();Optional,None,Some,optional(),none(),some().
@perfective/common/promise:Run,result().
@perfective/common/string:Output,isNotOutput(),isOutput(),output().
Improvements
@perfective/common/boolean:- Added JsDocs for all types and functions.
- Added ES Coverage documentation for the
Booleantype. - Added the
isBoolean()/isNotBoolean()predicates. - Moved the
isTruthy()/isFalsy()functions from@perfective/common/object.
@perfective/common/error:- Added
Recoverytype. - Added JsDocs for all types and functions.
- Added support for
cause(previous) error to thePanictype andpanic()function.
- Added
@perfective/common/maybe:- Changed the
nothing()/nil()functions return type toNothing<Present<T>>for TypeScript v5.3 compatibility.
- Changed the
@perfective/common/object:- Added JsDocs for all types and functions.
@perfective/common/string:- Fixed
lines()function: Use correct separator for Mac OS strings. - Deprecated the
stringFromCharCode()andstringFromCodePoint()functions.
Use theString.fromCharCode()andString.fromCodePoint()functions directly.
- Fixed
Deprecations
@perfective/common/function:- Deprecated the
emtpy()function. Usenaught()as an empty no-op function instead.
- Deprecated the
@perfective/common/error:- Deprecated the
Rethrowtype. UsePanicinstead. - Deprecated the
rethrow()function. Usepanic()instead. - Renamed the
unknownError()function intocaughtError().
- Deprecated the
@perfective/common/maybe:- Renamed the
naught()function intonil().
- Renamed the
@perfective/common/object:- Moved the
isTruthy()/isFalsy()functions into@perfective/common/boolean.
- Moved the
@perfective/common/result:- Deprecated the
recovery()function. UseResult.otherwise()instead.
- Deprecated the
v0.10.0-rc
- Added JSDocs for all functions and types.
- Updated the roadmap to cover all existing packages.
@perfective/common/date:- Supported string input parsing in the
timestamp()function.
- Supported string input parsing in the
@perfective/common/string:- Fixed
lines()function: using correct separator (\r) for Mac OS strings. - Deprecated the
stringFromCharCode()andstringFromCodePoint()functions. Use theString.fromCharCode()andString.fromCodePoint()functions directly.
- Fixed
v0.10.0-beta
New @perfective/common/date package
- Added functions for the
Dateclass:- Added
date(),now(), andepoch()Dateconstructors. - Added
isValid()/isInvalid()Datepredicates.
- Added
- Added
Timestamptype.- Added
timestamp()constructor.
- Added
Restructured Roadmap
ROADMAP.adoc now contains all built-in objects with their properties and methods. Some of the methods and properties already have a matching Perfective function, and some are marked as prohibited (e.g. eval) or not supported.
The Roadmap will document minimum support to tag @perfective/common v1.0.
v0.10.0-alpha
@perfective/common/result
- Added the
Result.that()filter method. - Added the
Result.which()type-guard method. - Added the
Result.when()filter method. - Added the
Result.or()fold method. - Added the
Result.otherwise()recovery method.- Deprecated the
recovery()function.
- Deprecated the
- [Breaking] Changed the
resultFrom()to usetry-catchinstead of theT | Errorunion type.
This makes the function behavior safer and allows wider usage.
Breaking changes
- Removed deprecated functions and types:
@perfective/common/array:arrayFromArrayLike(),arrayFromIterable(),flatten().
@perfective/common/match:Match.that(),Match.to();Statement,StatementEntry,statements();When.then().
@perfective/common/maybe:Maybe.lift()/lift(),Maybe.run()/run();Nullable,Nil,Only/Solum,nullable(),nil(),only()/solum();Optional,None,Some,optional(),none(),some().
@perfective/common/promise:Run,result().
@perfective/common/string:Output,isNotOutput(),isOutput(),output().
Deprecations
@perfective/common/function:- Deprecated the
emtpy()function.
Usenaught()as an empty no-op function instead.
- Deprecated the
@perfective/common/error:- Deprecated the
Rethrowtype. UsePanicinstead. - Deprecated the
rethrow()function. Usepanic()instead. - Renamed the
unknownError()function intocaughtError().
- Deprecated the
@perfective/common/maybe:- Renamed the
naught()function intonil().
- Renamed the
@perfective/common/object:- Moved the
isTruthy()/isFalsy()functions into@perfective/common/boolean.
- Moved the
@perfective/common/result:- Deprecated the
recovery()function.
UseResult.otherwise()instead.
- Deprecated the
Improvements
@perfective/common/boolean:- Added JsDocs for all types and functions.
- Added ES Coverage documentation for the
Booleantype. - Added the
isBoolean()/isNotBoolean()predicates. - Moved the
isTruthy()/isFalsy()functions from@perfective/common/object.
@perfective/common/error:- Added
Recoverytype. - Added JsDocs for all types and functions.
- Added support for
cause(previous) error to thePanictype andpanic()function.
- Added
@perfective/common/object:- Added JsDocs for all types and functions.
v0.9.0
Changes since v0.8.3.
New @perfective/common/result package
- Added the
Result<T>monad type withSuccess<T>andFailure<T>implementations.- Added the
result(),success(), andfailure()constructors. - Added the
resultOf()lazy constructor. - Added the
resultFrom(),successFrom(), andfailureFrom()functions. - Added the
recovery()function. - Added the
rejection()constructor for rejectedPromisehandling. - Added the
promisedResult()andsettledResult()async functions. - Added the
onto(),to(),into(), andthrough()lifting functions. - Added type guards:
isResult()/isNotResult(),isSuccess()/isNotSuccess(),- and
isFailure()/isNotFailure().
- Added the
- Added the
BiMapResult<T, U>type for theResult.to(maps)method:- Added the
successWith()andfailureWith()BiMapResultconstructors.
- Added the
- Added the
BiFoldResult<T, U>type for theResult.into(fold)method. - Added the
BiVoidResult<T>type for theResult.through(procedures)method.
Breaking changes
@perfective/common/function:- Changed the
same()function into a unary function.
To migrate:- replace calls passing the
sameas an argument withconstant(same); - replace calls of the
same()with justsame.
- replace calls passing the
- Changed the
@perfective/common/object:- Narrowed argument to the
NonNullabletype in the:pick()/recordWithPicked(),omit()/recordWithOmitted(),- and
filter()/recordFiltered()functions.
- Narrowed argument to the
Deprecations
@perfective/common/array:- Merged the
flatten()function into theconcatenated()function. - Merged the
arrayFromIterable()andarrayFromArrayLike()functions into the newelements()function.
- Merged the
@perfective/common/match:- Renamed the
Match.that()andMatch.to()methods intoMatch.cases(). - Renamed the
When.then()method intoWhen.to(). - Renamed the
Statementtype intoCase. - Renamed the
StatementEntrytype intoCaseEntry. - Renamed the
statements()function intofromEntries().
- Renamed the
@perfective/common/maybe:- Renamed the
Maybe.run()method into theMaybe.through()method. - Deprecated the
NullableandOptionaltypes.
Both types cover specific edge cases for theMaybetype.
But they have not been used in real-world applications.
Use cases that these types covered can be handled byMaybe,
so there is no good reason to maintain them.- Deprecated
nil(),nullable(),only(), andsolum()functions. - Deprecated
none(),optional(), andsome()functions. - Deprecated
lift()function.
- Deprecated
- Deprecated the
Maybe.lift()method.
Use theMaybe.into()method with themaybeFrom()function instead.
- Renamed the
@perfective/common/promise:- Renamed the
Runtype intoExecutor.
ECMA specification uses the termexecutor. - Renamed the
result()function intosettlement().
- Renamed the
@perfective/common/string:- Deprecated the
Outputinterface. - Deprecated the
output(),isOutput(), andisNotOutput()functions.
Use theString()function for native string coercion instead.
- Deprecated the
Improvements
-
Removed mock files from the distribution.
mock.tsfiles are only imported in tests. -
@perfective/common:- Added support of abstract classes to the
isInstanceOf()/isNotInstanceOf()type guards. - Added the
Voidable<T>type. - Added the
ecmaType()andisEcmaType()functions. - Added the
tsType()andisTsType()functions. - Added the
present(),notNull(), anddefined()functions. - Set
Present<T>as theisPresent()function return value. - Set
Defined<T>as theisDefined()function return value. - Set
NotNull<T>as theisNotNull()function return value.
- Added support of abstract classes to the
-
@perfective/common/array:- Added the
pushInto()function.
- Added the
-
@perfective/common/error:- Fixed the
Exceptionclass prototype for
the ES5 compilation. - Added the
chained()function. - Included a non-error value output into an
unknownError()message.
- Fixed the
-
@perfective/common/function:- Added the
BiMap<T1, U1, T2, V2>arguments pair type. - Added the
BiFold<T1, T2, U>arguments pair type. - Added the
VoidandUnaryVoid<T>procedure types.
- Added the
-
@perfective/common/match:- Added the
caseFromEntry()function.
- Added the
-
@perfective/common/maybe:- Added
Maybe.into(reduce)method andinto(reduce)function. - Added
maybeFrom()andjustFrom()functions. - Narrowed signatures for the
maybe()function.
When a function is given an always present value, it will returnJust<T>,
and for always absent values, it will returnNothing<T>.
Otherwise, theMaybetype is compiled as an interface and cannot be checked with theinstance ofin runtime. - Added JSDocs for the
Maybetype methods. - Changed error messages for absent values in
Just. - Switch to
extendsinstead ofimplementsinMaybe - Added type guards:
isMaybe()/isNotMaybe(),isJust()/isNotJust(),- and
isNothing()/isNotNothing().
- Added
-
@perfective/common/object:- Added the
hasMethod()andhasNoMethod()functions. - Changed the
isRecord()predicate to be a type guard. - Marked property definition in the
ObjectWithUndefinedtype as optional.
Required to work withexactOptionalPropertyTypes: true.
Otherwise, an object with a never defined property cannot be assigned to an object with a property set to
undefined.
The type guard is not yet strict enough, but it is better than just a predicate.
- Added the
-
@perfective/common/promise:- Added the
Resolvableshortcut type. - Added the
OnFulfilledandOnRejectedtypes. - Added the
fulfilled()andrejected()functions. - Added the
settled()function.
- Added the
v0.9.0-rc
- Updated documentation.
v0.9.0-beta
Deprecations
@perfective/common/array:- Merged the
flatten()function into theconcatenated()function. - Merged the
arrayFromIterable()andarrayFromArrayLike()functions into the newelements()function.
- Merged the
@perfective/common/maybe:- Renamed the
Maybe.run()method into theMaybe.through()method.
- Renamed the
Improvements
@perfective/common:- Added support of abstract classes to the
isInstanceOf()/isNotInstanceOf()type guards.
- Added support of abstract classes to the
@perfective/common/error:- Fixed the
Exceptionclass prototype for
the ES5 compilation.
- Fixed the
@perfective/common/maybe:- Added the
isMaybe()/isNotMaybe(),isJust()/isNotJust(), andisNothing()/isNotNothing()type guards.
- Added the
@perfective/common/result:- Added the
onto(),to(),into(), andthrough()lifting functions. - Added the
isResult()/isNotResult(),isSuccess()/isNotSuccess(),andisFailure()/isNotFailure()type guards.
- Added the
v0.9.0-alpha
New @perfective/common/result package
- Added the
Result<T>monad type withSuccess<T>andFailure<T>implementations.- Added the
result(),success(), andfailure()constructors. - Added the
resultOf()lazy constructor. - Added the
resultFrom(),successFrom(), andfailureFrom()functions. - Added the
recovery()function. - Added the
rejection()constructor for rejectedPromisehandling. - Added the
promisedResult()andsettledResult()async functions.
- Added the
- Added the
BiMapResult<T, U>type for theResult.to(maps)method:- Added the
successWith()andfailureWith()BiMapResultconstructors.
- Added the
- Added the
BiFoldResult<T, U>type for theResult.into(fold)method. - Added the
BiVoidResult<T>type for theResult.through(procedures)method.
Breaking changes
@perfective/common/function:- Changed the
same()function into a unary function.
To migrate:- replace calls passing the
sameas an argument withconstant(same); - replace calls of the
same()with justsame.
- replace calls passing the
- Changed the
@perfective/common/object:- Narrowed argument to the
NonNullabletype in thepick()/recordWithPicked(),omit()/recordWithOmitted(), andfilter()/recordFiltered()functions.
- Narrowed argument to the
Deprecations
@perfective/common/match:- Renamed the
Match.that()andMatch.to()methods intoMatch.cases(). - Renamed the
When.then()method intoWhen.to(). - Renamed the
Statementtype intoCase. - Renamed the
StatementEntrytype intoCaseEntry. - Renamed the
statements()function intofromEntries().
- Renamed the
@perfective/common/maybe:- Deprecated the
NullableandOptionaltypes.
Both types cover specific edge cases for theMaybetype.
But they have not been used in real-world applications.
Use cases that these types covered can be handled byMaybe,
so there is no good reason to maintain them.- Deprecated
nil(),nullable(),only(), andsolum()functions. - Deprecated
none(),optional(), andsome()functions. - Deprecated
lift()function.
- Deprecated
- Deprecated the
Maybe.lift()method.
Use theMaybe.into()method with themaybeFrom()function instead.
- Deprecated the
@perfective/common/promise:- Renamed the
Runtype intoExecutor.
ECMA specification uses the termexecutor. - Renamed the
result()function intosettlement().
- Renamed the
@perfective/common/string:- Deprecated the
Outputinterface. - Deprecated the
output(),isOutput(), andisNotOutput()functions.
Use theString()function for native string coercion instead.
- Deprecated the
Improvements
- Removed mock files from the distribution.
mock.tsfiles are only imported in tests. @perfective/common:- Added the
Voidable<T>type. - Added the
ecmaType()andisEcmaType()functions. - Added the
tsType()andisTsType()functions. - Added the
present(),notNull(), anddefined()functions. - Set
Present<T>as theisPresent()function return value. - Set
Defined<T>as theisDefined()function return value. - Set
NotNull<T>as theisNotNull()function return value.
- Added the
@perfective/common/array:- Added the
pushInto()function.
- Added the
@perfective/common/error:- Added the
chained()function. - Included a non-error value output into an
unknownError()message.
- Added the
@perfective/common/function:- Added the
BiMap<T1, U1, T2, V2>arguments pair type. - Added the
BiFold<T1, T2, U>arguments pair type. - Added the
VoidandUnaryVoid<T>procedure types.
- Added the
@perfective/common/match:- Added the
caseFromEntry()function.
- Added the
@perfective/common/maybe:- Added
Maybe.into(reduce)method andinto(reduce)function. - Added
maybeFrom()andjustFrom()functions. - Narrowed signatures for the
maybe()function.
When a function is given an always present value, it will returnJust<T>,
and for always absent values, it will returnNothing<T>. - Added JSDocs for the
Maybetype methods. - Changed error messages for absent values in
Just. - Switch to
extendsinstead ofimplementsinMaybe
Otherwise, theMaybetype is compiled as an interface and cannot be checked with theinstance ofin runtime.
- Added
@perfective/common/object:- Added the
hasMethod()andhasNoMethod()functions. - Changed the
isRecord()predicate to be a type guard. - Marked property definition in the
ObjectWithUndefinedtype as optional.
Required to work withexactOptionalPropertyTypes: true.
Otherwise, an object with a never defined property cannot be assigned to an object with a property set to undefined.
The type guard is not yet strict enough, but it is better than just a predicate.
- Added the
@perfective/common/promise:- Added the
Resolvableshortcut type. - Added the
OnFulfilledandOnRejectedtypes. - Added the
fulfilled()andrejected()functions. - Added the
settled()function.
- Added the
v0.8.3
- Update
@perfective/common/maybepackage documentation.