Gathering detailed insights and metrics for just-camel-case
Gathering detailed insights and metrics for just-camel-case
Gathering detailed insights and metrics for just-camel-case
Gathering detailed insights and metrics for just-camel-case
npm install just-camel-case
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
6,056 Stars
999 Commits
209 Forks
42 Watching
36 Branches
94 Contributors
Updated on 28 Nov 2024
JavaScript (85.58%)
TypeScript (14.42%)
Cumulative downloads
Total Downloads
Last day
16%
13,938
Compared to previous day
Last week
4.6%
62,879
Compared to previous week
Last month
8.1%
260,823
Compared to previous month
Last year
63.4%
2,480,220
Compared to previous year
No dependencies detected.
A library of zero-dependency npm modules that do just one thing. A guilt-free alternative to those bulkier utility libraries. Ideal for PWA development or whenever bytes are precious.
We welcome contributions. Please follow our contribution guidelines.
A REPL for every utility (powered by RunKit)
All packages support ES module or Common JS syntax without requiring transpilation
// esm (node / bundler)
import clone from 'just-clone';
// esm (native browser code)
import clone from './node_modules/just-clone/index.mjs';
// cjs
const clone = require('just-clone');
We've now added TypeScript definitions and tests for every Just utility
Most utilities still work with any platform that supports ES5, but these are the earliest versions guranteed to support every utility. For guidance, any platform that supports spread in array literals will work with Just.
Chrome | Safari | Firefox | Edge | Node | Mobile Safari | Android Chrome |
---|---|---|---|---|---|---|
46 | 8 | 16 | 12 | 6.0 | 8 | 46 |
1npm install just-diff
1yarn add just-diff
Return an object representing the difference between two other objects Pass converter to format as http://jsonpatch.com
1import {diff} from 'just-diff'; 2 3const obj1 = {a: 4, b: 5}; 4const obj2 = {a: 3, b: 5}; 5const obj3 = {a: 4, c: 5}; 6 7diff(obj1, obj2); 8[ 9 { "op": "replace", "path": ['a'], "value": 3 } 10] 11 12diff(obj2, obj3); 13[ 14 { "op": "remove", "path": ['b'] }, 15 { "op": "replace", "path": ['a'], "value": 4 } 16 { "op": "add", "path": ['c'], "value": 5 } 17] 18 19// using converter to generate jsPatch standard paths 20import {diff, jsonPatchPathConverter} from 'just-diff' 21diff(obj1, obj2, jsonPatchPathConverter); 22[ 23 { "op": "replace", "path": '/a', "value": 3 } 24] 25 26diff(obj2, obj3, jsonPatchPathConverter); 27[ 28 { "op": "remove", "path": '/b' }, 29 { "op": "replace", "path": '/a', "value": 4 } 30 { "op": "add", "path": '/c', "value": 5 } 31] 32 33// arrays 34const obj4 = {a: 4, b: [1, 2, 3]}; 35const obj5 = {a: 3, b: [1, 2, 4]}; 36const obj6 = {a: 3, b: [1, 2, 4, 5]}; 37 38diff(obj4, obj5); 39[ 40 { "op": "replace", "path": ['a'], "value": 3 } 41 { "op": "replace", "path": ['b', 2], "value": 4 } 42] 43 44diff(obj5, obj6); 45[ 46 { "op": "add", "path": ['b', 3], "value": 5 } 47] 48 49// nested paths 50const obj7 = {a: 4, b: {c: 3}}; 51const obj8 = {a: 4, b: {c: 4}}; 52const obj9 = {a: 5, b: {d: 4}}; 53 54diff(obj7, obj8); 55[ 56 { "op": "replace", "path": ['b', 'c'], "value": 4 } 57] 58 59diff(obj8, obj9); 60[ 61 { "op": "replace", "path": ['a'], "value": 5 } 62 { "op": "remove", "path": ['b', 'c']} 63 { "op": "add", "path": ['b', 'd'], "value": 4 } 64]
1npm install just-diff-apply
1yarn add just-diff-apply
Apply a diff object to an object. Pass converter to apply a http://jsonpatch.com standard patch
1 import {diffApply} from 'just-diff-apply'; 2 3 const obj1 = {a: 3, b: 5}; 4 diffApply(obj1, 5 [ 6 { "op": "remove", "path": ['b'] }, 7 { "op": "replace", "path": ['a'], "value": 4 }, 8 { "op": "add", "path": ['c'], "value": 5 } 9 ] 10 ); 11 obj1; // {a: 4, c: 5} 12 13 const obj2 = {a: 3, b: 5}; 14 diffApply(obj2, 15 [ 16 { "op": "move", "from": ['a'], "path": ['c']}, 17 ] 18 ); 19 obj2; // {b: 5, c: 3} 20 21 // using converter to apply jsPatch standard paths 22 // see http://jsonpatch.com 23 import {diffApply, jsonPatchPathConverter} from 'just-diff-apply' 24 const obj3 = {a: 3, b: 5}; 25 diffApply(obj3, [ 26 { "op": "remove", "path": '/b' }, 27 { "op": "replace", "path": '/a', "value": 4 } 28 { "op": "add", "path": '/c', "value": 5 } 29 ], jsonPatchPathConverter); 30 obj3; // {a: 4, c: 5} 31 32 // arrays (array key can be string or numeric) 33 const obj4 = {a: 4, b: [1, 2, 3]}; 34 diffApply(obj4, [ 35 { "op": "replace", "path": ['a'], "value": 3 } 36 { "op": "replace", "path": ['b', 2], "value": 4 } 37 { "op": "add", "path": ['b', 3], "value": 9 } 38 ]); 39 obj4; // {a: 3, b: [1, 2, 4, 9]} 40 41 // nested paths 42 const obj5 = {a: 4, b: {c: 3}}; 43 diffApply(obj5, [ 44 { "op": "replace", "path": ['a'], "value": 5 } 45 { "op": "remove", "path": ['b', 'c']} 46 { "op": "add", "path": ['b', 'd'], "value": 4 } 47 ]); 48 obj5; // {a: 5, b: {d: 4}}
1npm install just-compare
1yarn add just-compare
Compare two collections
1import compare from 'just-compare'; 2 3// primitives: value1 === value2 4// functions: value1.toString == value2.toString 5// arrays: if length, sequence and values of properties are identical 6// objects: if length, names and values of properties are identical 7compare([1, [2, 3]], [1, [2, 3]]); // true 8compare([1, [2, 3], 4], [1, [2, 3]]); // false 9compare({a: 2, b: 3}, {a: 2, b: 3}); // true 10compare({a: 2, b: 3}, {b: 3, a: 2}); // true 11compare({a: 2, b: 3, c: 4}, {a: 2, b: 3}); // false 12compare({a: 2, b: 3}, {a: 2, b: 3, c: 4}); // false 13compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}]]); // false 14compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}], 4]); // true 15compare(NaN, NaN); // true
1npm install just-clone
1yarn add just-clone
Deep copies objects, arrays, maps and sets
1// Deep copies objects and arrays, doesn't clone functions 2 3import clone from 'just-clone'; 4 5var arr = [1, 2, 3]; 6var subObj = { aa: 1 }; 7var obj = { a: 3, b: 5, c: arr, d: subObj }; 8var objClone = clone(obj); 9arr.push(4); 10objClone.d.bb = 2; 11obj; // {a: 3, b: 5, c: [1, 2, 3, 4], d: {aa: 1}} 12objClone; // {a: 3, b: 5, c: [1, 2, 3], d: {aa: 1, bb: 2}}
1npm install just-pluck-it
1yarn add just-pluck-it
Pluck a property from each member of a collection
1import pluck from 'just-pluck-it'; 2 3pluck([{a:1, b:2}, {a:4, b:3}, {a:2, b:5}], 'a'); // [1, 4, 2] 4pluck({x: {a:1, b:2}, y: {a:4, b:3}, z: {a:2, b:5}}, 'a'); // {x: 1, y: 4, z: 2}
1npm install just-flush
1yarn add just-flush
Returns a copy of an array or object with null/undefined members removed
1import flush from 'just-flush'; 2 3flush([1, undefined, 2, null, 3, NaN, 0]); // [1, 2, 3, NaN, 0] 4flush([true, null, false, true, [null], undefined]); // [true, false, true, [null]] 5flush({a: 2, b: null, c: 4, d: undefined}); // {a: 2, c: 4} 6flush('something'); // undefined 7flush(); // undefined
1npm install just-extend
1yarn add just-extend
Extend an object
1import extend from 'just-extend'; 2 3var obj = {a: 3, b: 5}; 4extend(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8} 5obj; // {a: 4, b: 5, c: 8} 6 7var obj = {a: 3, b: 5}; 8extend({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8} 9obj; // {a: 3, b: 5} 10 11var arr = [1, 2, 3]; 12var obj = {a: 3, b: 5}; 13extend(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]} 14arr.push(4); 15obj; // {a: 3, b: 5, c: [1, 2, 3, 4]} 16 17var arr = [1, 2, 3]; 18var obj = {a: 3, b: 5}; 19extend(true, obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]} 20arr.push(4); 21obj; // {a: 3, b: 5, c: [1, 2, 3]} 22 23extend({a: 4, b: 5}); // {a: 4, b: 5} 24extend({a: 4, b: 5}, 3); {a: 4, b: 5} 25extend({a: 4, b: 5}, true); {a: 4, b: 5} 26extend('hello', {a: 4, b: 5}); // throws 27extend(3, {a: 4, b: 5}); // throws
1npm install just-merge
1yarn add just-merge
Shallow assign. Like just-extend but without deep copy option.
1import merge from 'just-merge'; 2 3let obj = {a: 3, b: 5}; 4merge(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8} 5obj; // {a: 4, b: 5, c: 8} 6 7let obj = {a: 3, b: 5}; 8merge({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8} 9obj; // {a: 3, b: 5} 10 11let arr = [1, 2, 3]; 12let obj = {a: 3, b: 5}; 13merge(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]} 14arr.push[4]; 15obj; // {a: 3, b: 5, c: [1, 2, 3, 4]} 16 17merge({a: 4, b: 5}); // {a: 4, b: 5} 18merge(3, {a: 4, b: 5}); // throws 19merge({a: 4, b: 5}, 3); // throws 20merge({a: 4, b: 5}, {b: 4, c: 5}, 'c'); // throws
1npm install just-values
1yarn add just-values
Return property values as an array
1const values = require('just-values'); 2 3values({a: 4, c: 8}); // [4, 8] 4values({a: {aa: 2}, b: {bb: 4}}); // [{aa: 2}, {bb: 4}] 5values({}); // [] 6values([1, 2, 3]); // [1, 2, 3] 7values(function(a, b) {return a + b;}); // [] 8values(new String('hello')); // ['h', 'e', 'l', 'l', 'o'] 9values(1); // throws exception 10values(true); // throws exception 11values(undefined); // throws exception 12values(null); // throws exception
1npm install just-entries
1yarn add just-entries
Return object entries as an array of [key, value] pairs
1import entries from 'just-entries'; 2 3// Object: 4entries({c: 8, a: 4}); // [['c', 8], ['a', 4]] 5entries({b: {bb: 4}, a: {aa: 2}}); // [['b', {bb: 4}], ['a', {aa: 2}]] 6entries({}); // [] 7 8// Array: 9entries([{c: 8}, {a: 4}]); // [[0, {c: 8}], [1, {a: 4}]] 10entries(['À', 'mauvais', 'ouvrier', 'point', 'de', 'bon', 'outil']) 11// [[0, 'À'], [1, 'mauvais'] ... [6, 'outil']] 12entries([]); // []
1npm install just-pick
1yarn add just-pick
Copy an object but with only the specified keys
1import pick from 'just-pick'; 2 3var obj = { a: 3, b: 5, c: 9 }; 4pick(obj, ['a', 'c']); // {a: 3, c: 9} 5pick(obj, 'a', 'c'); // {a: 3, c: 9} 6pick(obj, ['a', 'b', 'd']); // {a: 3, b: 5} 7pick(obj, ['a', 'a']); // {a: 3}
1npm install just-omit
1yarn add just-omit
Copy an object but omit the specified keys
1import omit from 'just-omit'; 2 3var obj = {a: 3, b: 5, c: 9}; 4omit(obj, ['a', 'c']); // {b: 5} 5omit(obj, 'a', 'c'); // {b: 5} 6omit(obj, ['a', 'b', 'd']); // {c: 9} 7omit(obj, ['a', 'a']); // {b: 5, c: 9}
1npm install just-is-empty
1yarn add just-is-empty
Return true if object has no enumerable key values
1import isEmpty from 'just-is-empty'; 2 isEmpty({a: 3, b: 5}) // false 3 isEmpty([1, 2]) // false 4 isEmpty(new Set([1, 2, 2])) // false 5 isEmpty((new Map()).set('a', 2)) // false 6 isEmpty({}) // true 7 isEmpty([]) // true 8 isEmpty(new Set()) // true 9 isEmpty(new Map()) // true 10 isEmpty('abc') // false 11 isEmpty('') // true 12 isEmpty(0) // true 13 isEmpty(1) // true 14 isEmpty(true) // true 15 isEmpty(Symbol('abc')); // true 16 isEmpty(//); // true 17 isEmpty(new String('abc')); // false 18 isEmpty(new String('')); // true 19 isEmpty(new Boolean(true)); // true 20 isEmpty(null) // true 21 isEmpty(undefined) // true
1npm install just-is-circular
1yarn add just-is-circular
Return true if object has a circular reference NOTE: not supported in IE or microsoft edge
1import isCircular from 'just-is-circular'; 2const a = {}; 3a.b = a; 4isCircular(a); // true 5 6const a = {}; 7a.b = { 8 c: a 9}; 10isCircular(a); // true 11 12const a = {}; 13a.b = { 14 c: 4 15}; 16isCircular(a); // false 17 18const a = []; 19a.push(a); 20isCircular(a); // true 21 22isCircular({}); // false 23isCircular('hi'); // false 24isCircular(undefined); // false
1npm install just-is-primitive
1yarn add just-is-primitive
Determine if a value is a primitive value
1import isPrimitive from 'just-is-primitive'; 2isPrimitive('hi') // true 3isPrimitive(3) // true 4isPrimitive(true) // true 5isPrimitive(false) // true 6isPrimitive(null) // true 7isPrimitive(undefined) // true 8isPrimitive(Symbol()) // true 9isPrimitive({}) // false 10isPrimitive([]) // false 11isPrimitive(function() {}) // false 12isPrimitive(new Date()) // false 13isPrimitive(/a/) // false
1npm install just-filter-object
1yarn add just-filter-object
Filter an object
1import filter from 'just-filter'; 2 3// returns a new object containing those original properties for which the predicate returns truthy 4filter({a: 3, b: 5, c: 9}, (key, value) => value < 6); // {a: 3, b: 5} 5filter({a1: 3, b1: 5, a2: 9}, (key, value) => key[0] == 'a'); // {a1: 3, a2: 9} 6filter({a: 3, b: 5, c: null}, (key, value) => value); // {a: 3, b: 5}
1npm install just-map-object
1yarn add just-map-object
Map an object, passing key and value to predicates
1import map from 'just-map-object'; 2 3// DEPRECATED: use just-map-values 4map({a: 3, b: 5, c: 9}, (key, value) => value + 1); // {a: 4, b: 6, c: 10} 5map({a: 3, b: 5, c: 9}, (key, value) => key); // {a: 'a', b: 'b', c: 'c'} 6map({a: 3, b: 5, c: 9}, (key, value) => key + value); // {a: 'a3', b: 'b5', c: 'c9'}```
1npm install just-map-values
1yarn add just-map-values
Map an object, predicate updates values, receives (value, key, object)
1import map from 'just-map-values'; 2 3// predicate updates values, receives (value, key, obj) 4map({a: 3, b: 5, c: 9}, (value) => value + 1); // {a: 4, b: 6, c: 10} 5map({a: 3, b: 5, c: 9}, (value, key) => value + key); // {a: 3a, b: 5b, c: 9c} 6map({a: 3, b: 5, c: 9}, (value, key, obj) => obj.b); // {a: 5, b: 5, c: 5}
1npm install just-map-keys
1yarn add just-map-keys
Map an object, predicate updates keys, receives (value, key, object)
1import map from 'just-map-keys'; 2 3// predicate updates keys, receives (value, key, object) 4map({a: 'cow', b: 'sheep', c: 'pig'}, (value) => value); 5 // {cow: 'cow', sheep: 'sheep', pig: 'pig'} 6map([4, 5, 6], (value, key) => key + 1); // {1: 4, 2: 5, 3: 6} 7map({a: 3, b: 5, c: 9}, (value, key) => key + value); // {a3: 3, b5: 5, c9: 9} 8map({a: 3, b: 5, c: 9}, (value, key, obj) => obj.b + value + key); 9 // {'8a': 3, '10b': 5, '14c': 9}
1npm install just-deep-map-values
1yarn add just-deep-map-values
Returns an object with values at all depths mapped according to the provided function
1import deepMapValues from 'just-deep-map-values'; 2 3const squareFn = (number) => number * number; 4deepMapValues({ a: 1, b: { c: 2, d: { e: 3 } } }, squareFn); // => { a: 1, b: { c: 4, d: { e: 9 } } }
1npm install just-reduce-object
1yarn add just-reduce-object
Reduce an object
1import reduce from 'just-reduce-object'; 2 3// applies a function against an accumulator and each key-value pairs of the object 4// to reduce it to a single value 5reduce({a: 3, b: 5, c: 9}, (acc, key, value, index, keys) => { 6 acc[value] = key; 7 return acc; 8}, {}); // {3: 'a', 5: 'b', 9: 'c'} 9 10reduce({a: 3, b: 5, c: 9}, (acc, key, value, index, keys) => { 11 acc += value; 12 return acc; 13}); // 17
1npm install just-safe-get
1yarn add just-safe-get
Get value at property, don't throw if parent is undefined
1import get from 'just-safe-get'; 2 3const obj = {a: {aa: {aaa: 2}}, b: 4}; 4 5get(obj, 'a.aa.aaa'); // 2 6get(obj, ['a', 'aa', 'aaa']); // 2 7 8get(obj, 'b.bb.bbb'); // undefined 9get(obj, ['b', 'bb', 'bbb']); // undefined 10 11get(obj.a, 'aa.aaa'); // 2 12get(obj.a, ['aa', 'aaa']); // 2 13 14get(obj.b, 'bb.bbb'); // undefined 15get(obj.b, ['bb', 'bbb']); // undefined 16 17get(obj.b, 'bb.bbb', 5); // 5 18get(obj.b, ['bb', 'bbb'], true); // true 19 20get(null, 'a'); // undefined 21get(undefined, ['a']); // undefined 22 23get(null, 'a', 42); // 42 24get(undefined, ['a'], 42); // 42 25 26const obj = {a: {}}; 27const sym = Symbol(); 28obj.a[sym] = 4; 29get(obj.a, sym); // 4
1npm install just-safe-set
1yarn add just-safe-set
Set value at property, create intermediate properties if necessary
1import set from 'just-safe-set'; 2 3const obj1 = {}; 4set(obj1, 'a.aa.aaa', 4); // true 5obj1; // {a: {aa: {aaa: 4}}} 6 7const obj2 = {}; 8set(obj2, ['a', 'aa', 'aaa'], 4); // true 9obj2; // {a: {aa: {aaa: 4}}} 10 11const obj3 = {a: {aa: {aaa: 2}}}; 12set(obj3, 'a.aa.aaa', 3); // true 13obj3; // {a: {aa: {aaa: 3}}} 14 15const obj5 = {a: {}}; 16const sym = Symbol(); 17set(obj5.a, sym, 7); // true 18obj5; // {a: {Symbol(): 7}}
1npm install just-typeof
1yarn add just-typeof
Type inferer
1import typeOf from 'just-typeof'; 2 3typeOf({}); // 'object' 4typeOf([]); // 'array' 5typeOf(function() {}); // 'function' 6typeOf(/a/); // 'regexp' 7typeOf(new Date()); // 'date' 8typeOf(null); // 'null' 9typeOf(undefined); // 'undefined' 10typeOf('a'); // 'string' 11typeOf(1); // 'number' 12typeOf(true); // 'boolean'
1npm install just-flip-object
1yarn add just-flip-object
Flip the keys and values
1import flip from 'just-flip-object'; 2 3// flip the key and value 4flip({a: 'x', b: 'y', c: 'z'}); // {x: 'a', y: 'b', z: 'c'} 5flip({a: 1, b: 2, c: 3}); // {'1': 'a', '2': 'b', '3': 'c'} 6flip({a: false, b: true}); // {false: 'a', true: 'b'}
1npm install just-has
1yarn add just-has
Return a boolen indicating the existence of a deep property, don't throw if parent is undefined
1import has from 'just-has'; 2 3const obj = {a: {aa: {aaa: 2}}, b: 4}; 4 5has(obj, 'a.aa.aaa'); // true 6has(obj, ['a', 'aa', 'aaa']); // true 7 8has(obj, 'b.bb.bbb'); // false 9has(obj, ['b', 'bb', 'bbb']); // false 10 11has(obj.a, 'aa.aaa'); // true 12has(obj.a, ['aa', 'aaa']); // true 13 14has(obj.b, 'bb.bbb'); // false 15has(obj.b, ['bb', 'bbb']); // false 16 17has(null, 'a'); // false 18has(undefined, ['a']); // false 19 20const obj = {a: {}}; 21const sym = Symbol(); 22obj.a[sym] = 4; 23has(obj.a, sym); // true
1npm install just-cartesian-product
1yarn add just-cartesian-product
Takes an input of an array of arrays and returns their Cartesian product.
1import cartesianProduct from 'just-cartesian-product'; 2 3cartesianProduct([[1, 2], ['a', 'b']]); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] 4cartesianProduct([[1, 2], ['a', 'b', 'c']]); // [[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c']] 5cartesianProduct([]); // [] 6cartesianProduct(); // throws
1npm install just-unique
1yarn add just-unique
Dedupes an array
1import unique from 'just-unique'; 2 3unique([1, 2, 3, 2, 3, 4, 3, 2, 1, 3]); // [1, 2, 3, 4] 4 5var a = {a: 3}; 6var b = {b: 4}; 7var c = {c: 5}; 8unique([a, a, b, c, b]); // [a, b, c] 9 10unique([1, '1', 2, '2', 3, 2]); // [1, '1', 2, '2', 3] 11 12// declaring sorted array for performance 13unique([1, 1, '1', 2, 2, 5, '5', '5'], true); // [1, '1', 2, 5, '6'] 14 15// declaring strings array for performance 16unique(['a', 'c', 'b', 'c', 'a'], false, true); // ['a', 'b', 'c']
1npm install just-flatten-it
1yarn add just-flatten-it
Return a flattened array
1import flatten from 'just-flatten-it'; 2 3flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]]); 4// [1, 2, 3, 4, 5, 6, 7, 8, 9] 5 6flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]], 1); 7// [1, [2, 3], [[4, 5], 6, 7, [8, 9]]]
1npm install just-index
1yarn add just-index
Return an object from an array, keyed by the value at the given id
1import index from 'just-index'; 2 3index([{id: 'first', val: 1}, {id: 'second', val: 2}], 'id'); 4// {first: {id: 'first', val: 1}, second: {id: 'second', val: 2}} 5index([{id: 'first', val: 1}, null], 'id'); // {first: {id: 'first', val: 1}} 6index([], 'id'); // {} 7index([], null); // undefined 8index({}, 'id'); // undefined
1npm install just-insert
1yarn add just-insert
Inserts a sub-array into an array starting at the given index. Returns a copy
1import insert from 'just-insert'; 2 3insert([1, 2, 5, 6], ['a', 'c', 'e'], 2); // [1, 2, 'a', 'c', 'e', 5, 6] 4insert([1, 2, 5, 6], 'a', 2); // [1, 2, 'a', 5, 6] 5insert([1, 2, 5, 6], ['a', 'c', 'e'], 0); // ['a', 'c', 'e', 1, 2, 5, 6] 6insert([1, 2, 5, 6], ['a', 'c', 'e']); // ['a', 'c', 'e', 1, 2, 5, 6]
1npm install just-intersect
1yarn add just-intersect
Return the intersect of two arrays
1import intersect from 'just-intersect'; 2 3intersect([1, 2, 5, 6], [2, 3, 5, 6]); // [2, 5, 6] 4intersect([1, 2, 2, 4, 5], [3, 2, 2, 5, 7]); // [2, 5]
1npm install just-compact
1yarn add just-compact
Returns a copy of an array with falsey values removed
1import compact from 'just-compact'; 2 3compact([1, null, 2, undefined, null, NaN, 3, 4, false, 5]); // [1, 2, 3, 4, 5] 4compact([1, 2, [], 4, {}]); // [1, 2, [], 4, {}] 5compact([]); // [] 6compact({}); // throws
1npm install just-last
1yarn add just-last
Return the last member of an array
1import last from 'just-last'; 2 3last([1, 2, 3, 4, 5]); // 5 4last([{a: 1}, {b: 1}, {c: 1}]); // {c: 1} 5last([true, false, [true, false]]); // [true, false] 6last(); // undefined 7last([]); // undefined 8last(null); // undefined 9last(undefined); // undefined
1npm install just-tail
1yarn add just-tail
Return all but the first element of an array
1import tail from 'just-tail'; 2 3tail([1, 2, 3, 4, 5]); // [2, 3, 4, 5] 4tail([{a: 1}, {b: 1}, {c: 1}]); // [{b: 1}, {c: 1}] 5tail([true, false, [true, false]]); // [false, [true, false]] 6tail([]); // [] 7tail(); // undefined 8tail(null); // undefined 9tail(undefined); // undefined
1npm install just-random
1yarn add just-random
Return a randomly selected element in an array
1import random from 'just-random'; 2 3random([1, 2, 3]); 4// one of [1, 2, 3], at random
1npm install just-shuffle
1yarn add just-shuffle
Return the elements of an array in random order
1import shuffle from 'just-shuffle'; 2 3shuffle([1, 2, 3]); 4// array with original elements randomly sorted 5shuffle([1, 2, 3], {shuffleAll: true}); 6// array with original elements randomly sorted and all in new postions 7shuffle([]); // [] 8shuffle([1]); // [1] 9shuffle(); // throws 10shuffle(undefined); // throws 11shuffle(null); // throws 12shuffle({}); // throws
1npm install just-split
1yarn add just-split
Splits array into groups of n items each
1import split from 'just-split'; 2 3split([]); // [] 4split([1, 2, 3, 4, 5]); // [[1, 2, 3, 4, 5]] 5split([1, 2, 3, 4, 5, 6, 7, 8, 9], 3); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 6split([1, 2, 3, 4, 5, 6, 7, 8, 9], '3'); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 7split(['a', 'b', 'c', 'd', 'e'], 2); // [['a', 'b'], ['c', 'd'], ['e']] 8split([1, 2, 3, 4, 5, 6, 7, 8], 3); // [[1, 2, 3], [4, 5, 6], [7, 8]]
1npm install just-split-at
1yarn add just-split-at
Splits an array into two at a given position
1import splitAt from 'just-split-at'; 2 3splitAt([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4, 5]] 4splitAt([{a: 1}, {b: 1}, {c: 1}], -1); // [[{a: 1}, {b: 1}], [{c: 1}]] 5splitAt([], 2); // [[], []] 6splitAt(null, 1); // throws 7splitAt(undefined, 1); // throws
1npm install just-order-by
1yarn add just-order-by
Produces a new array, sorted in given order
1import orderBy from 'just-order-by'; 2 3orderBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35] 4 5orderBy( 6 [ 7 { user: 'fabio', details: { city: 'Milan', age: 34 } }, 8 { user: 'max', details: { city: 'Munich', age: 29 } }, 9 { user: 'zacarias', details: { city: 'Sao Paulo', age: 44 } }, 10 { user: 'robert', details: { city: 'Manchester', age: 28 } }, 11 { user: 'max', details: { city: 'Zurich', age: 38 } }, 12 ], 13 [ 14 { 15 property(v) { 16 return v.details.age; 17 }, 18 }, 19 ] 20); 21 22/* 23[ 24 {user: 'robert', age: 28}, 25 {user: 'max', age: 29}, 26 {user: 'fabio', age: 34}, 27 {user: 'klaus', age: 38}, 28 {user: 'zacarias', age: 44}, 29] 30*/ 31 32orderBy( 33 [ 34 {user: 'fabio', age: 34}, 35 {user: 'max', age: 29}, 36 {user: 'zacarias', age: 44}, 37 {user: 'robert', age: 28}, 38 {user: 'klaus', age: 38}, 39 ], 40 [ 41 { 42 property: 'user', 43 }, 44 ] 45); 46 47/* 48[ 49 {user: 'fabio', age: 34}, 50 {user: 'klaus', age: 38}, 51 {user: 'max', age: 29}, 52 {user: 'robert', age: 28}, 53 {user: 'zacarias', age: 44}, 54] 55*/ 56 57orderBy( 58 [ 59 { user: 'fabio', age: 34 }, 60 { user: 'max', age: 29 }, 61 { user: 'zacarias', age: 44 }, 62 { user: 'moris', age: 28 }, 63 { user: 'max', age: 38 }, 64 ], 65 [ 66 { 67 property: 'user', 68 order: 'desc', 69 }, 70 { 71 property(v) { 72 return v.age; 73 }, 74 }, 75 ] 76); 77 78/* 79[ 80 { 81 user: 'zacarias', 82 age: 44 83 }, 84 { 85 user: 'moris', 86 age: 28 87 }, 88 { 89 user: 'max', 90 age: 29 91 }, 92 { 93 user: 'max', 94 age: 38 95 }, 96 { 97 user: 'fabio', 98 age: 34 99 } 100] 101*/
1npm install just-sort-by
1yarn add just-sort-by
Produces a new array, sorted in ascending order
1import sortBy from 'just-sort-by'; 2 3sortBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35] 4 5sortBy([ 6 {user: 'fabio', details: {city: "Milan", age: 34}}, 7 {user: 'max', details: {city: "Munich", age: 29}}, 8 {user: 'zacarias', details: {city: "Sao Paulo", age: 44}}, 9 {user: 'robert', details: {city: "Manchester", age: 28}}, 10 {user: 'klaus', details: {city: "Zurich", age: 38}}, 11], function(o) { 12 return o.details.age; 13}); 14 15/* 16[ 17 {user: 'robert', age: 28}, 18 {user: 'max', age: 29}, 19 {user: 'fabio', age: 34}, 20 {user: 'klaus', age: 38}, 21 {user: 'zacarias', age: 44}, 22] 23*/ 24 25sortBy([ 26 {user: 'fabio', age: 34}, 27 {user: 'max', age: 29}, 28 {user: 'zacarias', age: 44}, 29 {user: 'robert', age: 28}, 30 {user: 'klaus', age: 38}, 31], 'user'); 32/* 33[ 34 {user: 'fabio', age: 34}, 35 {user: 'klaus', age: 38}, 36 {user: 'max', age: 29}, 37 {user: 'robert', age: 28}, 38 {user: 'zacarias', age: 44}, 39] 40*/
1npm install just-partition
1yarn add just-partition
Elements satisfying predicate added to first array, remainder added to second
1import partition from 'just-partition'; 2 3partition([1, 5, 2, 4, 3], n => n > 3); // [[5, 4],[1, 2, 3]] 4partition(['a', 2, 3, '3'], x => typeof x == 'string'); // [['a', '3'],[2, 3]] 5partition([1, 2, 3, 4], x => typeof x == 'number'); // [[1, 2, 3, 4],[]] 6partition([1, 2, 3, 4], x => typeof x == 'string'); // [[], [1, 2, 3, 4]] 7partition([], n => n > 3); // [[], []] 8partition({a: 1, b: 2}, n => n > 1); // throws 9partition(null, n => n > 1); // throws 10partition(undefined, n => n > 1); // throws
1npm install just-permutations
1yarn add just-permutations
Returns all permutations of the length N of the elements of the given Array
1import permutations from 'just-permutations'; 2 3permutations([1, 2, 3]); // [[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]] 4permutations([]); // [] 5permutations(); // throws
1npm install just-range
1yarn add just-range
Generate a range array for numbers
1import range from 'just-range'; 2 3range(1, 5); // [1, 2, 3, 4] 4range(5); // [0, 1, 2, 3, 4] 5range(-5); // [0, -1, -2, -3, -4] 6range(0, 20, 5) // [0, 5, 10, 15]
1npm install just-remove
1yarn add just-remove
Removes one array from another
1import remove from 'just-remove'; 2 3remove([1, 2, 3, 4, 5, 6], [1, 3, 6]); // [2, 4, 5]
1npm install just-union
1yarn add just-union
Returns the union of two arrays
1import union from 'just-union'; 2 3union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 5, 6, 3, 4]
1npm install just-zip-it
1yarn add just-zip-it
Returns an array of grouped elements, taking n-th element from every given array
1import zip from 'just-zip-it'; 2 3zip([1, 2, 3]); // [[1], [2], [3]] 4zip([1, 2, 3], ['a', 'b', 'c']); // [[1, 'a'], [2, 'b'], [3, 'c']] 5zip([1, 2], ['a', 'b'], [true, false]); //[[1, 'a', true], [2, 'b', false]] 6 7zip(undefined, {}, false, 1, 'foo'); // [] 8zip([1, 2], ['a', 'b'], undefined, {}, false, 1, 'foo'); // [[1, 'a'], [2, 'b']] 9 10zip([1, 2, 3], ['a', 'b'], [true]); // [[1, 'a', true], [2, 'b', undefined], [3, undefined, undefined]]
1npm install just-group-by
1yarn add just-group-by
Return a grouped object from array
1import groupBy from 'just-group-by'; 2 3groupBy([6.1, 4.2, 6.3], Math.floor); // { '4': [4.2], '6': [6.1, 6.3] } 4groupBy([1,2,3,4,5,6,7,8], function(i) { return i % 2}); // { '0': [2, 4, 6, 8], '1': [1, 3, 5, 7] }
1npm install just-mean
1yarn add just-mean
The mean (average) value in an array
1import mean from 'just-mean'; 2 3mean([1, 2, 3, 2, 4, 1]); // 2.1666666667 4mean(3, 2, 1); // 2 5mean([4]); // 4 6mean(['3', 2]); // throws 7mean(); // throws
1npm install just-median
1yarn add just-median
Return the median value of an array of numbers
1import median from 'just-median'; 2 3median([1, 2, 3, 4, 5]); // 3 4median([3, -1, 2]); // 2 5median([9, 14, 14, 200, 15]); // 14 6median(1, 2, 4, 3); // 2.5 7median(['3', 2, 1]); // throws 8median(); // throws
1npm install just-mode
1yarn add just-mode
Return the most frequently occuring number(s)
1import mode from 'just-mode'; 2 3mode([1, 2, 3, 2]); // 2 4mode(4, 4, 1, 4); // 4 5mode(100, 100, 101, 101); // [100, 101] 6mode(4, 3, 2, 1); // [1, 2, 3, 4] 7mode(['1', 2, 2, 1, 2]); // throws 8mode(null); // throws
1npm install just-percentile
1yarn add just-percentile
Return the value at the given percentile (using linear interpolation)
1import percentile from 'just-percentile'; 2 3percentile([1, 2, 3], 0); // 1 4percentile([1, 2, 3], 0.5); // 2 5percentile([1, 2, 3], 1); // 3 6 7// See https://en.wikipedia.org/wiki/Percentile (linear interpolation method) 8percentile([15, 20, 35, 40, 50], 0.05); // 15 9percentile([15, 20, 35, 40, 50], 0.3); // 20 10percentile([15, 20, 35, 40, 50], 0.4); // 27.5 11percentile([15, 20, 35, 40, 50], 0.95); // 50 12 13percentile(1, 2, 3, 50); // throws 14percentile(['1', 2, 3], 50); // throws 15percentile([], 50); // throws
1npm install just-variance
1yarn add just-variance
Return the standard deviation of an array or numeric argument list
1import variance from 'just-variance'; 2 3variance([1, 2, 3, 2, 4, 1]); // 1.3666666667 4variance(3, 2, 1); // 1 5variance([100, 100, 100.1, 100]); // 0.0025 6variance(1, 2, 3, 4, 5, -6); // 15.5 7variance([4]); // throws 8variance(['3', 2]); // throws 9variance(NaN, NaN); // throws 10variance(); // throws
1npm install just-standard-deviation
1yarn add just-standard-deviation
Return the standard deviation of an array or numeric argument list
1import standardDeviation from "just-standard-deviation"; 2 3standardDeviation([1, 2, 3, 2, 4, 1]); // 1.16904519 4standardDeviation(3, 2, 1); // 1 5standardDeviation([100, 100, 100.1, 100]); // 0.05 6standardDeviation(1, 2, 3, 4, 5, -6); // 3.9370039 7standardDeviation([4]); // throws 8standardDeviation(["3", 2]); // throws 9standardDeviation(NaN, NaN); // throws 10standardDeviation(); // throws
1npm install just-skewness
1yarn add just-skewness
Return the skewness of an array or numeric argument list using Pearson's second skewness coefficient
1import skewness from "just-skewness"; 2 3// Using Pearson's second skewness coefficient 4skewness(3, 2, 1); // 0 5skewness([1, 2, 3, 2, 4, 1]); // 0.4276994613841504 6skewness(1, 2, 3, 4, 5, -6); // -0.762000762001143 7skewness([1, 2, 3, 4, 9]); // 0.7705935588815224 8skewness([4]); // throws 9skewness(["3", 2]); // throws 10skewness(NaN, NaN); // throws 11skewness(); // throws
1npm install just-template
1yarn add just-template
Interpolate a string with variables
1import template from 'just-template'; 2 3var data = { 4 a: { 5 aa: { 6 aaa: 'apple', 7 bbb: 'pear' 8 }, 9 bb: 'orange' 10 }, 11 b: 'plum' 12}; 13template('2 {{a.aa.aaa}}s, a {{a.aa.bbb}}, 3 {{a.bb}}s and a {{b}}. Yes 1 {{a.aa.bbb}}.', data); 14// '2 apples, a pear, 3 oranges and a plum. Yes 1 pear.'
1npm install just-truncate
1yarn add just-truncate
Truncate a string with a custom suffix
1 truncate('when shall we three meet again', 9); // 'when s...' 2 truncate('when shall we three meet again', 10, ' (etc)'); // 'when (etc)' 3 truncate('when shall we', 15,); // 'when shall we' 4 truncate('when shall we', 15, '(more)'); // 'when shall we' 5 truncate('when shall we', 10, ' (etc etc etc)'); // ' (etc etc etc)'
1npm install just-prune
1yarn add just-prune
Prune a string with whole words and a custom suffix
1 prune('when shall we three meet again', 7); // 'when...' 2 prune('when shall we three meet again', 7, ' (more)'; // 'when (more)' 3 prune('when shall we', 15,); // 'when shall we' 4 prune('when shall we', 15, ' (etc)'); // 'when shall we' 5 prune('when shall we', 7, ' (more)'); // ' (more)'
1npm install just-squash
1yarn add just-squash
Remove all spaces from a string, optionally remove escape sequences too
1 squash('the cat sat on the mat'); // 'thecatsatonthemat' 2 squash(' the cat sat on the mat '); // 'thecatsatonthemat' 3 squash('\tthe cat\n sat \fon \vthe \rmat '); // '\tthecat\nsat\fon\vthe\rmat' 4 squash('\tthe cat\n sat \fon \vthe \rmat ', true); // 'thecatsatonthemat' 5 squash(`the cat 6sat on the mat`, true); // thecatsatonthemat
1npm install just-left-pad
1yarn add just-left-pad
Add characters to the left of a string such that its total length is n
1import leftPad from 'just-left-pad'; 2 3leftPad('hello', 9); // ' hello' 4leftPad('hello', 3); // 'hello' 5leftPad('hello', 9, '.'); // '....hello' 6leftPad('hello', 9, '..'); // '....hello' 7leftPad('hello', 10, 'ab'); // 'bababhello' 8leftPad('hello', 9, '\uD83D\uDC04'); // '🐄🐄🐄🐄hello' 9leftPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // '🐄🐑🐄🐑🐄hello' 10leftPad('hello', 7, '🐄'), // '🐄🐄hello' 11leftPad(null, 7); // throws 12leftPad([], 4, '*'); // throws 13leftPad('hello', 4, true); // throws 14leftPad('hello', -4, true); // throws 15leftPad('hello', 2.3, true); // throws
1npm install just-right-pad
1yarn add just-right-pad
Add characters to the right of a string such that its total length is n
1import rightPad from 'just-right-pad'; 2 3rightPad('hello', 9); // 'hello ' 4rightPad('hello', 3); // 'hello' 5rightPad('hello', 9, '.'); // 'hello....' 6rightPad('hello', 9, '..'); // 'hello....' 7rightPad('hello', 10, 'ab'); // 'helloababa' 8rightPad('hello', 9, '\uD83D\uDC04'); // 'hello🐄🐄🐄🐄' 9rightPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // 'hello🐑🐄🐑🐄🐑' 10rightPad('hello', 7, '🐄'), // 'hello🐄🐄' 11rightPad(null, 7); // throws 12rightPad([], 4, '*'); // throws 13rightPad('hello', 4, true); // throws 14rightPad('hello', -4, true); // throws 15rightPad('hello', 2.3, true); // throws
1npm install just-camel-case
1yarn add just-camel-case
Convert a string to camel case
1 import camelCase from 'just-camel-case'; 2 3 camelCase('the quick brown fox'); // 'theQuickBrownFox' 4 camelCase('the_quick_brown_fox'); // 'theQuickBrownFox' 5 camelCase('the-quick-brown-fox'); // 'theQuickBrownFox' 6 camelCase('theQuickBrownFox'); // 'theQuickBrownFox' 7 camelCase('thequickbrownfox'); // 'thequickbrownfox' 8 camelCase('the - quick * brown# fox'); // 'theQuickBrownFox' 9 camelCase('behold theQuickBrownFox'); // 'beholdTheQuickBrownFox' 10 camelCase('Behold theQuickBrownFox'); // 'beholdTheQuickBrownFox' 11 // all caps words are camel-cased 12 camelCase('The quick brown FOX'), 'theQuickBrownFox'); 13 // all caps substrings >= 4 chars are camel-cased 14 camelCase('theQUickBrownFox'); // 'theQUickBrownFox' 15 camelCase('theQUIckBrownFox'); // 'theQUIckBrownFox' 16 camelCase('theQUICKBrownFox'); // 'theQuickBrownFox'
1npm install just-kebab-case
1yarn add just-kebab-case
Convert a string to kebab case
1 import kebabCase from 'just-kebab-case';
2
3 kebabCase('the quick brown fox'); // 'the-quick-brown-fox'
4 kebabCase('the-quick-brown-fox'); // 'the-quick-brown-fox'
5 kebabCase('the_quick_brown_fox'); // 'the-quick-brown-fox'
6 kebabCase('theQuickBrownFox'); // 'the-quick-brown-fox'
7 kebabCase('theQuickBrown Fox'); // 'the-quick-brown-fox'
8 kebabCase('thequickbrownfox'); // 'thequickbrownfox'
9 kebabCase('the - quick * brown# fox'); // 'the-quick-brown-fox'
10 kebabCase('theQUICKBrownFox'); // 'the-q-u-i-c-k-brown-fox'
1npm install just-snake-case
1yarn add just-snake-case
Convert a string to snake case
1 import snakeCase from 'just-snake-case';
2
3 snakeCase('the quick brown fox'); // 'the_quick_brown_fox'
4 snakeCase('the-quick-brown-fox'); // 'the_quick_brown_fox'
5 snakeCase('the_quick_brown_fox'); // 'the_quick_brown_fox'
6 snakeCase('theQuickBrownFox'); // 'the_quick_brown_fox'
7 snakeCase('thequickbrownfox'); // 'thequickbrownfox'
8 snakeCase('the - quick * brown# fox'); // 'the_quick_brown_fox'
9 snakeCase('theQUICKBrownFox'); // 'the_q_u_i_c_k_brown_fox'
1npm install just-pascal-case
1yarn add just-pascal-case
Convert a string to pascal case
1 import pascalCase from 'just-pascal-case';
2
3 pascalCase('the quick brown fox'); // 'TheQuickBrownFox'
4 pascalCase('the_quick_brown_fox'); // 'TheQuickBrownFox'
5 pascalCase('the-quick-brown-fox'); // 'TheQuickBrownFox'
6 pascalCase('theQuickBrownFox'); // 'TheQuickBrownFox'
7 pascalCase('thequickbrownfox'); // 'Thequickbrownfox'
8 pascalCase('the - quick * brown# fox'); // 'TheQuickBrownFox'
9 pascalCase('theQUICKBrownFox'); // 'TheQUICKBrownFox'
1npm install just-capitalize
1yarn add just-capitalize
Capitalize the first character of a string
1 import capitalize from 'just-capitalize'; 2 3/* 4 capitalize('capitals'); // 'Capitals' 5 capitalize('Capitals'); // 'Capitals' 6 capitalize('many words'); // 'Many words' 7 capitalize('!exclaim'); // '!exclaim' 8*/
1npm install just-replace-all
1yarn add just-replace-all
Replace all occurrences of a string within a string with another string
1 import replaceAll from 'just-replace-all'; 2 3/* 4 replaceAll('hello, world', 'l', 'q'); // 'heqqo, worqd' 5 replaceAll('hello, world', 'l', 'qq'); // 'heqqqqo, worqqd' 6 replaceAll('hello, world', 'll', 'q'); // 'heqo, world' 7 replaceAll('hello, world', '', 'q'); // 'hello, world' 8 replaceAll('hello, world', 'l', ''); // 'heo, word' 9 replaceAll('hello, world', null, 'q'); // 'hello, world' 10 replaceAll('hello, world', 'l'); // throw 11 replaceAll('hello, world'); // throw 12 replaceAll(); // throw 13 replaceAll(null, 'l', 'q'); // throw 14 replaceAll('hello, world', null, 'q'); // throw 15 replaceAll('hello, world', 'l', null); // throw 16*/
1npm install just-clamp
1yarn add just-clamp
Restrict a number within a range
1import clamp from 'just-clamp'; 2 3var n = 5; 4clamp(1, n, 12); // 5 5clamp(3, n, 1); // 3 6clamp(8, n, 9); // 8 7clamp(0, n, 0); // 0 8 9var n = -5; 10clamp(1, n, 12); // 1 11clamp(-7, n, -8); // -7 12 13clamp(NaN, n, 8); // NaN 14clamp(3, n, NaN); // NaN 15clamp(3, NaN, 8); // NaN 16 17clamp(undefined, n, 8); // throws 18clamp(3, n, 'h'); // throws 19clamp(3, false, 8); // throws
1npm install just-is-prime
1yarn add just-is-prime
Check if number is prime
1 import isPrime from 'just-is-prime; 2 3/* 4 isPrime(1); // false 5 isPrime(2); // true 6 isPrime(17); // true 7 isPrime(10); // false 8 isPrime(); // throws 9 isPrime(null); // throws 10 isPrime("js"); // throws 11 isPrime({}); // throws 12 isPrime(function() {}); // throws 13 isPrime([]); // throws 14*/
1npm install just-modulo
1yarn add just-modulo
Modulo of a number and a divisor
1import modulo from 'just-modulo'; 2 3modulo(7, 5); // 2 4modulo(17, 23); // 17 5modulo(16.2, 3.8); // 1 6modulo(5.8, 3.4); //2.4 7modulo(4, 0); // 4 8modulo(-7, 5); // 3 9modulo(-2, 15); // 13 10modulo(-5.8, 3.4); // 1 11modulo(12, -1); // NaN 12modulo(-3, -8); // NaN 13modulo(12, 'apple'); // NaN 14modulo('bee', 9); // NaN 15modulo(null, undefined); // NaN
1npm install just-random-integer
1yarn add just-random-integer
Produces a random integer within a given range
1import random from 'just-random-integer'; 2 3random(); 4// Returns either 0 or 1 5random(5); 6// Returns a random integer between 0 and 5 (inclusively) 7random(3, 10); 8// Returns a random integer between 3 and 10 (inclusively) 9random(-5.8, 10.4); 10// Returns a random integer between -5 and 10 (inclusively)
1npm install just-compose
1yarn add just-compose
Return a function composed of 2 or more functions
1import compose from 'just-compose'; 2 3const sqRootBiggest = compose(Math.max, Math.sqrt, Math.trunc); 4sqRootBiggest(10, 5); // 3 5sqRootBiggest(7, 0, 16); // 4
1npm install just-curry-it
1yarn add just-curry-it
Return a curried function
1import curry from 'just-curry-it'; 2 3function add(a, b, c) { 4 return a + b + c; 5} 6curry(add)(1)(2)(3); // 6 7curry(add)(1)(2)(2); // 5 8curry(add)(2)(4, 3); // 9 9 10function add(...args) { 11 return args.reduce((sum, n) => sum + n, 0) 12} 13var curryAdd4 = curry(add, 4) 14curryAdd4(1)(2, 3)(4); // 10 15 16function converter(ratio, input) { 17 return (input*ratio).toFixed(1); 18} 19const curriedConverter = curry(converter) 20const milesToKm = curriedConverter(1.62); 21milesToKm(35); // 56.7 22milesToKm(10); // 16.2
1npm install just-demethodize
1yarn add just-demethodize
Turn a method into a standalone function; the first arg becomes this
1import demethodize from 'just-demethodize'; 2 3const trimFn = demethodize(''.trim); 4['hello ', ' goodbye', 'hello again'].map(trimFn); // ['hello', 'goodbye', 'hello again']
1npm install just-flip
1yarn add just-flip
Flip first two arguments of a function
1import flip from 'just-flip'; 2 3flip(console.log)(1, 2, 3) // 2, 1, 3 4 5import map from 'just-map-object'; 6import partial from 'just-partial'; 7 8const numbers = {x: 5, y: 10}; 9const flippedMap = flip(map); 10const double = partial(flippedMap, (undefined, number) => number * 2); 11double(numbers) // {x: 10, y: 20];
1npm install just-partial-it
1yarn add just-partial-it
Return a partial function
1import partial from 'just-partial-it'; 2 3const cubedRoot = partial(Math.pow, _, 1/3); 4cubedRoot(64); // 4 5 6const getRoot = partial(Math.pow, 64); 7getRoot(1/2); // 8
1npm install just-pipe
1yarn add just-pipe
Pass a value through a pipeline of functions
1import pipe from 'just-pipe 2 3pipe(3, a => a+1, b => b*2) // 8 4pipe('John Smith', a => a.split(' '), b => b.reverse(), c => c[0]) // 'Smith'
1npm install just-debounce-it
1yarn add just-debounce-it
Return a debounced function
1import debounce from "just-debounce-it"; 2 3const fn1 = debounce(() => console.log("Hello"), 500); 4fn1(); 5fn1(); 6fn1(); 7// 500ms later logs 'hello' once 8 9const fn2 = debounce(() => console.log("Hello"), 500, true); 10fn2(); // logs hello immediately 11fn2(); 12fn2(); 13// 500ms later logs 'hello' once 14 15const fn3 = debounce(() => console.log("Hello"), 500); 16fn3(); 17fn3(); 18fn3(); 19fn3.cancel(); 20// function cancelled before 'hello' is logged 21 22const fn4 = debounce(() => console.log("Hello"), 500); 23fn4(); 24fn4(); 25fn4(); 26fn4.flush(); 27// immediately invoke the debounced function
1npm install just-memoize
1yarn add just-memoize
An implementation of the memoize technique
1import memoize from 'just-memoize'; 2 3const sumByOne = memoize(function(value) { 4 return value + 1; 5}); 6 7sumByOne(10); // Returns value returned by the function 8sumByOne(10); // Cache hit! 9 10sumByOne(20); // Returns value returned by the function 11sumByOne(20); // Cache hit! 12 13// Custom cache key (key defaults to JSON stringified arguments) 14var sum = memoize(function(a, b) { 15 return a + b; 16}, function(a, b) { 17 return `${a}-${b}`; 18}); 19 20sum(10, 10); // Returns value returned by the function 21sum(10, 20); // Returns value returned by the function 22sum(10, 20); // Cache hit!
1npm install just-memoize-last
1yarn add just-memoize-last
A memoize implementation that only caches the most recent evaluation
1const memoizeLast = require('just-memoize-last') 2const compare = require('just-compare') 3 4const maxValue = memoizeLast(function(arr) { 5 return Math.max(...arr) 6}, function(a, b) { 7 return compare(a, b) 8}); 9 10maxValue([1,2,3]) // 3 11maxValue([1,2,3]) // cache hit! 12maxValue([1,3,4]) // 4 13maxValue([1,2,3]) // 3
1npm install just-random
1yarn add just-random
Return a randomly selected element in an array
1import random from 'just-random'; 2 3random([1, 2, 3]); 4// one of [1, 2, 3], at random
1npm install just-throttle
1yarn add just-throttle
Return a throttled function
1import throttle from 'just-throttle'; 2 3// no matter how many times the function is called, only invoke once within the given interval 4// options: 5// `leading`: invoke before interval 6// `trailing`: invoke afer interval 7 8const fn1 = throttle(() => console.log('hello'), 500, {leading: true}); 9setInterval(fn1, 400); 10// logs 'hello' immediately and then every 500ms 11 12const fn2 = throttle(() => console.log('hello'), 500, {trailing: true}); 13setInterval(fn2, 400); 14// logs 'hello' after 500ms and then every 500ms 15 16const fn3 = throttle(() => console.log('hello'), 500, {leading: true, trailing: true}); 17// forces trailing to false 18 19const fn4 = throttle(() => console.log('hello'), 500, { leading: false }); 20fn4(); 21fn4(); 22fn4(); 23fn4.cancel(); 24// function cancelled before 'hello' is logged 25 26const fn5 = throttle(() => console.log("Hello"), 500); 27fn5(); 28fn5(); 29fn5(); 30fn5.flush(); 31// immediately invoke the throttled function
1npm install just-once
1yarn add just-once
Create a function that can only be invoked once
1import once from 'just-once'; 2 3const fn = once(() => console.log('hello')); 4 5fn(); 6// logs 'hello' 7fn(); 8// does nothing
Run all tests as a single test suite with
npm run test
Cross browser tests (via saucelabs) are in the sauce
branch
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 10/30 approved changesets -- score normalized to 3
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
42 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
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