Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dizmo/functions-before
dizmoFun: before handler
https://github.com/dizmo/functions-before
before dizmo function handler javascript library typescript
Last synced: about 15 hours ago
JSON representation
dizmoFun: before handler
- Host: GitHub
- URL: https://github.com/dizmo/functions-before
- Owner: dizmo
- License: isc
- Created: 2018-08-27T11:48:38.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T13:43:25.000Z (about 1 year ago)
- Last Synced: 2024-08-08T19:55:49.451Z (3 months ago)
- Topics: before, dizmo, function, handler, javascript, library, typescript
- Language: JavaScript
- Homepage: https://npmjs.org/package/@dizmo/functions-before
- Size: 1.27 MB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![NPM version](https://badge.fury.io/js/%40dizmo%2Ffunctions-before.svg)](https://npmjs.org/package/@dizmo/functions-before)
[![Build Status](https://travis-ci.com/dizmo/functions-before.svg?branch=master)](https://travis-ci.com/dizmo/functions-before)
[![Coverage Status](https://coveralls.io/repos/github/dizmo/functions-before/badge.svg?branch=master)](https://coveralls.io/github/dizmo/functions-before?branch=master)# @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
```sh
npm install @dizmo/functions-before --save
```### Require
```javascript
const { before } = require("@dizmo/functions-before");
```### Examples
```typescript
import { before } from "@dizmo/functions-before";
``````typescript
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;
``````typescript
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
```sh
npm run clean
```### Build
```sh
npm run build
```#### without linting and cleaning:
```sh
npm run -- build --no-lint --no-clean
```#### with UMD bundling (incl. minimization):
```sh
npm run -- build --prepack
```#### with UMD bundling (excl. minimization):
```sh
npm run -- build --prepack --no-minify
```### Lint
```sh
npm run lint
```#### with auto-fixing:
```sh
npm run -- lint --fix
```### Test
```sh
npm run test
```#### without linting, cleaning and (re-)building:
```sh
npm run -- test --no-lint --no-clean --no-build
```### Cover
```sh
npm run cover
```#### without linting, cleaning and (re-)building:
```sh
npm run -- cover --no-lint --no-clean --no-build
```## Documentation
```sh
npm run docs
```## Publish
```sh
npm publish
```#### initially (if public):
```sh
npm publish --access=public
```## Copyright
© 2020 [dizmo AG](http://dizmo.com/), Switzerland