Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
feathers-hooks-utils
Advanced tools
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.
const utils = require('feathers-hooks-utils');
// Check we are running as a before hook performing an update or patch method.
exports.before = {
create: [
utils.checkContext(hook, 'before', ['update', 'patch']);
...
],
};
// Support conditional inclusion of hooks.
// Check user authentication with 1 line of code.
const populateOwnerId = false;
exports.before = {
create: concatHooks([ // Flatten hooks
utils.restrictToAuthenticated, // Ensure user is authenticated. Note its not a fcn call.
populateOwnerId && hooks.associateCurrentUser({ as: 'ownerId' }), // Conditional inclusion
hooks.associateCurrentUser({ as: 'createdById' }),
]),
};
/* Same result as
create: [
auth.verifyToken(),
auth.populateUser(),
auth.restrictToAuthenticated()
hooks.associateCurrentUser({ as: 'createdById' }),
]
*/
// Get hook data from `hook.data`, `hook.data.$set` or `hook.result` depending on the context.
exports.before: {
patch: [
(hook) => {
const data = utils.get(hook); // from hook.data.$set
...
},
],
};
exports.after: {
update: [
(hook) => {
const data = utils.get(hook); // from hook.result
...
},
],
};
// Set hook data in `hook.data`, `hook.data.$set` or `hook.result` depending on the context.
exports.before: {
create: [
(hook) => {
...
utils.set(hook, 'age', 30); // into hook.data
},
],
};
exports.after: {
create: [
(hook) => {
...
utils.set(hook, 'readAt', new Date()); // into hook.result
},
],
};
// Replace all hook data in `hook.data`, `hook.data.$set` or `hook.result` depending on the context.
// This might be used, for example, to replace the original hook data after it has been sanitized.
exports.before: {
create: [
(hook) => {
...
utils.setAll(hook, sanitizedData); // into hook.data
},
],
};
exports.after: {
create: [
(hook) => {
...
utils.set(hook, replacementData); // into hook.result
},
],
};
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.
// ES5
const utils = require('feathers-hooks-utils');
const checkContext = utils.checkContext;
// or ES6
import { checkContext } from 'feathers-hooks-utils';
You can require individual utilities if you want to reduce (a little bit of) code:
// ES5
const 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.
FAQs
Utility library for writing Feathersjs hooks.
The npm package feathers-hooks-utils receives a total of 18 weekly downloads. As such, feathers-hooks-utils popularity was classified as not popular.
We found that feathers-hooks-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.