typescript-is
Advanced tools
Comparing version 0.12.3 to 0.12.4
/** | ||
* Checks if the given argument is assignable to the given type-argument. | ||
* | ||
* | ||
* @param object object whose type needs to be checked. | ||
@@ -16,5 +16,5 @@ * @returns `true` if `object` is assignable to `T`, false otherwise. | ||
* Creates a function similar to `is<T>` that can be invoked at a later point. | ||
* | ||
* | ||
* This is useful, for example, if you want to re-use the function multiple times. | ||
* | ||
* | ||
* @example | ||
@@ -32,3 +32,3 @@ ``` | ||
* Superfluous properties will cause the validation to fail. | ||
* | ||
* | ||
* @param object object whose type needs to be checked. | ||
@@ -47,5 +47,5 @@ * @returns `true` if `object` is assignable to `T` and if `T` is "assignable" to `object`, false otherwise. | ||
* Creates a function similar to `equals<T>` that can be invoked at a later point. | ||
* | ||
* | ||
* This is useful, for example, if you want to re-use the function multiple times. | ||
* | ||
* | ||
* @example | ||
@@ -64,3 +64,3 @@ ``` | ||
* If the given argument is not assignable to the given type-argument, an error will be thrown. | ||
* | ||
* | ||
* @param object object whose type will be asserted. | ||
@@ -78,5 +78,5 @@ * @returns the given `object`, or an error is thrown if validation failed. | ||
* Creates a function similar to `assertType<T>` that can be invoked at a later point. | ||
* | ||
* | ||
* This is useful, for example, if you want to re-use the function multiple times. | ||
* | ||
* | ||
* @example | ||
@@ -96,3 +96,3 @@ ``` | ||
* Superfluous properties will cause the validation to fail. | ||
* | ||
* | ||
* @param object object whose type will be asserted. | ||
@@ -110,5 +110,5 @@ * @returns the given `object`, or an error is thrown if validation failed. | ||
* Creates a function similar to `assertEquals<T>` that can be invoked at a later point. | ||
* | ||
* | ||
* This is useful, for example, if you want to re-use the function multiple times. | ||
* | ||
* | ||
* @example | ||
@@ -136,6 +136,6 @@ ``` | ||
* Then, when the class is decorated with `ValidateClass`, the method's arguments will be validated. | ||
* | ||
* | ||
* @param options options for the decorator. | ||
* Check `AssertTypeOptions` documentation for more information. | ||
* | ||
* | ||
* @example | ||
@@ -153,3 +153,3 @@ * ``` | ||
* Overrides methods in the target class with a proxy that will first validate the argument types. | ||
* | ||
* | ||
* @param errorConstructor a constructor of an `Error` class. | ||
@@ -171,3 +171,3 @@ * This will be used to create an error when validation fails. | ||
* By default, a class decorated with `@ValidateClass` will also throw errors of this class, unless it's overriden using the options. | ||
* | ||
* | ||
* @example | ||
@@ -179,3 +179,3 @@ * ``` | ||
} | ||
// Somewhere higher up the call stack: | ||
@@ -192,1 +192,8 @@ try { | ||
export class TypeGuardError extends Error { } | ||
/** | ||
* Set default getErrorMessage function used for transpiled source. | ||
* | ||
* @param getErrorMessage | ||
*/ | ||
export function setDefaultGetErrorMessage(getErrorMessage?: () => string | null): void; |
17
index.js
@@ -0,1 +1,3 @@ | ||
let defaultGetErrorMessage = () => null; | ||
function checkGetErrorMessage(getErrorMessage) { | ||
@@ -46,3 +48,3 @@ if (typeof getErrorMessage !== 'function') { | ||
function is(obj, getErrorMessage) { | ||
function is(obj, getErrorMessage = defaultGetErrorMessage) { | ||
checkGetErrorMessage(getErrorMessage); | ||
@@ -53,3 +55,3 @@ const errorMessage = getErrorMessage(obj); | ||
function assertType(obj, getErrorMessage) { | ||
function assertType(obj, getErrorMessage = defaultGetErrorMessage) { | ||
checkGetErrorMessage(getErrorMessage); | ||
@@ -64,3 +66,3 @@ const errorMessage = getErrorMessage(obj); | ||
function createIs(getErrorMessage) { | ||
function createIs(getErrorMessage = defaultGetErrorMessage) { | ||
checkGetErrorMessage(getErrorMessage); | ||
@@ -70,3 +72,3 @@ return (obj) => is(obj, getErrorMessage); | ||
function createAssertType(getErrorMessage) { | ||
function createAssertType(getErrorMessage = defaultGetErrorMessage) { | ||
checkGetErrorMessage(getErrorMessage); | ||
@@ -76,2 +78,6 @@ return (obj) => assertType(obj, getErrorMessage); | ||
function setDefaultGetErrorMessage(getErrorMessage) { | ||
defaultGetErrorMessage = getErrorMessage; | ||
} | ||
module.exports = { | ||
@@ -88,3 +94,4 @@ is, | ||
ValidateClass, | ||
TypeGuardError | ||
TypeGuardError, | ||
setDefaultGetErrorMessage | ||
}; |
{ | ||
"name": "typescript-is", | ||
"version": "0.12.3", | ||
"version": "0.12.4", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=6.14.4" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
211134
2562