Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
A tiny custom identity function creator for composable softwares.
import {createIdentity, identity, identitySecond, identityLast, identitySecondLast} from 'identitate';
// use built-in methods
console.log(identity('first', 'second', 'third', 'fourth', 'fifth')); // 'first'
console.log(identitySecond('first', 'second', 'third', 'fourth', 'fifth')); // 'second'
console.log(identityLast('first', 'second', 'third', 'fourth', 'fifth')); // 'fifth'
console.log(identitySecondLast('first', 'second', 'third', 'fourth', 'fifth')); // 'fourth'
// or create your own
const identityThird = createIdentity(2);
const identityThirdLast = createIdentity(-3);
const identityFirstNested = createIdentity(0, 'deeply[0].nested');
console.log(identityThird('first', 'second', 'third', 'fourth', 'fifth')); // 'third'
console.log(identityThirdLast('first', 'second', 'third', 'fourth', 'fifth')); // 'third'
console.log(identityFirstNested({deeply: [{nested: 'value'}]}, 'second', 'third', 'fourth', 'fifth')); // 'value'
returns first argument passed to it
The classic identity function:
console.log(identity('first', 'second', 'third', 'fourth', 'fifth')); // 'first'
returns second argument passed to it
console.log(identitySecond('first', 'second', 'third', 'fourth', 'fifth')); // 'second'
Example usage when creating meta
properties with the popular redux-actions
package:
import {identity, identitySecond} from 'identitate';
import {createAction} from 'redux-actions';
export const doThing = createAction('DO_THING', identity, identitySecond);
console.log(doThing('payload', 'meta')); // {meta: 'meta', payload: 'payload', type: 'DO_THING'}
returns last argument passed to it, regardless of total number of arguments
console.log(identityLast('first', 'second', 'third', 'fourth', 'fifth')); // 'fifth'
console.log(identityLast('first', 'second', 'third')); // 'third'
returns second-to-last argument passed to it, regardless of total number of arguments
console.log(identityLast('first', 'second', 'third', 'fourth', 'fifth')); // 'fourth'
console.log(identityLast('first', 'second', 'third')); // 'second'
creates a new identity method based on the parameters passed
createIdentity(position: number[, path: (Array<number|string>|number|string)]): any
// use a positive number to get the index of the arguments (zero-indexed)
const identityFourth = createIdentity(3);
console.log(identityLast('first', 'second', 'third', 'fourth', 'fifth')); // 'fourth'
// use a negative number to get the index of the arguments relative to the last
const identityThirdLast = createidentity(-3);
console.log(identityLast('first', 'second', 'third', 'fourth', 'fifth')); // 'third'
// include a path to get the deeply-nested value of that argument
const identityNested = createIdentity(0, 'deeply.nested');
console.log(identityNested({deeply: {nested: 'value'}})); // 'value'
The path
parameter uses pathington under the hood for path parsing, so check there for valid values.
Standard stuff, clone the repo and npm install
dependencies. The npm scripts available:
build
=> run webpack to build development dist
file with NODE_ENV=developmentbuild:minified
=> run webpack to build production dist
file with NODE_ENV=productiondev
=> run webpack dev server to run example app / playgrounddist
=> runs build
and build-minified
lint
=> run ESLint against all files in the src
folderprepublish
=> runs compile-for-publish
prepublish:compile
=> run lint
, test:coverage
, transpile:es
, transpile:lib
, dist
test
=> run AVA test functions with NODE_ENV=test
test:coverage
=> run test
but with nyc
for coverage checkertest:watch
=> run test
, but with persistent watchertranspile:lib
=> run babel against all files in src
to create files in lib
transpile:es
=> run babel against all files in src
to create files in es
, preserving ES2015 modules (for
pkg.module
)1.0.0
FAQs
Custom identity functions for composability
The npm package identitate receives a total of 12,770 weekly downloads. As such, identitate popularity was classified as popular.
We found that identitate 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.