1.0.16 • Published 3 years ago
@dizmo/functions-before v1.0.16
@dizmo/functions-before
Returns a function decorating an original function with a callback, which will be invoked before the execution of the original function. The callback can block the invocation of the original function by returning false.
Usage
Install
npm install @dizmo/functions-before --saveRequire
const { before } = require("@dizmo/functions-before");Examples
import { before } from "@dizmo/functions-before";const f1 = (value: number): number => {
return value;
};
const f2 = before(f1, (
fn: Function, value: number
): boolean|undefined => {
const expect = value === 0 || value === 1;
});
const expect0 = f2(0) === 0;
const expect1 = f2(1) === 1;class Class {
@before.decorator((
fn: Function, value: number
): boolean|undefined => {
return false; // blocks method invocation!
})
public method(value: number): number {
return value;
}
}
const expect0 = new Class().method(0) === undefined;
const expect1 = new Class().method(1) === undefined;Development
Clean
npm run cleanBuild
npm run buildwithout linting and cleaning:
npm run -- build --no-lint --no-cleanwith UMD bundling (incl. minimization):
npm run -- build --prepackwith UMD bundling (excl. minimization):
npm run -- build --prepack --no-minifyLint
npm run lintwith auto-fixing:
npm run -- lint --fixTest
npm run testwithout linting, cleaning and (re-)building:
npm run -- test --no-lint --no-clean --no-buildCover
npm run coverwithout linting, cleaning and (re-)building:
npm run -- cover --no-lint --no-clean --no-buildDocumentation
npm run docsPublish
npm publishinitially (if public):
npm publish --access=publicCopyright
© 2020 dizmo AG, Switzerland