Just

A library of dependency-free JavaScript utilities that do just one thing.

README




Just



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.

Build status

We welcome contributions. Please follow our contribution guidelines.

Try :icecream:


A REPL for every utility (powered by RunKit)


Read :books:


- TRADEOFFS.md -- When to use Just (and when not to).
- The Zen of Dependency-Free -- Why I wrote Just.

## ES and CJS modules available for every utility

All packages support ES module or Common JS syntax without requiring transpilation
  1. ```
  2. // esm (node / bundler)
  3. import clone from 'just-clone';

  4. // esm (native browser code)
  5. import clone from './node_modules/just-clone/index.mjs';

  6. // cjs
  7. const clone = require('just-clone');
  8. ```
## TypeScript

We've now added TypeScript definitions and tests for every Just utility

Browser/Platform Support :computer:


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.

ChromeSafariFirefoxEdgeNodeMobileAndroid
-----------------------------------------------------
46816126.0846

The Modules :package:


  - just-diff
- Objects {}
  - just-pick
  - just-omit
  - just-has
- Arrays []
  - just-last
  - just-tail
  - just-mean
  - just-mode
- Strings ""
- Numbers +-
  - just-flip
  - just-once

Collections



[🍦 Try it](https://anguscroll.com/just/just-diff)

  1. ``` sh
  2. npm install just-diff
  3. ```
  1. ``` sh
  2. yarn add just-diff
  3. ```

Return an object representing the difference between two other objects
Pass converter to format as http://jsonpatch.com

  1. ``` js
  2. import {diff} from 'just-diff';

  3. const obj1 = {a: 4, b: 5};
  4. const obj2 = {a: 3, b: 5};
  5. const obj3 = {a: 4, c: 5};

  6. diff(obj1, obj2);
  7. [
  8.   { "op": "replace", "path": ['a'], "value": 3 }
  9. ]

  10. diff(obj2, obj3);
  11. [
  12.   { "op": "remove", "path": ['b'] },
  13.   { "op": "replace", "path": ['a'], "value": 4 }
  14.   { "op": "add", "path": ['c'], "value": 5 }
  15. ]

  16. // using converter to generate jsPatch standard paths
  17. import {diff, jsonPatchPathConverter} from 'just-diff'
  18. diff(obj1, obj2, jsonPatchPathConverter);
  19. [
  20.   { "op": "replace", "path": '/a', "value": 3 }
  21. ]

  22. diff(obj2, obj3, jsonPatchPathConverter);
  23. [
  24.   { "op": "remove", "path": '/b' },
  25.   { "op": "replace", "path": '/a', "value": 4 }
  26.   { "op": "add", "path": '/c', "value": 5 }
  27. ]

  28. // arrays
  29. const obj4 = {a: 4, b: [1, 2, 3]};
  30. const obj5 = {a: 3, b: [1, 2, 4]};
  31. const obj6 = {a: 3, b: [1, 2, 4, 5]};

  32. diff(obj4, obj5);
  33. [
  34.   { "op": "replace", "path": ['a'], "value": 3 }
  35.   { "op": "replace", "path": ['b', 2], "value": 4 }
  36. ]

  37. diff(obj5, obj6);
  38. [
  39.   { "op": "add", "path": ['b', 3], "value": 5 }
  40. ]

  41. // nested paths
  42. const obj7 = {a: 4, b: {c: 3}};
  43. const obj8 = {a: 4, b: {c: 4}};
  44. const obj9 = {a: 5, b: {d: 4}};

  45. diff(obj7, obj8);
  46. [
  47.   { "op": "replace", "path": ['b', 'c'], "value": 4 }
  48. ]

  49. diff(obj8, obj9);
  50. [
  51.   { "op": "replace", "path": ['a'], "value": 5 }
  52.   { "op": "remove", "path": ['b', 'c']}
  53.   { "op": "add", "path": ['b', 'd'], "value": 4 }
  54. ]
  55. ```


[🍦 Try it](https://anguscroll.com/just/just-diff-apply)

  1. ``` sh
  2. npm install just-diff-apply
  3. ```
  1. ``` sh
  2. yarn add just-diff-apply
  3. ```

Apply a diff object to an object. Pass converter to apply a http://jsonpatch.com standard patch

  1. ``` js
  2.   import {diffApply} from 'just-diff-apply';

  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.   const obj2 = {a: 3, b: 5};
  13.   diffApply(obj2,
  14.     [
  15.       { "op": "move", "from": ['a'], "path": ['c']},
  16.     ]
  17.   );
  18.   obj2; // {b: 5, c: 3}

  19.   // using converter to apply jsPatch standard paths
  20.   // see http://jsonpatch.com
  21.   import {diffApply, jsonPatchPathConverter} from 'just-diff-apply'
  22.   const obj3 = {a: 3, b: 5};
  23.   diffApply(obj3, [
  24.     { "op": "remove", "path": '/b' },
  25.     { "op": "replace", "path": '/a', "value": 4 }
  26.     { "op": "add", "path": '/c', "value": 5 }
  27.   ], jsonPatchPathConverter);
  28.   obj3; // {a: 4, c: 5}

  29.   // arrays (array key can be string or numeric)
  30.   const obj4 = {a: 4, b: [1, 2, 3]};
  31.   diffApply(obj4, [
  32.     { "op": "replace", "path": ['a'], "value": 3 }
  33.     { "op": "replace", "path": ['b', 2], "value": 4 }
  34.     { "op": "add", "path": ['b', 3], "value": 9 }
  35.   ]);
  36.   obj4; // {a: 3, b: [1, 2, 4, 9]}

  37.   // nested paths
  38.   const obj5 = {a: 4, b: {c: 3}};
  39.   diffApply(obj5, [
  40.     { "op": "replace", "path": ['a'], "value": 5 }
  41.     { "op": "remove", "path": ['b', 'c']}
  42.     { "op": "add", "path": ['b', 'd'], "value": 4 }
  43.   ]);
  44.   obj5; // {a: 5, b: {d: 4}}
  45. ```


[🍦 Try it](https://anguscroll.com/just/just-compare)

  1. ``` sh
  2. npm install just-compare
  3. ```
  1. ``` sh
  2. yarn add just-compare
  3. ```

Compare two collections

  1. ``` js
  2. import compare from 'just-compare';

  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
  7. compare([1, [2, 3]], [1, [2, 3]]); // true
  8. compare([1, [2, 3], 4], [1, [2, 3]]); // false
  9. compare({a: 2, b: 3}, {a: 2, b: 3}); // true
  10. compare({a: 2, b: 3}, {b: 3, a: 2}); // true
  11. compare({a: 2, b: 3, c: 4}, {a: 2, b: 3}); // false
  12. compare({a: 2, b: 3}, {a: 2, b: 3, c: 4}); // false
  13. compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}]]); // false
  14. compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}], 4]); // true
  15. compare(NaN, NaN); // true
  16. ```


[🍦 Try it](https://anguscroll.com/just/just-clone)

  1. ``` sh
  2. npm install just-clone
  3. ```
  1. ``` sh
  2. yarn add just-clone
  3. ```

Deep copies objects, arrays, maps and sets

  1. ``` js
  2. // Deep copies objects and arrays, doesn't clone functions

  3. import clone from 'just-clone';

  4. var arr = [1, 2, 3];
  5. var subObj = { aa: 1 };
  6. var obj = { a: 3, b: 5, c: arr, d: subObj };
  7. var objClone = clone(obj);
  8. arr.push(4);
  9. objClone.d.bb = 2;
  10. obj; // {a: 3, b: 5, c: [1, 2, 3, 4], d: {aa: 1}}
  11. objClone; // {a: 3, b: 5, c: [1, 2, 3], d: {aa: 1, bb: 2}}
  12. ```


[🍦 Try it](https://anguscroll.com/just/just-pluck-it)

  1. ``` sh
  2. npm install just-pluck-it
  3. ```
  1. ``` sh
  2. yarn add just-pluck-it
  3. ```

Pluck a property from each member of a collection

  1. ``` js
  2. import pluck from 'just-pluck-it';

  3. pluck([{a:1, b:2}, {a:4, b:3}, {a:2, b:5}], 'a'); // [1, 4, 2]
  4. pluck({x: {a:1, b:2}, y: {a:4, b:3}, z: {a:2, b:5}}, 'a'); // {x: 1, y: 4, z: 2}
  5. ```


[🍦 Try it](https://anguscroll.com/just/just-flush)

  1. ``` sh
  2. npm install just-flush
  3. ```
  1. ``` sh
  2. yarn add just-flush
  3. ```

Returns a copy of an array or object with null/undefined members removed

  1. ``` js
  2. import flush from 'just-flush';

  3. flush([1, undefined, 2, null, 3, NaN, 0]); // [1, 2, 3, NaN, 0]
  4. flush([true, null, false, true, [null], undefined]); // [true, false, true, [null]]
  5. flush({a: 2, b: null, c: 4, d: undefined}); // {a: 2, c: 4}
  6. flush('something'); // undefined
  7. flush(); // undefined
  8. ```

Objects



[🍦 Try it](https://anguscroll.com/just/just-extend)

  1. ``` sh
  2. npm install just-extend
  3. ```
  1. ``` sh
  2. yarn add just-extend
  3. ```

Extend an object

  1. ``` js
  2. import extend from 'just-extend';

  3. var obj = {a: 3, b: 5};
  4. extend(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
  5. obj; // {a: 4, b: 5, c: 8}

  6. var obj = {a: 3, b: 5};
  7. extend({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
  8. obj; // {a: 3, b: 5}

  9. var arr = [1, 2, 3];
  10. var obj = {a: 3, b: 5};
  11. extend(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
  12. arr.push(4);
  13. obj; // {a: 3, b: 5, c: [1, 2, 3, 4]}

  14. var arr = [1, 2, 3];
  15. var obj = {a: 3, b: 5};
  16. extend(true, obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
  17. arr.push(4);
  18. obj; // {a: 3, b: 5, c: [1, 2, 3]}

  19. extend({a: 4, b: 5}); // {a: 4, b: 5}
  20. extend({a: 4, b: 5}, 3); {a: 4, b: 5}
  21. extend({a: 4, b: 5}, true); {a: 4, b: 5}
  22. extend('hello', {a: 4, b: 5}); // throws
  23. extend(3, {a: 4, b: 5}); // throws
  24. ```


[🍦 Try it](https://anguscroll.com/just/just-merge)

  1. ``` sh
  2. npm install just-merge
  3. ```
  1. ``` sh
  2. yarn add just-merge
  3. ```

Shallow assign. Like just-extend but without deep copy option.

  1. ``` js
  2. import merge from 'just-merge';

  3. let obj = {a: 3, b: 5};
  4. merge(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
  5. obj; // {a: 4, b: 5, c: 8}

  6. let obj = {a: 3, b: 5};
  7. merge({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
  8. obj; // {a: 3, b: 5}

  9. let arr = [1, 2, 3];
  10. let obj = {a: 3, b: 5};
  11. merge(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
  12. arr.push[4];
  13. obj; // {a: 3, b: 5, c: [1, 2, 3, 4]}

  14. merge({a: 4, b: 5}); // {a: 4, b: 5}
  15. merge(3, {a: 4, b: 5}); // throws
  16. merge({a: 4, b: 5}, 3); // throws
  17. merge({a: 4, b: 5}, {b: 4, c: 5}, 'c'); // throws
  18. ```


[🍦 Try it](https://anguscroll.com/just/just-values)

  1. ``` sh
  2. npm install just-values
  3. ```
  1. ``` sh
  2. yarn add just-values
  3. ```

Return property values as an array

  1. ``` js
  2. const values = require('just-values');

  3. values({a: 4, c: 8}); // [4, 8]
  4. values({a: {aa: 2}, b: {bb: 4}}); // [{aa: 2}, {bb: 4}]
  5. values({}); // []
  6. values([1, 2, 3]); // [1, 2, 3]
  7. values(function(a, b) {return a + b;}); // []
  8. values(new String('hello')); // ['h', 'e', 'l', 'l', 'o']
  9. values(1); // throws exception
  10. values(true); // throws exception
  11. values(undefined); // throws exception
  12. values(null); // throws exception
  13. ```


[🍦 Try it](https://anguscroll.com/just/just-entries)

  1. ``` sh
  2. npm install just-entries
  3. ```
  1. ``` sh
  2. yarn add just-entries
  3. ```

Return object entries as an array of [key, value] pairs

  1. ``` js
  2. import entries from 'just-entries';

  3. // Object:
  4. entries({c: 8, a: 4}); // [['c', 8], ['a', 4]]
  5. entries({b: {bb: 4}, a: {aa: 2}}); // [['b', {bb: 4}], ['a', {aa: 2}]]
  6. entries({}); // []

  7. // Array:
  8. entries([{c: 8}, {a: 4}]); // [[0, {c: 8}], [1, {a: 4}]]
  9. entries(['À', 'mauvais', 'ouvrier', 'point', 'de', 'bon', 'outil'])
  10. // [[0, 'À'], [1, 'mauvais'] ... [6, 'outil']]
  11. entries([]); // []
  12. ```


[🍦 Try it](https://anguscroll.com/just/just-pick)

  1. ``` sh
  2. npm install just-pick
  3. ```
  1. ``` sh
  2. yarn add just-pick
  3. ```

Copy an object but with only the specified keys

  1. ``` js
  2. import pick from 'just-pick';

  3. var obj = { a: 3, b: 5, c: 9 };
  4. pick(obj, ['a', 'c']); // {a: 3, c: 9}
  5. pick(obj, 'a', 'c'); // {a: 3, c: 9}
  6. pick(obj, ['a', 'b', 'd']); // {a: 3, b: 5}
  7. pick(obj, ['a', 'a']); // {a: 3}
  8. ```


[🍦 Try it](https://anguscroll.com/just/just-omit)

  1. ``` sh
  2. npm install just-omit
  3. ```
  1. ``` sh
  2. yarn add just-omit
  3. ```

Copy an object but omit the specified keys

  1. ``` js
  2. import omit from 'just-omit';

  3. var obj = {a: 3, b: 5, c: 9};
  4. omit(obj, ['a', 'c']); // {b: 5}
  5. omit(obj, 'a', 'c'); // {b: 5}
  6. omit(obj, ['a', 'b', 'd']); // {c: 9}
  7. omit(obj, ['a', 'a']); // {b: 5, c: 9}
  8. ```


[🍦 Try it](https://anguscroll.com/just/just-is-empty)

  1. ``` sh
  2. npm install just-is-empty
  3. ```
  1. ``` sh
  2. yarn add just-is-empty
  3. ```

Return true if object has no enumerable key values

  1. ``` js
  2. import isEmpty from 'just-is-empty';
  3. isEmpty({a: 3, b: 5}) // false
  4. isEmpty([1, 2]) // false
  5. isEmpty(new Set([1, 2, 2])) // false
  6. isEmpty((new Map()).set('a', 2)) // false
  7. isEmpty({}) // true
  8. isEmpty([]) // true
  9. isEmpty(new Set()) // true
  10. isEmpty(new Map()) // true
  11. isEmpty('abc') // false
  12. isEmpty('') // true
  13. isEmpty(0) // true
  14. isEmpty(1) // true
  15. isEmpty(true) // true
  16. isEmpty(Symbol('abc')); // true
  17. isEmpty(//); // true
  18. isEmpty(new String('abc')); // false
  19. isEmpty(new String('')); // true
  20. isEmpty(new Boolean(true)); // true
  21. isEmpty(null) // true
  22. isEmpty(undefined) // true
  23. ```


[🍦 Try it](https://anguscroll.com/just/just-is-circular)

  1. ``` sh
  2. npm install just-is-circular
  3. ```
  1. ``` sh
  2. yarn add just-is-circular
  3. ```

Return true if object has a circular reference
NOTE: not supported in IE or microsoft edge

  1. ``` js
  2. import isCircular from 'just-is-circular';
  3. const a = {};
  4. a.b = a;
  5. isCircular(a); // true

  6. const a = {};
  7. a.b = {
  8.   c: a
  9. };
  10. isCircular(a); // true

  11. const a = {};
  12. a.b = {
  13.   c: 4
  14. };
  15. isCircular(a); // false

  16. const a = [];
  17. a.push(a);
  18. isCircular(a); // true

  19. isCircular({}); // false
  20. isCircular('hi'); // false
  21. isCircular(undefined); // false
  22. ```


[🍦 Try it](https://anguscroll.com/just/just-is-primitive)

  1. ``` sh
  2. npm install just-is-primitive
  3. ```
  1. ``` sh
  2. yarn add just-is-primitive
  3. ```

Determine if a value is a primitive value

  1. ``` js
  2. import isPrimitive from 'just-is-primitive';
  3. isPrimitive('hi') // true
  4. isPrimitive(3) // true
  5. isPrimitive(true) // true
  6. isPrimitive(false) // true
  7. isPrimitive(null) // true
  8. isPrimitive(undefined) // true
  9. isPrimitive(Symbol()) // true
  10. isPrimitive({}) // false
  11. isPrimitive([]) // false
  12. isPrimitive(function() {}) // false
  13. isPrimitive(new Date()) // false
  14. isPrimitive(/a/) // false
  15. ```


[🍦 Try it](https://anguscroll.com/just/just-filter-object)

  1. ``` sh
  2. npm install just-filter-object
  3. ```
  1. ``` sh
  2. yarn add just-filter-object
  3. ```

Filter an object

  1. ``` js
  2. import filter from 'just-filter';

  3. // returns a new object containing those original properties for which the predicate returns truthy
  4. filter({a: 3, b: 5, c: 9}, (key, value) => value < 6); // {a: 3, b: 5}
  5. filter({a1: 3, b1: 5, a2: 9}, (key, value) => key[0] == 'a'); // {a1: 3, a2: 9}
  6. filter({a: 3, b: 5, c: null}, (key, value) => value); // {a: 3, b: 5}
  7. ```


[🍦 Try it](https://anguscroll.com/just/just-map-object)

  1. ``` sh
  2. npm install just-map-object
  3. ```
  1. ``` sh
  2. yarn add just-map-object
  3. ```

Map an object, passing key and value to predicates

  1. ``` js
  2. import map from 'just-map-object';

  3. // DEPRECATED: use just-map-values
  4. map({a: 3, b: 5, c: 9}, (key, value) => value + 1); // {a: 4, b: 6, c: 10}
  5. map({a: 3, b: 5, c: 9}, (key, value) => key); // {a: 'a', b: 'b', c: 'c'}
  6. map({a: 3, b: 5, c: 9}, (key, value) => key + value); // {a: 'a3', b: 'b5', c: 'c9'}```
  7. ```


[🍦 Try it](https://anguscroll.com/just/just-map-values)

  1. ``` sh
  2. npm install just-map-values
  3. ```
  1. ``` sh
  2. yarn add just-map-values
  3. ```

Map an object, predicate updates values, receives (value, key, object)

  1. ``` js
  2. import map from 'just-map-values';

  3. // predicate updates values, receives (value, key, obj)
  4. map({a: 3, b: 5, c: 9}, (value) => value + 1); // {a: 4, b: 6, c: 10}
  5. map({a: 3, b: 5, c: 9}, (value, key) => value + key); // {a: 3a, b: 5b, c: 9c}
  6. map({a: 3, b: 5, c: 9}, (value, key, obj) => obj.b); // {a: 5, b: 5, c: 5}
  7. ```


[🍦 Try it](https://anguscroll.com/just/just-map-keys)

  1. ``` sh
  2. npm install just-map-keys
  3. ```
  1. ``` sh
  2. yarn add just-map-keys
  3. ```

Map an object, predicate updates keys, receives (value, key, object)

  1. ``` js
  2. import map from 'just-map-keys';

  3. // predicate updates keys, receives (value, key, object)
  4. map({a: 'cow', b: 'sheep', c: 'pig'}, (value) => value);
  5.   // {cow: 'cow', sheep: 'sheep', pig: 'pig'}
  6. map([4, 5, 6], (value, key) => key + 1); // {1: 4, 2: 5, 3: 6}
  7. map({a: 3, b: 5, c: 9}, (value, key) => key + value); // {a3: 3, b5: 5, c9: 9}
  8. map({a: 3, b: 5, c: 9}, (value, key, obj) => obj.b + value + key);
  9.   // {'8a': 3, '10b': 5, '14c': 9}
  10. ```


[🍦 Try it](https://anguscroll.com/just/just-deep-map-values)

  1. ``` sh
  2. npm install just-deep-map-values
  3. ```
  1. ``` sh
  2. yarn add just-deep-map-values
  3. ```

Returns an object with values at all depths mapped according to the provided function

  1. ``` js
  2. import deepMapValues from 'just-deep-map-values';

  3. const squareFn = (number) => number * number;
  4. deepMapValues({ a: 1, b: { c: 2, d: { e: 3 } } }, squareFn); // => { a: 1, b: { c: 4, d: { e: 9 } } }
  5. ```


[🍦 Try it](https://anguscroll.com/just/just-reduce-object)

  1. ``` sh
  2. npm install just-reduce-object
  3. ```
  1. ``` sh
  2. yarn add just-reduce-object
  3. ```

Reduce an object

  1. ``` js
  2. import reduce from 'just-reduce-object';

  3. // applies a function against an accumulator and each key-value pairs of the object
  4. // to reduce it to a single value
  5. reduce({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. reduce({a: 3, b: 5, c: 9}, (acc, key, value, index, keys) => {
  10.   acc += value;
  11.   return acc;
  12. }); // 17
  13. ```


[🍦 Try it](https://anguscroll.com/just/just-safe-get)

  1. ``` sh
  2. npm install just-safe-get
  3. ```
  1. ``` sh
  2. yarn add just-safe-get
  3. ```

Get value at property, don't throw if parent is undefined

  1. ``` js
  2. import get from 'just-safe-get';

  3. const obj = {a: {aa: {aaa: 2}}, b: 4};

  4. get(obj, 'a.aa.aaa'); // 2
  5. get(obj, ['a', 'aa', 'aaa']); // 2

  6. get(obj, 'b.bb.bbb'); // undefined
  7. get(obj, ['b', 'bb', 'bbb']); // undefined

  8. get(obj.a, 'aa.aaa'); // 2
  9. get(obj.a, ['aa', 'aaa']); // 2

  10. get(obj.b, 'bb.bbb'); // undefined
  11. get(obj.b, ['bb', 'bbb']); // undefined

  12. get(obj.b, 'bb.bbb', 5); // 5
  13. get(obj.b, ['bb', 'bbb'], true); // true

  14. get(null, 'a'); // undefined
  15. get(undefined, ['a']); // undefined

  16. get(null, 'a', 42); // 42
  17. get(undefined, ['a'], 42); // 42

  18. const obj = {a: {}};
  19. const sym = Symbol();
  20. obj.a[sym] = 4;
  21. get(obj.a, sym); // 4
  22. ```


[🍦 Try it](https://anguscroll.com/just/just-safe-set)

  1. ``` sh
  2. npm install just-safe-set
  3. ```
  1. ``` sh
  2. yarn add just-safe-set
  3. ```

Set value at property, create intermediate properties if necessary

  1. ``` js
  2. import set from 'just-safe-set';

  3. const obj1 = {};
  4. set(obj1, 'a.aa.aaa', 4); // true
  5. obj1; // {a: {aa: {aaa: 4}}}

  6. const obj2 = {};
  7. set(obj2, ['a', 'aa', 'aaa'], 4); // true
  8. obj2; // {a: {aa: {aaa: 4}}}

  9. const obj3 = {a: {aa: {aaa: 2}}};
  10. set(obj3, 'a.aa.aaa', 3); // true
  11. obj3; // {a: {aa: {aaa: 3}}}

  12. // don't clobber existing
  13. const obj4 = {a: {aa: {aaa: 2}}};
  14. set(obj4, 'a.aa', {bbb: 7}); // false

  15. const obj5 = {a: {}};
  16. const sym = Symbol();
  17. set(obj5.a, sym, 7); // true
  18. obj5; // {a: {Symbol(): 7}}
  19. ```


[🍦 Try it](https://anguscroll.com/just/just-typeof)

  1. ``` sh
  2. npm install just-typeof
  3. ```
  1. ``` sh
  2. yarn add just-typeof
  3. ```

Type inferer

  1. ``` js
  2. import typeOf from 'just-typeof';

  3. typeOf({}); // 'object'
  4. typeOf([]); // 'array'
  5. typeOf(function() {}); // 'function'
  6. typeOf(/a/); // 'regexp'
  7. typeOf(new Date()); // 'date'
  8. typeOf(null); // 'null'
  9. typeOf(undefined); // 'undefined'
  10. typeOf('a'); // 'string'
  11. typeOf(1); // 'number'
  12. typeOf(true); // 'boolean'
  13. ```


[🍦 Try it](https://anguscroll.com/just/just-flip-object)

  1. ``` sh
  2. npm install just-flip-object
  3. ```
  1. ``` sh
  2. yarn add just-flip-object
  3. ```

Flip the keys and values

  1. ``` js
  2. import flip from 'just-flip-object';

  3. // flip the key and value
  4. flip({a: 'x', b: 'y', c: 'z'}); // {x: 'a', y: 'b', z: 'c'}
  5. flip({a: 1, b: 2, c: 3}); // {'1': 'a', '2': 'b', '3': 'c'}
  6. flip({a: false, b: true}); // {false: 'a', true: 'b'}
  7. ```


[🍦 Try it](https://anguscroll.com/just/just-has)

  1. ``` sh
  2. npm install just-has
  3. ```
  1. ``` sh
  2. yarn add just-has
  3. ```

Return a boolen indicating the existence of a deep property, don't throw if parent is undefined

  1. ``` js
  2. import has from 'just-has';

  3. const obj = {a: {aa: {aaa: 2}}, b: 4};

  4. has(obj, 'a.aa.aaa'); // true
  5. has(obj, ['a', 'aa', 'aaa']); // true

  6. has(obj, 'b.bb.bbb'); // false
  7. has(obj, ['b', 'bb', 'bbb']); // false

  8. has(obj.a, 'aa.aaa'); // true
  9. has(obj.a, ['aa', 'aaa']); // true

  10. has(obj.b, 'bb.bbb'); // false
  11. has(obj.b, ['bb', 'bbb']); // false

  12. has(null, 'a'); // false
  13. has(undefined, ['a']); // false

  14. const obj = {a: {}};
  15. const sym = Symbol();
  16. obj.a[sym] = 4;
  17. has(obj.a, sym); // true
  18. ```

Arrays



[🍦 Try it](https://anguscroll.com/just/just-cartesian-product)

  1. ``` sh
  2. npm install just-cartesian-product
  3. ```
  1. ``` sh
  2. yarn add just-cartesian-product
  3. ```

Takes an input of an array of arrays and returns their Cartesian product.

  1. ``` js
  2. import cartesianProduct from 'just-cartesian-product';

  3. cartesianProduct([[1, 2], ['a', 'b']]); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
  4. cartesianProduct([[1, 2], ['a', 'b', 'c']]); // [[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c']]
  5. cartesianProduct([]); // []
  6. cartesianProduct(); // throws
  7. ```


[🍦 Try it](https://anguscroll.com/just/just-unique)

  1. ``` sh
  2. npm install just-unique
  3. ```
  1. ``` sh
  2. yarn add just-unique
  3. ```

Dedupes an array

  1. ``` js
  2. import unique from 'just-unique';

  3. unique([1, 2, 3, 2, 3, 4, 3, 2, 1, 3]); // [1, 2, 3, 4]

  4. var a = {a: 3};
  5. var b = {b: 4};
  6. var c = {c: 5};
  7. unique([a, a, b, c, b]); // [a, b, c]

  8. unique([1, '1', 2, '2', 3, 2]); // [1, '1', 2, '2', 3]

  9. // declaring sorted array for performance
  10. unique([1, 1, '1', 2, 2, 5, '5', '5'], true); // [1, '1', 2, 5, '6']

  11. // declaring strings array for performance
  12. unique(['a', 'c', 'b', 'c', 'a'], false, true); // ['a', 'b', 'c']
  13. ```


[🍦 Try it](https://anguscroll.com/just/just-flatten-it)

  1. ``` sh
  2. npm install just-flatten-it
  3. ```
  1. ``` sh
  2. yarn add just-flatten-it
  3. ```

Return a flattened array

  1. ``` js
  2. import flatten from 'just-flatten-it';

  3. flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]]);
  4. // [1, 2, 3, 4, 5, 6, 7, 8, 9]

  5. flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]], 1);
  6. // [1, [2, 3], [[4, 5], 6, 7, [8, 9]]]
  7. ```


[🍦 Try it](https://anguscroll.com/just/just-index)

  1. ``` sh
  2. npm install just-index
  3. ```
  1. ``` sh
  2. yarn add just-index
  3. ```

Return an object from an array, keyed by the value at the given id

  1. ``` js
  2. import index from 'just-index';

  3. index([{id: 'first', val: 1}, {id: 'second', val: 2}], 'id');
  4. // {first: {id: 'first', val: 1}, second: {id: 'second', val: 2}}
  5. index([{id: 'first', val: 1}, null], 'id'); // {first: {id: 'first', val: 1}}
  6. index([], 'id'); // {}
  7. index([], null); // undefined
  8. index({}, 'id'); // undefined
  9. ```


[🍦 Try it](https://anguscroll.com/just/just-insert)

  1. ``` sh
  2. npm install just-insert
  3. ```
  1. ``` sh
  2. yarn add just-insert
  3. ```

Inserts a sub-array into an array starting at the given index. Returns a copy

  1. ``` js
  2. import insert from 'just-insert';

  3. insert([1, 2, 5, 6], ['a', 'c', 'e'], 2); // [1, 2, 'a', 'c', 'e', 5, 6]
  4. insert([1, 2, 5, 6], 'a', 2); // [1, 2, 'a', 5, 6]
  5. insert([1, 2, 5, 6], ['a', 'c', 'e'], 0); // ['a', 'c', 'e', 1, 2, 5, 6]
  6. insert([1, 2, 5, 6], ['a', 'c', 'e']); // ['a', 'c', 'e', 1, 2, 5, 6]
  7. ```


[🍦 Try it](https://anguscroll.com/just/just-intersect)

  1. ``` sh
  2. npm install just-intersect
  3. ```
  1. ``` sh
  2. yarn add just-intersect
  3. ```

Return the intersect of two arrays

  1. ``` js
  2. import intersect from 'just-intersect';

  3. intersect([1, 2, 5, 6], [2, 3, 5, 6]); // [2, 5, 6]
  4. intersect([1, 2, 2, 4, 5], [3, 2, 2, 5, 7]); // [2, 5]  
  5. ```


[🍦 Try it](https://anguscroll.com/just/just-compact)

  1. ``` sh
  2. npm install just-compact
  3. ```
  1. ``` sh
  2. yarn add just-compact
  3. ```

Returns a copy of an array with falsey values removed

  1. ``` js
  2. import compact from 'just-compact';

  3. compact([1, null, 2, undefined, null, NaN, 3, 4, false, 5]); // [1, 2, 3, 4, 5]
  4. compact([1, 2, [], 4, {}]); // [1, 2, [], 4, {}]
  5. compact([]); // []
  6. compact({}); // throws
  7. ```


[🍦 Try it](https://anguscroll.com/just/just-last)

  1. ``` sh
  2. npm install just-last
  3. ```
  1. ``` sh
  2. yarn add just-last
  3. ```

Return the last member of an array

  1. ``` js
  2. import last from 'just-last';

  3. last([1, 2, 3, 4, 5]); // 5
  4. last([{a: 1}, {b: 1}, {c: 1}]); // {c: 1}
  5. last([true, false, [true, false]]); // [true, false]
  6. last(); // undefined
  7. last([]); // undefined
  8. last(null); // undefined
  9. last(undefined); // undefined
  10. ```


[🍦 Try it](https://anguscroll.com/just/just-tail)

  1. ``` sh
  2. npm install just-tail
  3. ```
  1. ``` sh
  2. yarn add just-tail
  3. ```

Return all but the first element of an array

  1. ``` js
  2. import tail from 'just-tail';

  3. tail([1, 2, 3, 4, 5]); // [2, 3, 4, 5]
  4. tail([{a: 1}, {b: 1}, {c: 1}]); // [{b: 1}, {c: 1}]
  5. tail([true, false, [true, false]]); // [false, [true, false]]
  6. tail([]); // []
  7. tail(); // undefined
  8. tail(null); // undefined
  9. tail(undefined); // undefined
  10. ```


[🍦 Try it](https://anguscroll.com/just/just-random)

  1. ``` sh
  2. npm install just-random
  3. ```
  1. ``` sh
  2. yarn add just-random
  3. ```

Return a randomly selected element in an array

  1. ``` js
  2. import random from 'just-random';

  3. random([1, 2, 3]);
  4. // one of [1, 2, 3], at random
  5. ```


[🍦 Try it](https://anguscroll.com/just/just-shuffle)

  1. ``` sh
  2. npm install just-shuffle
  3. ```
  1. ``` sh
  2. yarn add just-shuffle
  3. ```

Return the elements of an array in random order

  1. ``` js
  2. import shuffle from 'just-shuffle';

  3. shuffle([1, 2, 3]);
  4. // array with original elements randomly sorted
  5. shuffle([1, 2, 3], {shuffleAll: true});
  6. // array with original elements randomly sorted and all in new postions
  7. shuffle([]); // []
  8. shuffle([1]); // [1]
  9. shuffle(); // throws
  10. shuffle(undefined); // throws
  11. shuffle(null); // throws
  12. shuffle({}); // throws
  13. ```


[🍦 Try it](https://anguscroll.com/just/just-split)

  1. ``` sh
  2. npm install just-split
  3. ```
  1. ``` sh
  2. yarn add just-split
  3. ```

Splits array into groups of n items each

  1. ``` js
  2. import split from 'just-split';

  3. split([]); // []
  4. split([1, 2, 3, 4, 5]); // [[1, 2, 3, 4, 5]]
  5. split([1, 2, 3, 4, 5, 6, 7, 8, 9], 3); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  6. split([1, 2, 3, 4, 5, 6, 7, 8, 9], '3'); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  7. split(['a', 'b', 'c', 'd', 'e'], 2); // [['a', 'b'], ['c', 'd'], ['e']]
  8. split([1, 2, 3, 4, 5, 6, 7, 8], 3); // [[1, 2, 3], [4, 5, 6], [7, 8]]
  9. ```


[🍦 Try it](https://anguscroll.com/just/just-split-at)

  1. ``` sh
  2. npm install just-split-at
  3. ```
  1. ``` sh
  2. yarn add just-split-at
  3. ```

Splits an array into two at a given position

  1. ``` js
  2. import splitAt from 'just-split-at';

  3. splitAt([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4, 5]]
  4. splitAt([{a: 1}, {b: 1}, {c: 1}], -1); // [[{a: 1}, {b: 1}], [{c: 1}]]
  5. splitAt([], 2); // [[], []]
  6. splitAt(null, 1); // throws
  7. splitAt(undefined, 1); // throws
  8. ```


[🍦 Try it](https://anguscroll.com/just/just-sort-by)

  1. ``` sh
  2. npm install just-sort-by
  3. ```
  1. ``` sh
  2. yarn add just-sort-by
  3. ```

Produces a new array, sorted in ascending order

  1. ``` js
  2. import sortBy from 'just-sort-by';

  3. sortBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35]

  4. sortBy([
  5.   {user: 'fabio', details: {city: "Milan", age: 34}},
  6.   {user: 'max', details: {city: "Munich", age: 29}},
  7.   {user: 'zacarias', details: {city: "Sao Paulo", age: 44}},
  8.   {user: 'robert', details: {city: "Manchester", age: 28}},
  9.   {user: 'klaus', details: {city: "Zurich", age: 38}},
  10. ], function(o) {
  11.   return o.details.age;
  12. });

  13. /*
  14. [
  15.   {user: 'robert', age: 28},
  16.   {user: 'max', age: 29},
  17.   {user: 'fabio', age: 34},
  18.   {user: 'klaus', age: 38},
  19.   {user: 'zacarias', age: 44},
  20. ]
  21. */

  22. sortBy([
  23.   {user: 'fabio', age: 34},
  24.   {user: 'max', age: 29},
  25.   {user: 'zacarias', age: 44},
  26.   {user: 'robert', age: 28},
  27.   {user: 'klaus', age: 38},
  28. ], 'user');
  29. /*
  30. [
  31.   {user: 'fabio', age: 34},
  32.   {user: 'klaus', age: 38},
  33.   {user: 'max', age: 29},
  34.   {user: 'robert', age: 28},
  35.   {user: 'zacarias', age: 44},
  36. ]
  37. */
  38. ```


[🍦 Try it](https://anguscroll.com/just/just-partition)

  1. ``` sh
  2. npm install just-partition
  3. ```
  1. ``` sh
  2. yarn add just-partition
  3. ```

Elements satisfying predicate added to first array, remainder added to second

  1. ``` js
  2. import partition from 'just-partition';

  3. partition([1, 5, 2, 4, 3], n => n > 3); // [[5, 4],[1, 2, 3]]
  4. partition(['a', 2, 3, '3'], x => typeof x == 'string'); // [['a', '3'],[2, 3]]
  5. partition([1, 2, 3, 4], x => typeof x == 'number'); // [[1, 2, 3, 4],[]]
  6. partition([1, 2, 3, 4], x => typeof x == 'string'); // [[], [1, 2, 3, 4]]
  7. partition([], n => n > 3); // [[], []]
  8. partition({a: 1, b: 2}, n => n > 1); // throws
  9. partition(null, n => n > 1); // throws
  10. partition(undefined, n => n > 1); // throws
  11. ```


[🍦 Try it](https://anguscroll.com/just/just-permutations)

  1. ``` sh
  2. npm install just-permutations
  3. ```
  1. ``` sh
  2. yarn add just-permutations
  3. ```

Returns all permutations of the length N of the elements of the given Array

  1. ``` js
  2. import permutations from 'just-array-permutations;

  3. permutations([1, 2, 3]); // [[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]
  4. permutations([]); // []
  5. permutations(); // throws
  6. ```


[🍦 Try it](https://anguscroll.com/just/just-range)

  1. ``` sh
  2. npm install just-range
  3. ```
  1. ``` sh
  2. yarn add just-range
  3. ```

Generate a range array for numbers

  1. ``` js
  2. import range from 'just-range';

  3. range(1, 5); // [1, 2, 3, 4]
  4. range(5); // [0, 1, 2, 3, 4]
  5. range(-5); // [0, -1, -2, -3, -4]
  6. range(0, 20, 5) // [0, 5, 10, 15]
  7. ```


[🍦 Try it](https://anguscroll.com/just/just-remove)

  1. ``` sh
  2. npm install just-remove
  3. ```
  1. ``` sh
  2. yarn add just-remove
  3. ```

Removes one array from another

  1. ``` js
  2. import remove from 'just-remove';

  3. remove([1, 2, 3, 4, 5, 6], [1, 3, 6]); // [2, 4, 5]
  4. ```


[🍦 Try it](https://anguscroll.com/just/just-union)

  1. ``` sh
  2. npm install just-union
  3. ```
  1. ``` sh
  2. yarn add just-union
  3. ```

Returns the union of two arrays

  1. ``` js
  2. import union from 'just-union';

  3. union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 5, 6, 3, 4]
  4. ```


[🍦 Try it](https://anguscroll.com/just/just-zip-it)

  1. ``` sh
  2. npm install just-zip-it
  3. ```
  1. ``` sh
  2. yarn add just-zip-it
  3. ```

Returns an array of grouped elements, taking n-th element from every given array

  1. ``` js
  2. import zip from 'just-zip-it';

  3. zip([1, 2, 3]); // [[1], [2], [3]]
  4. zip([1, 2, 3], ['a', 'b', 'c']); // [[1, 'a'], [2, 'b'], [3, 'c']]
  5. zip([1, 2], ['a', 'b'], [true, false]); //[[1, 'a', true], [2, 'b', false]]

  6. zip(undefined, {}, false, 1, 'foo'); // []
  7. zip([1, 2], ['a', 'b'], undefined, {}, false, 1, 'foo'); // [[1, 'a'], [2, 'b']]

  8. zip([1, 2, 3], ['a', 'b'], [true]); // [[1, 'a', true], [2, 'b', undefined], [3, undefined, undefined]]
  9. ```


[🍦 Try it](https://anguscroll.com/just/just-group-by)

  1. ``` sh
  2. npm install just-group-by
  3. ```
  1. ``` sh
  2. yarn add just-group-by
  3. ```

Return a grouped object from array

  1. ``` js
  2. import groupBy from 'just-group-by';

  3. groupBy([6.1, 4.2, 6.3], Math.floor); // { '4': [4.2], '6': [6.1, 6.3] }
  4. groupBy([1,2,3,4,5,6,7,8], function(i) { return i % 2}); // { '0': [2, 4, 6, 8], '1': [1, 3, 5, 7] }
  5. ```

Statistics



[🍦 Try it](https://anguscroll.com/just/just-mean)

  1. ``` sh
  2. npm install just-mean
  3. ```
  1. ``` sh
  2. yarn add just-mean
  3. ```

The mean (average) value in an array

  1. ``` js
  2. import mean from 'just-mean';

  3. mean([1, 2, 3, 2, 4, 1]); // 2.1666666667
  4. mean(3, 2, 1); // 2
  5. mean([4]); // 4
  6. mean(['3', 2]); // throws
  7. mean(); // throws
  8. ```


[🍦 Try it](https://anguscroll.com/just/just-median)

  1. ``` sh
  2. npm install just-median
  3. ```
  1. ``` sh
  2. yarn add just-median
  3. ```

Return the median value of an array of numbers

  1. ``` js
  2. import median from 'just-median';

  3. median([1, 2, 3, 4, 5]); // 3
  4. median([3, -1, 2]); // 2
  5. median([9, 14, 14, 200, 15]); // 14
  6. median(1, 2, 4, 3); // 2.5
  7. median(['3', 2, 1]); // throws
  8. median(); // throws
  9. ```


[🍦 Try it](https://anguscroll.com/just/just-mode)

  1. ``` sh
  2. npm install just-mode
  3. ```
  1. ``` sh
  2. yarn add just-mode
  3. ```

Return the most frequently occuring number(s)

  1. ``` js
  2. import mode from 'just-mode';

  3. mode([1, 2, 3, 2]); // 2
  4. mode(4, 4, 1, 4); // 4
  5. mode(100, 100, 101, 101); // [100, 101]
  6. mode(4, 3, 2, 1); // [1, 2, 3, 4]
  7. mode(['1', 2, 2, 1, 2]); // throws
  8. mode(null); // throws
  9. ```


[🍦 Try it](https://anguscroll.com/just/just-percentile)

  1. ``` sh
  2. npm install just-percentile
  3. ```
  1. ``` sh
  2. yarn add just-percentile
  3. ```

Return the value at the given percentile (using linear interpolation)

  1. ``` js
  2. import percentile from 'just-percentile';

  3. percentile([1, 2, 3], 0); // 1
  4. percentile([1, 2, 3], 0.5); // 2
  5. percentile([1, 2, 3], 1); // 3

  6. // See https://en.wikipedia.org/wiki/Percentile (linear interpolation method)
  7. percentile([15, 20, 35, 40, 50], 0.05); // 15
  8. percentile([15, 20, 35, 40, 50], 0.3); // 20
  9. percentile([15, 20, 35, 40, 50], 0.4); // 27.5
  10. percentile([15, 20, 35, 40, 50], 0.95); // 50

  11. percentile(1, 2, 3, 50); // throws
  12. percentile(['1', 2, 3], 50); // throws
  13. percentile([], 50); // throws
  14. ```


[🍦 Try it](https://anguscroll.com/just/just-variance)

  1. ``` sh
  2. npm install just-variance
  3. ```
  1. ``` sh
  2. yarn add just-variance
  3. ```

Return the standard deviation of an array or numeric argument list

  1. ``` js
  2. import variance from 'just-variance';

  3. variance([1, 2, 3, 2, 4, 1]); // 1.3666666667
  4. variance(3, 2, 1); // 1
  5. variance([100, 100, 100.1, 100]); // 0.0025
  6. variance(1, 2, 3, 4, 5, -6); // 15.5
  7. variance([4]); // throws
  8. variance(['3', 2]); // throws
  9. variance(NaN, NaN); // throws
  10. variance(); // throws
  11. ```


[🍦 Try it](https://anguscroll.com/just/just-standard-deviation)

  1. ``` sh
  2. npm install just-standard-deviation
  3. ```
  1. ``` sh
  2. yarn add just-standard-deviation
  3. ```

Return the standard deviation of an array or numeric argument list

  1. ``` js
  2. import standardDeviation from "just-standard-deviation";

  3. standardDeviation([1, 2, 3, 2, 4, 1]); // 1.16904519
  4. standardDeviation(3, 2, 1); // 1
  5. standardDeviation([100, 100, 100.1, 100]); // 0.05
  6. standardDeviation(1, 2, 3, 4, 5, -6); // 3.9370039
  7. standardDeviation([4]); // throws
  8. standardDeviation(["3", 2]); // throws
  9. standardDeviation(NaN, NaN); // throws
  10. standardDeviation(); // throws
  11. ```


[🍦 Try it](https://anguscroll.com/just/just-skewness)

  1. ``` sh
  2. npm install just-skewness
  3. ```
  1. ``` sh
  2. yarn add just-skewness
  3. ```

Return the skewness of an array or numeric argument list using Pearson's second skewness coefficient

  1. ``` js
  2. import skewness from "just-skewness";

  3. // Using Pearson's second skewness coefficient
  4. skewness(3, 2, 1); // 0
  5. skewness([1, 2, 3, 2, 4, 1]); // 0.4276994613841504
  6. skewness(1, 2, 3, 4, 5, -6); // -0.762000762001143
  7. skewness([1, 2, 3, 4, 9]); // 0.7705935588815224
  8. skewness([4]); // throws
  9. skewness(["3", 2]); // throws
  10. skewness(NaN, NaN); // throws
  11. skewness(); // throws
  12. ```

Strings



[🍦 Try it](https://anguscroll.com/just/just-template)

  1. ``` sh
  2. npm install just-template
  3. ```
  1. ``` sh
  2. yarn add just-template
  3. ```

Interpolate a string with variables

  1. ``` js
  2. import template from 'just-template';

  3. var data = {
  4.   a: {
  5.     aa: {
  6.       aaa: 'apple',
  7.       bbb: 'pear'
  8.     },
  9.     bb: 'orange'
  10.   },
  11.   b: 'plum'
  12. };
  13. template('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.'
  15. ```


[🍦 Try it](https://anguscroll.com/just/just-truncate)

  1. ``` sh
  2. npm install just-truncate
  3. ```
  1. ``` sh
  2. yarn add just-truncate
  3. ```

Truncate a string with a custom suffix

  1. ``` js
  2.   truncate('when shall we three meet again', 9); // 'when s...'
  3.   truncate('when shall we three meet again', 10, ' (etc)'); // 'when (etc)'
  4.   truncate('when shall we', 15,); // 'when shall we'
  5.   truncate('when shall we', 15, '(more)'); // 'when shall we'
  6.   truncate('when shall we', 10, ' (etc etc etc)'); // ' (etc etc etc)'
  7. ```


[🍦 Try it](https://anguscroll.com/just/just-prune)

  1. ``` sh
  2. npm install just-prune
  3. ```
  1. ``` sh
  2. yarn add just-prune
  3. ```

Prune a string with whole words and a custom suffix

  1. ``` js
  2.   prune('when shall we three meet again', 7); // 'when...'
  3.   prune('when shall we three meet again', 7, ' (more)'; // 'when (more)'
  4.   prune('when shall we', 15,); // 'when shall we'
  5.   prune('when shall we', 15, ' (etc)'); // 'when shall we'
  6.   prune('when shall we', 7, ' (more)'); // ' (more)'
  7. ```


[🍦 Try it](https://anguscroll.com/just/just-squash)

  1. ``` sh
  2. npm install just-squash
  3. ```
  1. ``` sh
  2. yarn add just-squash
  3. ```

Remove all spaces from a string, optionally remove escape sequences too

  1. ``` js
  2.   squash('the cat sat on the mat'); // 'thecatsatonthemat'
  3.   squash(' the cat sat on the mat '); // 'thecatsatonthemat'
  4.   squash('\tthe cat\n sat \fon \vthe \rmat '); // '\tthecat\nsat\fon\vthe\rmat'
  5.   squash('\tthe cat\n sat \fon \vthe \rmat ', true); // 'thecatsatonthemat'
  6.   squash(`the cat
  7. sat on the mat`, true); // thecatsatonthemat
  8. ```


[🍦 Try it](https://anguscroll.com/just/just-left-pad)

  1. ``` sh
  2. npm install just-left-pad
  3. ```
  1. ``` sh
  2. yarn add just-left-pad
  3. ```

Add characters to the left of a string such that its total length is n

  1. ``` js
  2. import leftPad from 'just-left-pad';

  3. leftPad('hello', 9); // '    hello'
  4. leftPad('hello', 3); // 'hello'
  5. leftPad('hello', 9, '.'); // '....hello'
  6. leftPad('hello', 9, '..'); // '....hello'
  7. leftPad('hello', 10, 'ab'); // 'bababhello'
  8. leftPad('hello', 9, '\uD83D\uDC04'); // '🐄🐄🐄🐄hello'
  9. leftPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // '🐄🐑🐄🐑🐄hello'
  10. leftPad('hello', 7, '🐄'), // '🐄🐄hello'
  11. leftPad(null, 7); // throws
  12. leftPad([], 4, '*'); // throws
  13. leftPad('hello', 4, true); // throws
  14. leftPad('hello', -4, true); // throws  
  15. leftPad('hello', 2.3, true); // throws    
  16. ```


[🍦 Try it](https://anguscroll.com/just/just-right-pad)

  1. ``` sh
  2. npm install just-right-pad
  3. ```
  1. ``` sh
  2. yarn add just-right-pad
  3. ```

Add characters to the right of a string such that its total length is n

  1. ``` js
  2. import rightPad from 'just-right-pad';

  3. rightPad('hello', 9); // 'hello    '
  4. rightPad('hello', 3); // 'hello'
  5. rightPad('hello', 9, '.'); // 'hello....'
  6. rightPad('hello', 9, '..'); // 'hello....'
  7. rightPad('hello', 10, 'ab'); // 'helloababa'
  8. rightPad('hello', 9, '\uD83D\uDC04'); // 'hello🐄🐄🐄🐄'
  9. rightPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // 'hello🐑🐄🐑🐄🐑'
  10. rightPad('hello', 7, '🐄'), // 'hello🐄🐄'
  11. rightPad(null, 7); // throws
  12. rightPad([], 4, '*'); // throws
  13. rightPad('hello', 4, true); // throws
  14. rightPad('hello', -4, true); // throws  
  15. rightPad('hello', 2.3, true); // throws    
  16. ```


[🍦 Try it](https://anguscroll.com/just/just-camel-case)

  1. ``` sh
  2. npm install just-camel-case
  3. ```
  1. ``` sh
  2. yarn add just-camel-case
  3. ```

Convert a string to camel case

  1. ``` js
  2.   import camelCase from 'just-camel-case';

  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'
  17. ```


[🍦 Try it](https://anguscroll.com/just/just-kebab-case)

  1. ``` sh
  2. npm install just-kebab-case
  3. ```
  1. ``` sh
  2. yarn add just-kebab-case
  3. ```

Convert a string to kebab case

  1. ``` js
  2.   import kebabCase from 'just-kebab-case';

  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'
  11. ```


[🍦 Try it](https://anguscroll.com/just/just-snake-case)

  1. ``` sh
  2. npm install just-snake-case
  3. ```
  1. ``` sh
  2. yarn add just-snake-case
  3. ```

Convert a string to snake case

  1. ``` js
  2.   import snakeCase from 'just-snake-case';

  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'
  10. ```


[🍦 Try it](https://anguscroll.com/just/just-pascal-case)

  1. ``` sh
  2. npm install just-pascal-case
  3. ```
  1. ``` sh
  2. yarn add just-pascal-case
  3. ```

Convert a string to pascal case

  1. ``` js
  2.   import pascalCase from 'just-pascal-case';

  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'
  10. ```


[🍦 Try it](https://anguscroll.com/just/just-capitalize)

  1. ``` sh
  2. npm install just-capitalize
  3. ```
  1. ``` sh
  2. yarn add just-capitalize
  3. ```

Capitalize the first character of a string

  1. ``` js
  2.   import capitalize from 'just-capitalize';

  3. /*
  4.   capitalize('capitals'); // 'Capitals'
  5.   capitalize('Capitals'); // 'Capitals'
  6.   capitalize('many words'); // 'Many words'
  7.   capitalize('!exclaim'); // '!exclaim'
  8. */
  9. ```


[🍦 Try it](https://anguscroll.com/just/just-replace-all)

  1. ``` sh
  2. npm install just-replace-all
  3. ```
  1. ``` sh
  2. yarn add just-replace-all
  3. ```

Replace all occurrences of a string within a string with another string

  1. ``` js
  2.   import replaceAll from 'just-replace-all';

  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. */
  17. ```

Numbers



[🍦 Try it](https://anguscroll.com/just/just-clamp)

  1. ``` sh
  2. npm install just-clamp
  3. ```
  1. ``` sh
  2. yarn add just-clamp
  3. ```

Restrict a number within a range

  1. ``` js
  2. import clamp from 'just-clamp';

  3. var n = 5;
  4. clamp(1, n, 12); // 5
  5. clamp(3, n, 1); // 3
  6. clamp(8, n, 9); // 8
  7. clamp(0, n, 0); // 0

  8. var n = -5;
  9. clamp(1, n, 12); // 1
  10. clamp(-7, n, -8); // -7

  11. clamp(NaN, n, 8); // NaN
  12. clamp(3, n, NaN); // NaN  
  13. clamp(3, NaN, 8); // NaN    

  14. clamp(undefined, n, 8); // throws
  15. clamp(3, n, 'h'); // throws  
  16. clamp(3, false, 8); // throws
  17. ```


[🍦 Try it](https://anguscroll.com/just/just-is-prime)

  1. ``` sh
  2. npm install just-is-prime
  3. ```
  1. ``` sh
  2. yarn add just-is-prime
  3. ```

Check if number is prime

  1. ``` js
  2.   import isPrime from 'just-is-prime;

  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. */
  15. ```


[🍦 Try it](https://anguscroll.com/just/just-modulo)

  1. ``` sh
  2. npm install just-modulo
  3. ```
  1. ``` sh
  2. yarn add just-modulo
  3. ```

Modulo of a number and a divisor

  1. ``` js
  2. import modulo from 'just-modulo';

  3. modulo(7, 5); // 2
  4. modulo(17, 23); // 17
  5. modulo(16.2, 3.8); // 1
  6. modulo(5.8, 3.4); //2.4
  7. modulo(4, 0); // 4
  8. modulo(-7, 5); // 3
  9. modulo(-2, 15); // 13
  10. modulo(-5.8, 3.4); // 1
  11. modulo(12, -1); // NaN
  12. modulo(-3, -8); // NaN
  13. modulo(12, 'apple'); // NaN
  14. modulo('bee', 9); // NaN
  15. modulo(null, undefined); // NaN
  16. ```


[🍦 Try it](https://anguscroll.com/just/just-random-integer)

  1. ``` sh
  2. npm install just-random-integer
  3. ```
  1. ``` sh
  2. yarn add just-random-integer
  3. ```

Produces a random integer within a given range

  1. ``` js
  2. import random from 'just-random-integer';

  3. random();
  4. // Returns either 0 or 1
  5. random(5);
  6. // Returns a random integer between 0 and 5 (inclusively)
  7. random(3, 10);
  8. // Returns a random integer between 3 and 10 (inclusively)
  9. random(-5.8, 10.4);
  10. // Returns a random integer between -5 and 10 (inclusively)
  11. ```

Functions



[🍦 Try it](https://anguscroll.com/just/just-compose)

  1. ``` sh
  2. npm install just-compose
  3. ```
  1. ``` sh
  2. yarn add just-compose
  3. ```

Return a function composed of 2 or more functions

  1. ``` js
  2. import compose from 'just-compose';

  3. const sqRootBiggest = compose(Math.max, Math.sqrt, Math.trunc);
  4. sqRootBiggest(10, 5); // 3
  5. sqRootBiggest(7, 0, 16); // 4
  6. ```


[🍦 Try it](https://anguscroll.com/just/just-curry-it)

  1. ``` sh
  2. npm install just-curry-it
  3. ```
  1. ``` sh
  2. yarn add just-curry-it
  3. ```

Return a curried function

  1. ``` js
  2. import curry from 'just-curry-it';

  3. function add(a, b, c) {
  4.   return a + b + c;
  5. }
  6. curry(add)(1)(2)(3); // 6
  7. curry(add)(1)(2)(2); // 5
  8. curry(add)(2)(4, 3); // 9

  9. function add(...args) {
  10.   return args.reduce((sum, n) => sum + n, 0)
  11. }
  12. var curryAdd4 = curry(add, 4)
  13. curryAdd4(1)(2, 3)(4); // 10

  14. function converter(ratio, input) {
  15.   return (input*ratio).toFixed(1);
  16. }
  17. const curriedConverter = curry(converter)
  18. const milesToKm = curriedConverter(1.62);
  19. milesToKm(35); // 56.7
  20. milesToKm(10); // 16.2
  21. ```


[🍦 Try it](https://anguscroll.com/just/just-demethodize)

  1. ``` sh
  2. npm install just-demethodize
  3. ```
  1. ``` sh
  2. yarn add just-demethodize
  3. ```

Turn a method into a standalone function; the first arg becomes this

  1. ``` js
  2. import demethodize from 'just-demethodize';

  3. const trimFn = demethodize(''.trim);
  4. ['hello ', ' goodbye', 'hello again'].map(trimFn); // ['hello', 'goodbye', 'hello again']
  5. ```


[🍦 Try it](https://anguscroll.com/just/just-flip)

  1. ``` sh
  2. npm install just-flip
  3. ```
  1. ``` sh
  2. yarn add just-flip
  3. ```

Flip first two arguments of a function

  1. ``` js
  2. import flip from 'just-flip';

  3. flip(console.log)(1, 2, 3) // 2, 1, 3

  4. import map from 'just-map-object';
  5. import partial from 'just-partial';

  6. const numbers = {x: 5, y: 10};
  7. const flippedMap = flip(map);
  8. const double = partial(flippedMap, (undefined, number) => number * 2);
  9. double(numbers) // {x: 10, y: 20];
  10. ```


[🍦 Try it](https://anguscroll.com/just/just-partial-it)

  1. ``` sh
  2. npm install just-partial-it
  3. ```
  1. ``` sh
  2. yarn add just-partial-it
  3. ```

Return a partial function

  1. ``` js