dizmo/functions-before


dizmoFun: before handler

https://npmjs.org/package/@dizmo/functions-before

License: ISC

Language: TypeScript

Keywords: before, dizmo, function, handler, javascript, library, typescript


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

let lib = 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

Build

npm run build

without linting:

npm run -- build --no-lint

Lint

npm run lint

with auto-fixing (for JavaScript and TypeScript):

npm run -- lint --fix

Test

npm run test

without (re-)building:

npm run -- test --no-build

Cover

npm run cover

without (re-)building:

npm run -- cover --no-build

Copyright

© 2018 dizmo AG, Switzerland

Project Statistics

Sourcerank 4
Repository Size 176 KB
Stars 0
Forks 0
Watchers 4
Open issues 0
Dependencies 0
Tags 4
Created
Last updated
Last pushed

Packages Referencing this Repo

@dizmo/functions-before
before invocation handler
Latest release 1.0.5 - Updated

Recent Tags See all

v1.0.4 August 27, 2018
v1.0.3 August 27, 2018
v1.0.2 August 27, 2018
v1.0.1 August 27, 2018

Something wrong with this page? Make a suggestion

Login to resync this repository