diff --git a/@vates/decorate-with/README.md b/@vates/decorate-with/README.md new file mode 100644 index 000000000..9b1a072cb --- /dev/null +++ b/@vates/decorate-with/README.md @@ -0,0 +1,45 @@ + + +# @vates/decorate-with + +[![Package Version](https://badgen.net/npm/v/@vates/decorate-with)](https://npmjs.org/package/@vates/decorate-with) ![License](https://badgen.net/npm/license/@vates/decorate-with) [![PackagePhobia](https://badgen.net/bundlephobia/minzip/@vates/decorate-with)](https://bundlephobia.com/result?p=@vates/decorate-with) [![Node compatibility](https://badgen.net/npm/node/@vates/decorate-with)](https://npmjs.org/package/@vates/decorate-with) + +> Creates a decorator from a function wrapper + +## Install + +Installation of the [npm package](https://npmjs.org/package/@vates/decorate-with): + +``` +> npm install --save @vates/decorate-with +``` + +## Usage + +For instance, allows using Lodash's functions as decorators: + +```js +import { decorateWith } from '@vates/decorate-with' + +class Foo { + @decorateWith(lodash.debounce, 150) + bar() { + // body + } +} +``` + +## Contributions + +Contributions are _very_ welcomed, either on the documentation or on +the code. + +You may: + +- report any [issue](https://github.com/vatesfr/xen-orchestra/issues) + you've encountered; +- fork and create a pull request. + +## License + +[ISC](https://spdx.org/licenses/ISC) © [Vates SAS](https://vates.fr) diff --git a/@vates/decorate-with/USAGE.md b/@vates/decorate-with/USAGE.md new file mode 100644 index 000000000..a9bf97c14 --- /dev/null +++ b/@vates/decorate-with/USAGE.md @@ -0,0 +1,12 @@ +For instance, allows using Lodash's functions as decorators: + +```js +import { decorateWith } from '@vates/decorate-with' + +class Foo { + @decorateWith(lodash.debounce, 150) + bar() { + // body + } +} +``` diff --git a/@vates/decorate-with/index.js b/@vates/decorate-with/index.js new file mode 100644 index 000000000..6c99c5878 --- /dev/null +++ b/@vates/decorate-with/index.js @@ -0,0 +1,4 @@ +exports.decorateWith = (fn, ...args) => (target, name, descriptor) => ({ + ...descriptor, + value: fn(descriptor.value, ...args), +}) diff --git a/@vates/decorate-with/package.json b/@vates/decorate-with/package.json new file mode 100644 index 000000000..6db9a0533 --- /dev/null +++ b/@vates/decorate-with/package.json @@ -0,0 +1,30 @@ +{ + "private": false, + "name": "@vates/decorate-with", + "description": "Creates a decorator from a function wrapper", + "keywords": [ + "apply", + "decorator", + "factory", + "wrapper" + ], + "homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/@vates/decorate-with", + "bugs": "https://github.com/vatesfr/xen-orchestra/issues", + "repository": { + "directory": "@vates/decorate-with", + "type": "git", + "url": "https://github.com/vatesfr/xen-orchestra.git" + }, + "author": { + "name": "Vates SAS", + "url": "https://vates.fr" + }, + "license": "ISC", + "version": "0.0.1", + "engines": { + "node": ">=8.10" + }, + "scripts": { + "postversion": "npm publish --access public" + } +}