
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
common utils that can be required selectively
Functional version of &&
var and = require('101/and');
and(true, false); // false
and(true, true); // true
Functional version of function.apply
var apply = require('101/apply');
and(true, false); // false
and(true, true); // true
Simple exists function
var exists = require('101/exists');
exists('foo'); // true
exists(null); // false
exists(undefined); // false
Just like ES6's array.findIndex
Finds the first value in the list that passes the given function (predicate) and returns it's index. If list is not provided findIndex will return a partial-function which accepts a list as the first argument.
var findIndex = require('101/find-index');
var arr = [1, 2, 3];
var index = findIndex(arr, function (val, i, arr) {
return val === 2;
});
// returns 1
// returns -1 if not found
Determines whether the keypaths exist and have the specified values.
var hasKeypaths = require('101/has-keypaths');
var obj = {
foo: {
bar: {
qux: 1
}
}
};
hasKeypaths(obj, ['foo.bar.qux']); // true
hasKeypaths(obj, { 'foo.bar.qux': 1 }); // true
hasKeypaths(obj, ['foo.qux']); // false
hasKeypaths(obj, { 'foo.bar': 2 }); // false
hasKeypaths(obj, { 'foo.bar': 1, 'nope': 1 }); // false
// optional 'deep' arg, defaults to true
var barObj = { bar: 1 };
hasKeypaths(obj, { 'foo.bar': barObj }); // true
hasKeypaths(obj, { 'foo.bar': barObj }, true); // true
hasKeypaths(obj, { 'foo.bar': barObj }, false); // false
hasKeypaths(obj, { 'foo.bar': obj.foo }, false); // true
hasKeypaths(obj, ['foo.bar'], false); // true, uses [hasOwnProperty vs in](http://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey)
Determines whether the keys exist and, if specified, has the values.
var hasProperties = require('101/has-properties');
var obj = {
foo: {
bar: 1
},
qux: 1
};
hasProperties(obj, ['foo', 'qux']); // true
hasProperties(obj, { qux: 1 }) // true
// optional 'deep' arg, defaults to true
var barObj = { bar: 1 };
hasProperties(obj, { 'foo.bar': barObj }); // true
hasProperties(obj, { 'foo.bar': barObj }, true); // true
hasProperties(obj, { 'foo.bar': barObj }, false); // false
hasProperties(obj, ['foo.bar'], false); // true, uses [hasOwnProperty vs in](http://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey)
Functional version of JavaScript's instanceof, returns a partial function which expects a value argument and returns
var instanceOf = require('101/instance-of');
['foo', 'bar', 1].map(instanceOf('string')); // [true, true, false]
Functional version of val typeof 'boolean'
var isBoolean = require('101/is-boolean');
[true, false, 1].map(isBoolean); // [true, true, false]
Functional version of val typeof 'function'
var isFunction = require('101/is-function');
[parseInt, function () {}, 'foo'].map(isFunction); // [true, true, false]
Functional strict version of val typeof 'object' (and not array or regexp)
var isObject = require('101/is-object');
[{}, { foo: 1 }, 100].map(isObject); // [true, true, false]
Functional version of val typeof 'string'
var isObject = require('101/is-object');
[{}, { foo: 1 }, 100].map(isObject); // [true, true, false]
Returns the last value of the item.
var last = require('101/last');
last([1, 2, 3]); // 3
last('hello'); // 'o'
last({
foo: 1,
bar: 2
}); // 2
Functional version of !
var not = require('101/not');
not(isString)('hey'); // false
not(isString)(100); // true
Functional version of ||
var or = require('101/or');
or(true, true); // true
or(true, false); // true
or(false, false); // false
Muxes arguments across many functions and &&'s the results
var passAll = require('101/pass-all');
['', 'foo', 'bar', 100].map(passAll(isString, isTruthy)); // [false, true, true, false]
Muxes arguments across many functions and ||'s the results
var passAny = require('101/pass-any');
['', 'foo', 'bar', 100].map(passAny(isString, isNumber)); // [true, true, true, true]
Returns a new object with the specified keys (with key values from obj)
var pick = require('101/pick');
var obj = {
foo: 1,
bar: 2
};
pick(obj, 'foo'); // { foo: 1 }
pick(obj, ['foo']); // { foo: 1 }
pick(obj, ['foo', 'bar']); // { foo: 1, bar: 2 }
// use it with array.map
[obj, obj, obj].map(pick('foo')); // [{ foo: 1 }, { foo: 1 }, { foo: 1 }];
Functional version of obj[key], returns the value of the key from obj.
var pluck = require('101/pluck');
var obj = {
foo: 1,
bar: 2
};
pluck(obj, 'foo'); // 1
// use it with array.map
[obj, obj, obj].map(pluck('foo')); // [1, 1, 1]
MIT
FAQs
common javascript utils that can be required selectively that assume es5+
The npm package 101 receives a total of 32,633 weekly downloads. As such, 101 popularity was classified as popular.
We found that 101 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
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.