1.0.16 • Published 1 year ago

@dizmo/functions-before v1.0.16

Weekly downloads
1
License
ISC
Repository
github
Last release
1 year ago

NPM version Build Status Coverage Status

@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 --save

Require

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 clean

Build

npm run build

without linting and cleaning:

npm run -- build --no-lint --no-clean

with UMD bundling (incl. minimization):

npm run -- build --prepack

with UMD bundling (excl. minimization):

npm run -- build --prepack --no-minify

Lint

npm run lint

with auto-fixing:

npm run -- lint --fix

Test

npm run test

without linting, cleaning and (re-)building:

npm run -- test --no-lint --no-clean --no-build

Cover

npm run cover

without linting, cleaning and (re-)building:

npm run -- cover --no-lint --no-clean --no-build

Documentation

npm run docs

Publish

npm publish

initially (if public):

npm publish --access=public

Copyright

© 2020 dizmo AG, Switzerland

1.0.16

1 year ago

1.0.15

3 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago