Gathering detailed insights and metrics for feathers-hooks-utils
Gathering detailed insights and metrics for feathers-hooks-utils
Gathering detailed insights and metrics for feathers-hooks-utils
Gathering detailed insights and metrics for feathers-hooks-utils
Provides some utilities that are useful when writing feathersjs hooks.
npm install feathers-hooks-utils
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
8 Stars
22 Commits
2 Watchers
1 Branches
1 Contributors
Updated on Sep 08, 2020
Latest Version
0.2.0
Package Id
feathers-hooks-utils@0.2.0
Size
11.93 kB
NPM Version
3.10.5
Node Version
6.2.2
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Utility library for writing Feathersjs hooks.
DEPRECATED. Goodbye, adiós, au revoir, auf Wiedersehen, zàijiàn.
A modified version of this repo has been moved into feathersjs/feathers-hooks-common/utils, and you should use that instead. However there are breaking differences.
1const utils = require('feathers-hooks-utils'); 2 3// Check we are running as a before hook performing an update or patch method. 4exports.before = { 5 create: [ 6 utils.checkContext(hook, 'before', ['update', 'patch']); 7 ... 8 ], 9};
1// Support conditional inclusion of hooks. 2// Check user authentication with 1 line of code. 3const populateOwnerId = false; 4 5exports.before = { 6 create: concatHooks([ // Flatten hooks 7 utils.restrictToAuthenticated, // Ensure user is authenticated. Note its not a fcn call. 8 populateOwnerId && hooks.associateCurrentUser({ as: 'ownerId' }), // Conditional inclusion 9 hooks.associateCurrentUser({ as: 'createdById' }), 10 ]), 11}; 12 13/* Same result as 14create: [ 15 auth.verifyToken(), 16 auth.populateUser(), 17 auth.restrictToAuthenticated() 18 hooks.associateCurrentUser({ as: 'createdById' }), 19] 20*/
1// Get hook data from `hook.data`, `hook.data.$set` or `hook.result` depending on the context. 2exports.before: { 3 patch: [ 4 (hook) => { 5 const data = utils.get(hook); // from hook.data.$set 6 ... 7 }, 8 ], 9}; 10exports.after: { 11 update: [ 12 (hook) => { 13 const data = utils.get(hook); // from hook.result 14 ... 15 }, 16 ], 17};
1// Set hook data in `hook.data`, `hook.data.$set` or `hook.result` depending on the context. 2exports.before: { 3 create: [ 4 (hook) => { 5 ... 6 utils.set(hook, 'age', 30); // into hook.data 7 }, 8 ], 9}; 10exports.after: { 11 create: [ 12 (hook) => { 13 ... 14 utils.set(hook, 'readAt', new Date()); // into hook.result 15 }, 16 ], 17};
1// Replace all hook data in `hook.data`, `hook.data.$set` or `hook.result` depending on the context. 2// This might be used, for example, to replace the original hook data after it has been sanitized. 3exports.before: { 4 create: [ 5 (hook) => { 6 ... 7 utils.setAll(hook, sanitizedData); // into hook.data 8 }, 9 ], 10}; 11exports.after: { 12 create: [ 13 (hook) => { 14 ... 15 utils.set(hook, replacementData); // into hook.result 16 }, 17 ], 18};
You will be writing hooks if you use Feathers.
This library delivers some of the common functions you want to perform, and its modularity should make your hooks easier to understand.
Install Nodejs.
Run npm install feathers-hooks-utils --save
in your project folder.
You can then require the utilities.
1// ES5 2const utils = require('feathers-hooks-utils'); 3const checkContext = utils.checkContext; 4// or ES6 5import { checkContext } from 'feathers-hooks-utils';
You can require individual utilities if you want to reduce (a little bit of) code:
1// ES5 2const checkContext = require('feathers-hooks-utils/lib/checkContext');
/src
on GitHub contains the ES6 source. It will run on Node 6+ without transpiling.
Each utility is fully documented in its source file.
npm test
to run tests.
npm run cover
to run tests plus coverage.
MIT. See LICENSE.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/22 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More