From 44a032cde11fd8a2def10cd8e4e6db57e051f532 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 27 Sep 2023 15:59:38 -0400 Subject: [PATCH 1/4] feat: use yaml for package data instead of json --- md-variables.json | 1718 ----------------------------------- package.json | 3 +- packages.yml | 1551 +++++++++++++++++++++++++++++++ scripts/generate-readmes.js | 10 +- yarn.lock | 5 + 5 files changed, 1566 insertions(+), 1721 deletions(-) delete mode 100644 md-variables.json create mode 100644 packages.yml diff --git a/md-variables.json b/md-variables.json deleted file mode 100644 index 568053e97..000000000 --- a/md-variables.json +++ /dev/null @@ -1,1718 +0,0 @@ -{ - "just-cartesian-product": { - "packageName": "just-cartesian-product", - "dir": "array-cartesian-product", - "description": "Takes an input of an array of arrays and returns their Cartesian product.", - "examples": [ - "import cartesianProduct from 'just-cartesian-product';", - "", - "cartesianProduct([[1, 2], ['a', 'b']]); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]", - "cartesianProduct([[1, 2], ['a', 'b', 'c']]); // [[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c']]", - "cartesianProduct([]); // []", - "cartesianProduct(); // throws" - ] - }, - "just-compact": { - "packageName": "just-compact", - "dir": "array-compact", - "description": "Returns a copy of an array with falsey values removed", - "examples": [ - "import compact from 'just-compact';", - "", - "compact([1, null, 2, undefined, null, NaN, 3, 4, false, 5]); // [1, 2, 3, 4, 5]", - "compact([1, 2, [], 4, {}]); // [1, 2, [], 4, {}]", - "compact([]); // []", - "compact({}); // throws" - ] - }, - "just-flatten-it": { - "packageName": "just-flatten-it", - "dir": "array-flatten", - "description": "Return a flattened array", - "examples": [ - "import flatten from 'just-flatten-it';", - "", - "flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]]);", - "// [1, 2, 3, 4, 5, 6, 7, 8, 9]", - "", - "flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]], 1);", - "// [1, [2, 3], [[4, 5], 6, 7, [8, 9]]]" - ] - }, - "just-group-by": { - "packageName": "just-group-by", - "dir": "array-group-by", - "description": "Return a grouped object from array", - "examples": [ - "import groupBy from 'just-group-by';", - "", - "groupBy([6.1, 4.2, 6.3], Math.floor); // { '4': [4.2], '6': [6.1, 6.3] }", - "groupBy([1,2,3,4,5,6,7,8], function(i) { return i % 2}); // { '0': [2, 4, 6, 8], '1': [1, 3, 5, 7] }" - ] - }, - "just-index": { - "packageName": "just-index", - "dir": "array-index", - "description": "Return an object from an array, keyed by the value at the given id", - "examples": [ - "import index from 'just-index';", - "", - "index([{id: 'first', val: 1}, {id: 'second', val: 2}], 'id');", - "// {first: {id: 'first', val: 1}, second: {id: 'second', val: 2}}", - "index([{id: 'first', val: 1}, null], 'id'); // {first: {id: 'first', val: 1}}", - "index([], 'id'); // {}", - "index([], null); // undefined", - "index({}, 'id'); // undefined" - ] - }, - "just-insert": { - "packageName": "just-insert", - "dir": "array-insert", - "description": "Inserts a sub-array into an array starting at the given index. Returns a copy", - "examples": [ - "import insert from 'just-insert';", - "", - "insert([1, 2, 5, 6], ['a', 'c', 'e'], 2); // [1, 2, 'a', 'c', 'e', 5, 6]", - "insert([1, 2, 5, 6], 'a', 2); // [1, 2, 'a', 5, 6]", - "insert([1, 2, 5, 6], ['a', 'c', 'e'], 0); // ['a', 'c', 'e', 1, 2, 5, 6]", - "insert([1, 2, 5, 6], ['a', 'c', 'e']); // ['a', 'c', 'e', 1, 2, 5, 6]" - ] - }, - "just-intersect": { - "packageName": "just-intersect", - "dir": "array-intersect", - "description": "Return the intersect of two arrays", - "examples": [ - "import intersect from 'just-intersect';", - "", - "intersect([1, 2, 5, 6], [2, 3, 5, 6]); // [2, 5, 6]", - "intersect([1, 2, 2, 4, 5], [3, 2, 2, 5, 7]); // [2, 5] " - ] - }, - "just-last": { - "packageName": "just-last", - "dir": "array-last", - "description": "Return the last member of an array", - "examples": [ - "import last from 'just-last';", - "", - "last([1, 2, 3, 4, 5]); // 5", - "last([{a: 1}, {b: 1}, {c: 1}]); // {c: 1}", - "last([true, false, [true, false]]); // [true, false]", - "last(); // undefined", - "last([]); // undefined", - "last(null); // undefined", - "last(undefined); // undefined" - ] - }, - "just-mean": { - "packageName": "just-mean", - "dir": "array-mean", - "description": "The mean (average) value in an array", - "examples": [ - "import mean from 'just-mean';", - "", - "mean([1, 2, 3, 2, 4, 1]); // 2.1666666667", - "mean(3, 2, 1); // 2", - "mean([4]); // 4", - "mean(['3', 2]); // throws", - "mean(); // throws" - ] - }, - "just-median": { - "packageName": "just-median", - "dir": "array-median", - "description": "Return the median value of an array of numbers", - "examples": [ - "import median from 'just-median';", - "", - "median([1, 2, 3, 4, 5]); // 3", - "median([3, -1, 2]); // 2", - "median([9, 14, 14, 200, 15]); // 14", - "median(1, 2, 4, 3); // 2.5", - "median(['3', 2, 1]); // throws", - "median(); // throws" - ] - }, - "just-mode": { - "packageName": "just-mode", - "dir": "array-mode", - "description": "Return the most frequently occuring number(s)", - "examples": [ - "import mode from 'just-mode';", - "", - "mode([1, 2, 3, 2]); // 2", - "mode(4, 4, 1, 4); // 4", - "mode(100, 100, 101, 101); // [100, 101]", - "mode(4, 3, 2, 1); // [1, 2, 3, 4]", - "mode(['1', 2, 2, 1, 2]); // throws", - "mode(null); // throws" - ] - }, - "just-order-by": { - "packageName": "just-order-by", - "dir": "array-order-by", - "description": "Produces a new array, sorted in given order", - "examples": [ - "import orderBy from 'just-order-by';", - "", - "orderBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35]", - "", - "orderBy(", - " [", - " { user: 'fabio', details: { city: 'Milan', age: 34 } },", - " { user: 'max', details: { city: 'Munich', age: 29 } },", - " { user: 'zacarias', details: { city: 'Sao Paulo', age: 44 } },", - " { user: 'robert', details: { city: 'Manchester', age: 28 } },", - " { user: 'max', details: { city: 'Zurich', age: 38 } },", - " ],", - " [", - " {", - " property(v) {", - " return v.details.age;", - " },", - " },", - " ]", - ");", - "", - "/*", - "[", - " {user: 'robert', age: 28},", - " {user: 'max', age: 29},", - " {user: 'fabio', age: 34},", - " {user: 'klaus', age: 38},", - " {user: 'zacarias', age: 44},", - "]", - "*/", - "", - "orderBy(", - " [", - " {user: 'fabio', age: 34},", - " {user: 'max', age: 29},", - " {user: 'zacarias', age: 44},", - " {user: 'robert', age: 28},", - " {user: 'klaus', age: 38},", - " ],", - " [", - " {", - " property: 'user',", - " },", - " ]", - ");", - "", - "/*", - "[", - " {user: 'fabio', age: 34},", - " {user: 'klaus', age: 38},", - " {user: 'max', age: 29},", - " {user: 'robert', age: 28},", - " {user: 'zacarias', age: 44},", - "]", - "*/", - "", - "orderBy(", - " [", - " { user: 'fabio', age: 34 },", - " { user: 'max', age: 29 },", - " { user: 'zacarias', age: 44 },", - " { user: 'moris', age: 28 },", - " { user: 'max', age: 38 },", - " ],", - " [", - " {", - " property: 'user',", - " order: 'desc',", - " },", - " {", - " property(v) {", - " return v.age;", - " },", - " },", - " ]", - ");", - "", - "/*", - "[", - " {", - " user: 'zacarias',", - " age: 44", - " },", - " {", - " user: 'moris',", - " age: 28", - " },", - " {", - " user: 'max',", - " age: 29", - " },", - " {", - " user: 'max',", - " age: 38", - " },", - " {", - " user: 'fabio',", - " age: 34", - " }", - "]", - "*/" - ] - }, - "just-partition": { - "packageName": "just-partition", - "dir": "array-partition", - "description": "Elements satisfying predicate added to first array, remainder added to second", - "examples": [ - "import partition from 'just-partition';", - "", - "partition([1, 5, 2, 4, 3], n => n > 3); // [[5, 4],[1, 2, 3]]", - "partition(['a', 2, 3, '3'], x => typeof x == 'string'); // [['a', '3'],[2, 3]]", - "partition([1, 2, 3, 4], x => typeof x == 'number'); // [[1, 2, 3, 4],[]]", - "partition([1, 2, 3, 4], x => typeof x == 'string'); // [[], [1, 2, 3, 4]]", - "partition([], n => n > 3); // [[], []]", - "partition({a: 1, b: 2}, n => n > 1); // throws", - "partition(null, n => n > 1); // throws", - "partition(undefined, n => n > 1); // throws" - ] - }, - "just-percentile": { - "packageName": "just-percentile", - "dir": "array-percentile", - "description": "Return the value at the given percentile (using linear interpolation)", - "examples": [ - "import percentile from 'just-percentile';", - "", - "percentile([1, 2, 3], 0); // 1", - "percentile([1, 2, 3], 0.5); // 2", - "percentile([1, 2, 3], 1); // 3", - "", - "// See https://en.wikipedia.org/wiki/Percentile (linear interpolation method)", - "percentile([15, 20, 35, 40, 50], 0.05); // 15", - "percentile([15, 20, 35, 40, 50], 0.3); // 20", - "percentile([15, 20, 35, 40, 50], 0.4); // 27.5", - "percentile([15, 20, 35, 40, 50], 0.95); // 50", - "", - "percentile(1, 2, 3, 50); // throws", - "percentile(['1', 2, 3], 50); // throws", - "percentile([], 50); // throws" - ] - }, - "just-permutations": { - "packageName": "just-permutations", - "dir": "array-permutations", - "description": "Returns all permutations of the length N of the elements of the given Array", - "examples": [ - "import permutations from 'just-permutations';", - "", - "permutations([1, 2, 3]); // [[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]", - "permutations([]); // []", - "permutations(); // throws" - ] - }, - "just-pipe": { - "packageName": "just-pipe", - "dir": "function-pipe", - "description": "Pass a value through a pipeline of functions", - "examples": [ - "import pipe from 'just-pipe", - "", - "pipe(3, a => a+1, b => b*2) // 8", - "pipe('John Smith', a => a.split(' '), b => b.reverse(), c => c[0]) // 'Smith'" - ] - }, - "just-random": { - "packageName": "just-random", - "dir": "array-random", - "description": "Return a randomly selected element in an array", - "examples": [ - "import random from 'just-random';", - "", - "random([1, 2, 3]);", - "// one of [1, 2, 3], at random" - ] - }, - "just-range": { - "packageName": "just-range", - "dir": "array-range", - "description": "Generate a range array for numbers", - "examples": [ - "import range from 'just-range';", - "", - "range(1, 5); // [1, 2, 3, 4]", - "range(5); // [0, 1, 2, 3, 4]", - "range(-5); // [0, -1, -2, -3, -4]", - "range(0, 20, 5) // [0, 5, 10, 15]" - ] - }, - "just-remove": { - "packageName": "just-remove", - "dir": "array-remove", - "description": "Removes one array from another", - "examples": [ - "import remove from 'just-remove';", - "", - "remove([1, 2, 3, 4, 5, 6], [1, 3, 6]); // [2, 4, 5]" - ] - }, - "just-shuffle": { - "packageName": "just-shuffle", - "dir": "array-shuffle", - "description": "Return the elements of an array in random order", - "examples": [ - "import shuffle from 'just-shuffle';", - "", - "shuffle([1, 2, 3]); ", - "// array with original elements randomly sorted", - "shuffle([1, 2, 3], {shuffleAll: true}); ", - "// array with original elements randomly sorted and all in new postions", - "shuffle([]); // []", - "shuffle([1]); // [1]", - "shuffle(); // throws", - "shuffle(undefined); // throws", - "shuffle(null); // throws", - "shuffle({}); // throws" - ] - }, - "just-skewness": { - "packageName": "just-skewness", - "dir": "array-skewness", - "description": "Return the skewness of an array or numeric argument list using Pearson's second skewness coefficient", - "examples": [ - "import skewness from \"just-skewness\";", - "", - "// Using Pearson's second skewness coefficient", - "skewness(3, 2, 1); // 0", - "skewness([1, 2, 3, 2, 4, 1]); // 0.4276994613841504", - "skewness(1, 2, 3, 4, 5, -6); // -0.762000762001143", - "skewness([1, 2, 3, 4, 9]); // 0.7705935588815224", - "skewness([4]); // throws", - "skewness([\"3\", 2]); // throws", - "skewness(NaN, NaN); // throws", - "skewness(); // throws" - ] - }, - "just-sort-by": { - "packageName": "just-sort-by", - "dir": "array-sort-by", - "description": "Produces a new array, sorted in ascending order", - "examples": [ - "import sortBy from 'just-sort-by';", - "", - "sortBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35]", - "", - "sortBy([", - " {user: 'fabio', details: {city: \"Milan\", age: 34}},", - " {user: 'max', details: {city: \"Munich\", age: 29}},", - " {user: 'zacarias', details: {city: \"Sao Paulo\", age: 44}},", - " {user: 'robert', details: {city: \"Manchester\", age: 28}},", - " {user: 'klaus', details: {city: \"Zurich\", age: 38}},", - "], function(o) {", - " return o.details.age;", - "});", - "", - "/*", - "[", - " {user: 'robert', age: 28},", - " {user: 'max', age: 29},", - " {user: 'fabio', age: 34},", - " {user: 'klaus', age: 38},", - " {user: 'zacarias', age: 44},", - "]", - "*/", - "", - "sortBy([", - " {user: 'fabio', age: 34},", - " {user: 'max', age: 29},", - " {user: 'zacarias', age: 44},", - " {user: 'robert', age: 28},", - " {user: 'klaus', age: 38},", - "], 'user');", - "/*", - "[", - " {user: 'fabio', age: 34},", - " {user: 'klaus', age: 38},", - " {user: 'max', age: 29},", - " {user: 'robert', age: 28},", - " {user: 'zacarias', age: 44},", - "]", - "*/" - ] - }, - "just-split": { - "packageName": "just-split", - "dir": "array-split", - "description": "Splits array into groups of n items each", - "examples": [ - "import split from 'just-split';", - "", - "split([]); // []", - "split([1, 2, 3, 4, 5]); // [[1, 2, 3, 4, 5]]", - "split([1, 2, 3, 4, 5, 6, 7, 8, 9], 3); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]", - "split([1, 2, 3, 4, 5, 6, 7, 8, 9], '3'); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]", - "split(['a', 'b', 'c', 'd', 'e'], 2); // [['a', 'b'], ['c', 'd'], ['e']]", - "split([1, 2, 3, 4, 5, 6, 7, 8], 3); // [[1, 2, 3], [4, 5, 6], [7, 8]]" - ] - }, - "just-split-at": { - "packageName": "just-split-at", - "dir": "array-split-at", - "description": "Splits an array into two at a given position", - "examples": [ - "import splitAt from 'just-split-at';", - "", - "splitAt([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4, 5]]", - "splitAt([{a: 1}, {b: 1}, {c: 1}], -1); // [[{a: 1}, {b: 1}], [{c: 1}]]", - "splitAt([], 2); // [[], []]", - "splitAt(null, 1); // throws", - "splitAt(undefined, 1); // throws" - ] - }, - "just-standard-deviation": { - "packageName": "just-standard-deviation", - "dir": "array-standard-deviation", - "description": "Return the standard deviation of an array or numeric argument list", - "examples": [ - "import standardDeviation from \"just-standard-deviation\";", - "", - "standardDeviation([1, 2, 3, 2, 4, 1]); // 1.16904519", - "standardDeviation(3, 2, 1); // 1", - "standardDeviation([100, 100, 100.1, 100]); // 0.05", - "standardDeviation(1, 2, 3, 4, 5, -6); // 3.9370039", - "standardDeviation([4]); // throws", - "standardDeviation([\"3\", 2]); // throws", - "standardDeviation(NaN, NaN); // throws", - "standardDeviation(); // throws" - ] - }, - "just-tail": { - "packageName": "just-tail", - "dir": "array-tail", - "description": "Return all but the first element of an array", - "examples": [ - "import tail from 'just-tail';", - "", - "tail([1, 2, 3, 4, 5]); // [2, 3, 4, 5]", - "tail([{a: 1}, {b: 1}, {c: 1}]); // [{b: 1}, {c: 1}]", - "tail([true, false, [true, false]]); // [false, [true, false]]", - "tail([]); // []", - "tail(); // undefined", - "tail(null); // undefined", - "tail(undefined); // undefined" - ] - }, - "just-union": { - "packageName": "just-union", - "dir": "array-union", - "description": "Returns the union of two arrays", - "examples": [ - "import union from 'just-union';", - "", - "union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 5, 6, 3, 4]" - ] - }, - "just-unique": { - "packageName": "just-unique", - "dir": "array-unique", - "description": "Dedupes an array", - "examples": [ - "import unique from 'just-unique';", - "", - "unique([1, 2, 3, 2, 3, 4, 3, 2, 1, 3]); // [1, 2, 3, 4]", - "", - "var a = {a: 3};", - "var b = {b: 4};", - "var c = {c: 5};", - "unique([a, a, b, c, b]); // [a, b, c]", - "", - "unique([1, '1', 2, '2', 3, 2]); // [1, '1', 2, '2', 3]", - "", - "// declaring sorted array for performance", - "unique([1, 1, '1', 2, 2, 5, '5', '5'], true); // [1, '1', 2, 5, '6']", - "", - "// declaring strings array for performance", - "unique(['a', 'c', 'b', 'c', 'a'], false, true); // ['a', 'b', 'c']" - ] - }, - "just-variance": { - "packageName": "just-variance", - "dir": "array-variance", - "description": "Return the standard deviation of an array or numeric argument list", - "examples": [ - "import variance from 'just-variance';", - "", - "variance([1, 2, 3, 2, 4, 1]); // 1.3666666667", - "variance(3, 2, 1); // 1", - "variance([100, 100, 100.1, 100]); // 0.0025", - "variance(1, 2, 3, 4, 5, -6); // 15.5", - "variance([4]); // throws", - "variance(['3', 2]); // throws", - "variance(NaN, NaN); // throws", - "variance(); // throws" - ] - }, - "just-zip-it": { - "packageName": "just-zip-it", - "dir": "array-zip", - "description": "Returns an array of grouped elements, taking n-th element from every given array", - "examples": [ - "import zip from 'just-zip-it';", - "", - "zip([1, 2, 3]); // [[1], [2], [3]]", - "zip([1, 2, 3], ['a', 'b', 'c']); // [[1, 'a'], [2, 'b'], [3, 'c']]", - "zip([1, 2], ['a', 'b'], [true, false]); //[[1, 'a', true], [2, 'b', false]]", - "", - "zip(undefined, {}, false, 1, 'foo'); // []", - "zip([1, 2], ['a', 'b'], undefined, {}, false, 1, 'foo'); // [[1, 'a'], [2, 'b']]", - "", - "zip([1, 2, 3], ['a', 'b'], [true]); // [[1, 'a', true], [2, 'b', undefined], [3, undefined, undefined]]" - ] - }, - "just-clone": { - "packageName": "just-clone", - "dir": "collection-clone", - "description": "Deep copies objects, arrays, maps and sets", - "examples": [ - "// Deep copies objects and arrays, doesn't clone functions", - "", - "import clone from 'just-clone';", - "", - "var arr = [1, 2, 3];", - "var subObj = { aa: 1 };", - "var obj = { a: 3, b: 5, c: arr, d: subObj };", - "var objClone = clone(obj);", - "arr.push(4);", - "objClone.d.bb = 2;", - "obj; // {a: 3, b: 5, c: [1, 2, 3, 4], d: {aa: 1}}", - "objClone; // {a: 3, b: 5, c: [1, 2, 3], d: {aa: 1, bb: 2}}" - ] - }, - "just-compare": { - "packageName": "just-compare", - "dir": "collection-compare", - "description": "Compare two collections", - "examples": [ - "import compare from 'just-compare';", - "", - "// primitives: value1 === value2", - "// functions: value1.toString == value2.toString", - "// arrays: if length, sequence and values of properties are identical", - "// objects: if length, names and values of properties are identical", - "compare([1, [2, 3]], [1, [2, 3]]); // true", - "compare([1, [2, 3], 4], [1, [2, 3]]); // false", - "compare({a: 2, b: 3}, {a: 2, b: 3}); // true", - "compare({a: 2, b: 3}, {b: 3, a: 2}); // true", - "compare({a: 2, b: 3, c: 4}, {a: 2, b: 3}); // false", - "compare({a: 2, b: 3}, {a: 2, b: 3, c: 4}); // false", - "compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}]]); // false", - "compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}], 4]); // true", - "compare(NaN, NaN); // true" - ] - }, - "just-diff": { - "packageName": "just-diff", - "dir": "collection-diff", - "description": [ - "Return an object representing the difference between two other objects", - "Pass converter to format as http://jsonpatch.com" - ], - "examples": [ - "import {diff} from 'just-diff';", - "", - "const obj1 = {a: 4, b: 5};", - "const obj2 = {a: 3, b: 5};", - "const obj3 = {a: 4, c: 5};", - "", - "diff(obj1, obj2);", - "[", - " { \"op\": \"replace\", \"path\": ['a'], \"value\": 3 }", - "]", - "", - "diff(obj2, obj3);", - "[", - " { \"op\": \"remove\", \"path\": ['b'] },", - " { \"op\": \"replace\", \"path\": ['a'], \"value\": 4 }", - " { \"op\": \"add\", \"path\": ['c'], \"value\": 5 }", - "]", - "", - "// using converter to generate jsPatch standard paths", - "import {diff, jsonPatchPathConverter} from 'just-diff'", - "diff(obj1, obj2, jsonPatchPathConverter);", - "[", - " { \"op\": \"replace\", \"path\": '/a', \"value\": 3 }", - "]", - "", - "diff(obj2, obj3, jsonPatchPathConverter);", - "[", - " { \"op\": \"remove\", \"path\": '/b' },", - " { \"op\": \"replace\", \"path\": '/a', \"value\": 4 }", - " { \"op\": \"add\", \"path\": '/c', \"value\": 5 }", - "]", - "", - "// arrays", - "const obj4 = {a: 4, b: [1, 2, 3]};", - "const obj5 = {a: 3, b: [1, 2, 4]};", - "const obj6 = {a: 3, b: [1, 2, 4, 5]};", - "", - "diff(obj4, obj5);", - "[", - " { \"op\": \"replace\", \"path\": ['a'], \"value\": 3 }", - " { \"op\": \"replace\", \"path\": ['b', 2], \"value\": 4 }", - "]", - "", - "diff(obj5, obj6);", - "[", - " { \"op\": \"add\", \"path\": ['b', 3], \"value\": 5 }", - "]", - "", - "// nested paths", - "const obj7 = {a: 4, b: {c: 3}};", - "const obj8 = {a: 4, b: {c: 4}};", - "const obj9 = {a: 5, b: {d: 4}};", - "", - "diff(obj7, obj8);", - "[", - " { \"op\": \"replace\", \"path\": ['b', 'c'], \"value\": 4 }", - "]", - "", - "diff(obj8, obj9);", - "[", - " { \"op\": \"replace\", \"path\": ['a'], \"value\": 5 }", - " { \"op\": \"remove\", \"path\": ['b', 'c']}", - " { \"op\": \"add\", \"path\": ['b', 'd'], \"value\": 4 }", - "]" - ] - }, - "just-diff-apply": { - "packageName": "just-diff-apply", - "dir": "collection-diff-apply", - "description": "Apply a diff object to an object. Pass converter to apply a http://jsonpatch.com standard patch", - "examples": [ - " import {diffApply} from 'just-diff-apply';", - "", - " const obj1 = {a: 3, b: 5};", - " diffApply(obj1,", - " [", - " { \"op\": \"remove\", \"path\": ['b'] },", - " { \"op\": \"replace\", \"path\": ['a'], \"value\": 4 },", - " { \"op\": \"add\", \"path\": ['c'], \"value\": 5 }", - " ]", - " );", - " obj1; // {a: 4, c: 5}", - "", - " const obj2 = {a: 3, b: 5};", - " diffApply(obj2,", - " [", - " { \"op\": \"move\", \"from\": ['a'], \"path\": ['c']},", - " ]", - " );", - " obj2; // {b: 5, c: 3}", - "", - " // using converter to apply jsPatch standard paths", - " // see http://jsonpatch.com", - " import {diffApply, jsonPatchPathConverter} from 'just-diff-apply'", - " const obj3 = {a: 3, b: 5};", - " diffApply(obj3, [", - " { \"op\": \"remove\", \"path\": '/b' },", - " { \"op\": \"replace\", \"path\": '/a', \"value\": 4 }", - " { \"op\": \"add\", \"path\": '/c', \"value\": 5 }", - " ], jsonPatchPathConverter);", - " obj3; // {a: 4, c: 5}", - "", - " // arrays (array key can be string or numeric)", - " const obj4 = {a: 4, b: [1, 2, 3]};", - " diffApply(obj4, [", - " { \"op\": \"replace\", \"path\": ['a'], \"value\": 3 }", - " { \"op\": \"replace\", \"path\": ['b', 2], \"value\": 4 }", - " { \"op\": \"add\", \"path\": ['b', 3], \"value\": 9 }", - " ]);", - " obj4; // {a: 3, b: [1, 2, 4, 9]}", - "", - " // nested paths", - " const obj5 = {a: 4, b: {c: 3}};", - " diffApply(obj5, [", - " { \"op\": \"replace\", \"path\": ['a'], \"value\": 5 }", - " { \"op\": \"remove\", \"path\": ['b', 'c']}", - " { \"op\": \"add\", \"path\": ['b', 'd'], \"value\": 4 }", - " ]);", - " obj5; // {a: 5, b: {d: 4}}" - ] - }, - "just-flush": { - "packageName": "just-flush", - "dir": "collection-flush", - "description": "Returns a copy of an array or object with null/undefined members removed", - "examples": [ - "import flush from 'just-flush';", - "", - "flush([1, undefined, 2, null, 3, NaN, 0]); // [1, 2, 3, NaN, 0]", - "flush([true, null, false, true, [null], undefined]); // [true, false, true, [null]]", - "flush({a: 2, b: null, c: 4, d: undefined}); // {a: 2, c: 4}", - "flush('something'); // undefined", - "flush(); // undefined" - ] - }, - "just-pluck-it": { - "packageName": "just-pluck-it", - "dir": "collection-pluck", - "description": "Pluck a property from each member of a collection", - "examples": [ - "import pluck from 'just-pluck-it';", - "", - "pluck([{a:1, b:2}, {a:4, b:3}, {a:2, b:5}], 'a'); // [1, 4, 2]", - "pluck({x: {a:1, b:2}, y: {a:4, b:3}, z: {a:2, b:5}}, 'a'); // {x: 1, y: 4, z: 2}" - ] - }, - "just-compose": { - "packageName": "just-compose", - "dir": "function-compose", - "description": "Return a function composed of 2 or more functions", - "examples": [ - "import compose from 'just-compose';", - "", - "const sqRootBiggest = compose(Math.max, Math.sqrt, Math.trunc);", - "sqRootBiggest(10, 5); // 3", - "sqRootBiggest(7, 0, 16); // 4" - ] - }, - "just-curry-it": { - "packageName": "just-curry-it", - "dir": "function-curry", - "description": "Return a curried function", - "examples": [ - "import curry from 'just-curry-it';", - "", - "function add(a, b, c) {", - " return a + b + c;", - "}", - "curry(add)(1)(2)(3); // 6", - "curry(add)(1)(2)(2); // 5", - "curry(add)(2)(4, 3); // 9", - "", - "function add(...args) {", - " return args.reduce((sum, n) => sum + n, 0)", - "}", - "var curryAdd4 = curry(add, 4)", - "curryAdd4(1)(2, 3)(4); // 10", - "", - "function converter(ratio, input) {", - " return (input*ratio).toFixed(1);", - "}", - "const curriedConverter = curry(converter)", - "const milesToKm = curriedConverter(1.62);", - "milesToKm(35); // 56.7", - "milesToKm(10); // 16.2" - ] - }, - "just-debounce-it": { - "packageName": "just-debounce-it", - "dir": "function-debounce", - "description": "Return a debounced function", - "examples": [ - "import debounce from \"just-debounce-it\";", - "", - "const fn1 = debounce(() => console.log(\"Hello\"), 500);", - "fn1();", - "fn1();", - "fn1();", - "// 500ms later logs 'hello' once", - "", - "const fn2 = debounce(() => console.log(\"Hello\"), 500, true);", - "fn2(); // logs hello immediately", - "fn2();", - "fn2();", - "// 500ms later logs 'hello' once", - "", - "const fn3 = debounce(() => console.log(\"Hello\"), 500);", - "fn3();", - "fn3();", - "fn3();", - "fn3.cancel();", - "// function cancelled before 'hello' is logged", - "", - "const fn4 = debounce(() => console.log(\"Hello\"), 500);", - "fn4();", - "fn4();", - "fn4();", - "fn4.flush();", - "// immediately invoke the debounced function" - ] - }, - "just-demethodize": { - "packageName": "just-demethodize", - "dir": "function-demethodize", - "description": "Turn a method into a standalone function; the first arg becomes `this`", - "examples": [ - "import demethodize from 'just-demethodize';", - "", - "const trimFn = demethodize(''.trim);", - "['hello ', ' goodbye', 'hello again'].map(trimFn); // ['hello', 'goodbye', 'hello again']" - ] - }, - "just-flip": { - "packageName": "just-flip", - "dir": "function-flip", - "description": "Flip first two arguments of a function", - "examples": [ - "import flip from 'just-flip';", - "", - "flip(console.log)(1, 2, 3) // 2, 1, 3", - "", - "import map from 'just-map-object';", - "import partial from 'just-partial';", - "", - "const numbers = {x: 5, y: 10};", - "const flippedMap = flip(map);", - "const double = partial(flippedMap, (undefined, number) => number * 2);", - "double(numbers) // {x: 10, y: 20];" - ] - }, - "just-memoize": { - "packageName": "just-memoize", - "dir": "function-memoize", - "description": "An implementation of the memoize technique", - "examples": [ - "import memoize from 'just-memoize';", - "", - "const sumByOne = memoize(function(value) {", - " return value + 1;", - "});", - "", - "sumByOne(10); // Returns value returned by the function", - "sumByOne(10); // Cache hit!", - "", - "sumByOne(20); // Returns value returned by the function", - "sumByOne(20); // Cache hit!", - "", - "// Custom cache key (key defaults to JSON stringified arguments)", - "var sum = memoize(function(a, b) {", - " return a + b;", - "}, function(a, b) {", - " return `${a}-${b}`;", - "});", - "", - "sum(10, 10); // Returns value returned by the function", - "sum(10, 20); // Returns value returned by the function", - "sum(10, 20); // Cache hit!" - ] - }, - "just-memoize-last": { - "packageName": "just-memoize-last", - "dir": "function-memoize-last", - "description": "A memoize implementation that only caches the most recent evaluation", - "examples": [ - "const memoizeLast = require('just-memoize-last')", - "const compare = require('just-compare')", - "", - "const maxValue = memoizeLast(function(arr) {", - " return Math.max(...arr)", - "}, function(a, b) {", - " return compare(a, b)", - "});", - "", - "maxValue([1,2,3]) // 3", - "maxValue([1,2,3]) // cache hit!", - "maxValue([1,3,4]) // 4", - "maxValue([1,2,3]) // 3" - ] - }, - "just-once": { - "packageName": "just-once", - "dir": "function-once", - "description": "Create a function that can only be invoked once", - "examples": [ - "import once from 'just-once';", - "", - "const fn = once(() => console.log('hello'));", - "", - "fn();", - "// logs 'hello'", - "fn();", - "// does nothing" - ] - }, - "just-partial-it": { - "packageName": "just-partial-it", - "dir": "function-partial", - "description": "Return a partial function", - "examples": [ - "import partial from 'just-partial-it';", - "", - "const cubedRoot = partial(Math.pow, _, 1/3);", - "cubedRoot(64); // 4", - "", - "const getRoot = partial(Math.pow, 64);", - "getRoot(1/2); // 8" - ] - }, - "just-throttle": { - "packageName": "just-throttle", - "dir": "function-throttle", - "description": "Return a throttled function", - "examples": [ - "import throttle from 'just-throttle';", - "", - "// no matter how many times the function is called, only invoke once within the given interval", - "// options: ", - "// `leading`: invoke before interval", - "// `trailing`: invoke afer interval", - "", - "const fn1 = throttle(() => console.log('hello'), 500, {leading: true});", - "setInterval(fn1, 400);", - "// logs 'hello' immediately and then every 500ms", - "", - "const fn2 = throttle(() => console.log('hello'), 500, {trailing: true});", - "setInterval(fn2, 400);", - "// logs 'hello' after 500ms and then every 500ms", - "", - "const fn3 = throttle(() => console.log('hello'), 500, {leading: true, trailing: true});", - "// forces trailing to false", - "", - "const fn4 = throttle(() => console.log('hello'), 500, { leading: false });", - "fn4();", - "fn4();", - "fn4();", - "fn4.cancel();", - "// function cancelled before 'hello' is logged", - "", - "const fn5 = throttle(() => console.log(\"Hello\"), 500);", - "fn5();", - "fn5();", - "fn5();", - "fn5.flush();", - "// immediately invoke the throttled function" - ] - }, - "just-clamp": { - "packageName": "just-clamp", - "dir": "number-clamp", - "description": "Restrict a number within a range", - "examples": [ - "import clamp from 'just-clamp';", - "", - "var n = 5;", - "clamp(1, n, 12); // 5", - "clamp(3, n, 1); // 3", - "clamp(8, n, 9); // 8", - "clamp(0, n, 0); // 0", - "", - "var n = -5;", - "clamp(1, n, 12); // 1", - "clamp(-7, n, -8); // -7", - "", - "clamp(NaN, n, 8); // NaN", - "clamp(3, n, NaN); // NaN ", - "clamp(3, NaN, 8); // NaN ", - "", - "clamp(undefined, n, 8); // throws", - "clamp(3, n, 'h'); // throws ", - "clamp(3, false, 8); // throws " - ] - }, - "just-in-range": { - "packageName": "just-in-range", - "dir": "number-in-range", - "description": "Check if number is within a given range", - "examples": [ - " import inRange from 'just-number-in-range'", - "", - "/*", - " inRange(2, 1, 10); // true", - " inRange(15, 20); // true", - " inRange(20, 21, 30); // false", - " inRange(30, 21, 30); // false", - " inRange(); // throws", - " inRange(100); // throws", - " inRange(\"js\"); // throws", - "*/" - ] - }, - "just-is-prime": { - "packageName": "just-is-prime", - "dir": "number-is-prime", - "description": "Check if number is prime", - "examples": [ - " import isPrime from 'just-is-prime;", - "", - "/*", - " isPrime(1); // false", - " isPrime(2); // true", - " isPrime(17); // true", - " isPrime(10); // false", - " isPrime(); // throws", - " isPrime(null); // throws", - " isPrime(\"js\"); // throws", - " isPrime({}); // throws", - " isPrime(function() {}); // throws", - " isPrime([]); // throws", - "*/" - ] - }, - "just-modulo": { - "packageName": "just-modulo", - "dir": "number-modulo", - "description": "Modulo of a number and a divisor", - "examples": [ - "import modulo from 'just-modulo';", - "", - "modulo(7, 5); // 2", - "modulo(17, 23); // 17", - "modulo(16.2, 3.8); // 1", - "modulo(5.8, 3.4); //2.4", - "modulo(4, 0); // 4", - "modulo(-7, 5); // 3", - "modulo(-2, 15); // 13", - "modulo(-5.8, 3.4); // 1", - "modulo(12, -1); // NaN", - "modulo(-3, -8); // NaN", - "modulo(12, 'apple'); // NaN", - "modulo('bee', 9); // NaN", - "modulo(null, undefined); // NaN" - ] - }, - "just-random-integer": { - "packageName": "just-random-integer", - "dir": "number-random-integer", - "description": "Produces a random integer within a given range", - "examples": [ - "import random from 'just-random-integer';", - "", - "random();", - "// Returns either 0 or 1", - "random(5);", - "// Returns a random integer between 0 and 5 (inclusively)", - "random(3, 10);", - "// Returns a random integer between 3 and 10 (inclusively)", - "random(-5.8, 10.4);", - "// Returns a random integer between -5 and 10 (inclusively)" - ] - }, - "just-entries": { - "packageName": "just-entries", - "dir": "object-entries", - "description": "Return object entries as an array of [key, value] pairs", - "examples": [ - "import entries from 'just-entries';", - "", - "// Object:", - "entries({c: 8, a: 4}); // [['c', 8], ['a', 4]]", - "entries({b: {bb: 4}, a: {aa: 2}}); // [['b', {bb: 4}], ['a', {aa: 2}]]", - "entries({}); // []", - "", - "// Array:", - "entries([{c: 8}, {a: 4}]); // [[0, {c: 8}], [1, {a: 4}]]", - "entries(['Γ€', 'mauvais', 'ouvrier', 'point', 'de', 'bon', 'outil'])", - "// [[0, 'Γ€'], [1, 'mauvais'] ... [6, 'outil']]", - "entries([]); // []" - ] - }, - "just-extend": { - "packageName": "just-extend", - "dir": "object-extend", - "description": "Extend an object", - "examples": [ - "import extend from 'just-extend';", - "", - "var obj = {a: 3, b: 5};", - "extend(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}", - "obj; // {a: 4, b: 5, c: 8}", - "", - "var obj = {a: 3, b: 5};", - "extend({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}", - "obj; // {a: 3, b: 5}", - "", - "var arr = [1, 2, 3];", - "var obj = {a: 3, b: 5};", - "extend(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}", - "arr.push(4);", - "obj; // {a: 3, b: 5, c: [1, 2, 3, 4]}", - "", - "var arr = [1, 2, 3];", - "var obj = {a: 3, b: 5};", - "extend(true, obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}", - "arr.push(4);", - "obj; // {a: 3, b: 5, c: [1, 2, 3]}", - "", - "extend({a: 4, b: 5}); // {a: 4, b: 5}", - "extend({a: 4, b: 5}, 3); {a: 4, b: 5}", - "extend({a: 4, b: 5}, true); {a: 4, b: 5}", - "extend('hello', {a: 4, b: 5}); // throws", - "extend(3, {a: 4, b: 5}); // throws" - ] - }, - "just-filter-object": { - "packageName": "just-filter-object", - "dir": "object-filter", - "description": "Filter an object", - "examples": [ - "import filter from 'just-filter';", - "", - "// returns a new object containing those original properties for which the predicate returns truthy", - "filter({a: 3, b: 5, c: 9}, (key, value) => value < 6); // {a: 3, b: 5}", - "filter({a1: 3, b1: 5, a2: 9}, (key, value) => key[0] == 'a'); // {a1: 3, a2: 9}", - "filter({a: 3, b: 5, c: null}, (key, value) => value); // {a: 3, b: 5}" - ] - }, - "just-flip-object": { - "packageName": "just-flip-object", - "dir": "object-flip", - "description": "Flip the keys and values", - "examples": [ - "import flip from 'just-flip-object';", - "", - "// flip the key and value", - "flip({a: 'x', b: 'y', c: 'z'}); // {x: 'a', y: 'b', z: 'c'}", - "flip({a: 1, b: 2, c: 3}); // {'1': 'a', '2': 'b', '3': 'c'}", - "flip({a: false, b: true}); // {false: 'a', true: 'b'}" - ] - }, - "just-has": { - "packageName": "just-has", - "dir": "object-has", - "description": "Return a boolen indicating the existence of a deep property, don't throw if parent is undefined", - "examples": [ - "import has from 'just-has';", - "", - "const obj = {a: {aa: {aaa: 2}}, b: 4};", - "", - "has(obj, 'a.aa.aaa'); // true", - "has(obj, ['a', 'aa', 'aaa']); // true", - "", - "has(obj, 'b.bb.bbb'); // false", - "has(obj, ['b', 'bb', 'bbb']); // false", - "", - "has(obj.a, 'aa.aaa'); // true", - "has(obj.a, ['aa', 'aaa']); // true", - "", - "has(obj.b, 'bb.bbb'); // false", - "has(obj.b, ['bb', 'bbb']); // false", - "", - "has(null, 'a'); // false", - "has(undefined, ['a']); // false", - "", - "const obj = {a: {}};", - "const sym = Symbol();", - "obj.a[sym] = 4;", - "has(obj.a, sym); // true" - ] - }, - "just-is-circular": { - "packageName": "just-is-circular", - "dir": "object-is-circular", - "description": [ - "Return true if object has a circular reference", - "NOTE: not supported in IE or microsoft edge" - ], - "examples": [ - "import isCircular from 'just-is-circular';", - "const a = {};", - "a.b = a;", - "isCircular(a); // true", - "", - "const a = {};", - "a.b = {", - " c: a", - "};", - "isCircular(a); // true", - "", - "const a = {};", - "a.b = {", - " c: 4", - "};", - "isCircular(a); // false", - "", - "const a = [];", - "a.push(a);", - "isCircular(a); // true", - "", - "isCircular({}); // false", - "isCircular('hi'); // false", - "isCircular(undefined); // false" - ] - }, - "just-is-empty": { - "packageName": "just-is-empty", - "dir": "object-is-empty", - "description": "Return true if object has no enumerable key values", - "examples": [ - "import isEmpty from 'just-is-empty';", - " isEmpty({a: 3, b: 5}) // false", - " isEmpty([1, 2]) // false", - " isEmpty(new Set([1, 2, 2])) // false", - " isEmpty((new Map()).set('a', 2)) // false", - " isEmpty({}) // true", - " isEmpty([]) // true", - " isEmpty(new Set()) // true", - " isEmpty(new Map()) // true", - " isEmpty('abc') // false", - " isEmpty('') // true", - " isEmpty(0) // true", - " isEmpty(1) // true", - " isEmpty(true) // true", - " isEmpty(Symbol('abc')); // true", - " isEmpty(//); // true", - " isEmpty(new String('abc')); // false", - " isEmpty(new String('')); // true", - " isEmpty(new Boolean(true)); // true", - " isEmpty(null) // true", - " isEmpty(undefined) // true" - ] - }, - "just-is-primitive": { - "packageName": "just-is-primitive", - "dir": "object-is-primitive", - "description": "Determine if a value is a primitive value", - "examples": [ - "import isPrimitive from 'just-is-primitive';", - "isPrimitive('hi') // true", - "isPrimitive(3) // true", - "isPrimitive(true) // true", - "isPrimitive(false) // true", - "isPrimitive(null) // true", - "isPrimitive(undefined) // true", - "isPrimitive(Symbol()) // true", - "isPrimitive({}) // false", - "isPrimitive([]) // false", - "isPrimitive(function() {}) // false", - "isPrimitive(new Date()) // false", - "isPrimitive(/a/) // false" - ] - }, - "just-map-object": { - "packageName": "just-map-object", - "dir": "object-map", - "description": "Map an object, passing key and value to predicates", - "examples": [ - "import map from 'just-map-object';", - "", - "// DEPRECATED: use just-map-values", - "map({a: 3, b: 5, c: 9}, (key, value) => value + 1); // {a: 4, b: 6, c: 10}", - "map({a: 3, b: 5, c: 9}, (key, value) => key); // {a: 'a', b: 'b', c: 'c'}", - "map({a: 3, b: 5, c: 9}, (key, value) => key + value); // {a: 'a3', b: 'b5', c: 'c9'}```" - ] - }, - "just-map-keys": { - "packageName": "just-map-keys", - "dir": "object-map-keys", - "description": "Map an object, predicate updates keys, receives (value, key, object)", - "examples": [ - "import map from 'just-map-keys';", - "", - "// predicate updates keys, receives (value, key, object)", - "map({a: 'cow', b: 'sheep', c: 'pig'}, (value) => value);", - " // {cow: 'cow', sheep: 'sheep', pig: 'pig'}", - "map([4, 5, 6], (value, key) => key + 1); // {1: 4, 2: 5, 3: 6}", - "map({a: 3, b: 5, c: 9}, (value, key) => key + value); // {a3: 3, b5: 5, c9: 9}", - "map({a: 3, b: 5, c: 9}, (value, key, obj) => obj.b + value + key);", - " // {'8a': 3, '10b': 5, '14c': 9}" - ] - }, - "just-map-values": { - "packageName": "just-map-values", - "dir": "object-map-values", - "description": "Map an object, predicate updates values, receives (value, key, object)", - "examples": [ - "import map from 'just-map-values';", - "", - "// predicate updates values, receives (value, key, obj)", - "map({a: 3, b: 5, c: 9}, (value) => value + 1); // {a: 4, b: 6, c: 10}", - "map({a: 3, b: 5, c: 9}, (value, key) => value + key); // {a: 3a, b: 5b, c: 9c}", - "map({a: 3, b: 5, c: 9}, (value, key, obj) => obj.b); // {a: 5, b: 5, c: 5}" - ] - }, - "just-merge": { - "packageName": "just-merge", - "dir": "object-merge", - "description": "Shallow assign. Like just-extend but without deep copy option.", - "examples": [ - "import merge from 'just-merge';", - "", - "let obj = {a: 3, b: 5};", - "merge(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}", - "obj; // {a: 4, b: 5, c: 8}", - "", - "let obj = {a: 3, b: 5};", - "merge({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}", - "obj; // {a: 3, b: 5}", - "", - "let arr = [1, 2, 3];", - "let obj = {a: 3, b: 5};", - "merge(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}", - "arr.push[4];", - "obj; // {a: 3, b: 5, c: [1, 2, 3, 4]}", - "", - "merge({a: 4, b: 5}); // {a: 4, b: 5}", - "merge(3, {a: 4, b: 5}); // throws", - "merge({a: 4, b: 5}, 3); // throws", - "merge({a: 4, b: 5}, {b: 4, c: 5}, 'c'); // throws" - ] - }, - "just-omit": { - "packageName": "just-omit", - "dir": "object-omit", - "description": "Copy an object but omit the specified keys", - "examples": [ - "import omit from 'just-omit';", - "", - "var obj = {a: 3, b: 5, c: 9};", - "omit(obj, ['a', 'c']); // {b: 5}", - "omit(obj, 'a', 'c'); // {b: 5}", - "omit(obj, ['a', 'b', 'd']); // {c: 9}", - "omit(obj, ['a', 'a']); // {b: 5, c: 9}" - ] - }, - "just-pick": { - "packageName": "just-pick", - "dir": "object-pick", - "description": "Copy an object but with only the specified keys", - "examples": [ - "import pick from 'just-pick';", - "", - "var obj = { a: 3, b: 5, c: 9 };", - "pick(obj, ['a', 'c']); // {a: 3, c: 9}", - "pick(obj, 'a', 'c'); // {a: 3, c: 9}", - "pick(obj, ['a', 'b', 'd']); // {a: 3, b: 5}", - "pick(obj, ['a', 'a']); // {a: 3}" - ] - }, - "just-reduce-object": { - "packageName": "just-reduce-object", - "dir": "object-reduce", - "description": "Reduce an object", - "examples": [ - "import reduce from 'just-reduce-object';", - "", - "// applies a function against an accumulator and each key-value pairs of the object", - "// to reduce it to a single value", - "reduce({a: 3, b: 5, c: 9}, (acc, key, value, index, keys) => {", - " acc[value] = key;", - " return acc;", - "}, {}); // {3: 'a', 5: 'b', 9: 'c'}", - "", - "reduce({a: 3, b: 5, c: 9}, (acc, key, value, index, keys) => {", - " acc += value;", - " return acc;", - "}); // 17" - ] - }, - "just-safe-get": { - "packageName": "just-safe-get", - "dir": "object-safe-get", - "description": "Get value at property, don't throw if parent is undefined", - "examples": [ - "import get from 'just-safe-get';", - "", - "const obj = {a: {aa: {aaa: 2}}, b: 4};", - "", - "get(obj, 'a.aa.aaa'); // 2", - "get(obj, ['a', 'aa', 'aaa']); // 2", - "", - "get(obj, 'b.bb.bbb'); // undefined", - "get(obj, ['b', 'bb', 'bbb']); // undefined", - "", - "get(obj.a, 'aa.aaa'); // 2", - "get(obj.a, ['aa', 'aaa']); // 2", - "", - "get(obj.b, 'bb.bbb'); // undefined", - "get(obj.b, ['bb', 'bbb']); // undefined", - "", - "get(obj.b, 'bb.bbb', 5); // 5", - "get(obj.b, ['bb', 'bbb'], true); // true", - "", - "get(null, 'a'); // undefined", - "get(undefined, ['a']); // undefined", - "", - "get(null, 'a', 42); // 42", - "get(undefined, ['a'], 42); // 42", - "", - "const obj = {a: {}};", - "const sym = Symbol();", - "obj.a[sym] = 4;", - "get(obj.a, sym); // 4" - ] - }, - "just-safe-set": { - "packageName": "just-safe-set", - "dir": "object-safe-set", - "description": "Set value at property, create intermediate properties if necessary", - "examples": [ - "import set from 'just-safe-set';", - "", - "const obj1 = {};", - "set(obj1, 'a.aa.aaa', 4); // true", - "obj1; // {a: {aa: {aaa: 4}}}", - "", - "const obj2 = {};", - "set(obj2, ['a', 'aa', 'aaa'], 4); // true", - "obj2; // {a: {aa: {aaa: 4}}}", - "", - "const obj3 = {a: {aa: {aaa: 2}}};", - "set(obj3, 'a.aa.aaa', 3); // true", - "obj3; // {a: {aa: {aaa: 3}}}", - "", - "const obj5 = {a: {}};", - "const sym = Symbol();", - "set(obj5.a, sym, 7); // true", - "obj5; // {a: {Symbol(): 7}}" - ] - }, - "just-typeof": { - "packageName": "just-typeof", - "dir": "object-typeof", - "description": "Type inferer", - "examples": [ - "import typeOf from 'just-typeof';", - "", - "typeOf({}); // 'object'", - "typeOf([]); // 'array'", - "typeOf(function() {}); // 'function'", - "typeOf(/a/); // 'regexp'", - "typeOf(new Date()); // 'date'", - "typeOf(null); // 'null'", - "typeOf(undefined); // 'undefined'", - "typeOf('a'); // 'string'", - "typeOf(1); // 'number'", - "typeOf(true); // 'boolean'" - ] - }, - "just-values": { - "packageName": "just-values", - "dir": "object-values", - "description": "Return property values as an array", - "examples": [ - "const values = require('just-values');", - "", - "values({a: 4, c: 8}); // [4, 8]", - "values({a: {aa: 2}, b: {bb: 4}}); // [{aa: 2}, {bb: 4}]", - "values({}); // []", - "values([1, 2, 3]); // [1, 2, 3]", - "values(function(a, b) {return a + b;}); // []", - "values(new String('hello')); // ['h', 'e', 'l', 'l', 'o']", - "values(1); // throws exception", - "values(true); // throws exception", - "values(undefined); // throws exception", - "values(null); // throws exception" - ] - }, - "just-camel-case": { - "packageName": "just-camel-case", - "dir": "string-camel-case", - "description": "Convert a string to camel case", - "examples": [ - " import camelCase from 'just-camel-case';", - "", - " camelCase('the quick brown fox'); // 'theQuickBrownFox'", - " camelCase('the_quick_brown_fox'); // 'theQuickBrownFox'", - " camelCase('the-quick-brown-fox'); // 'theQuickBrownFox'", - " camelCase('theQuickBrownFox'); // 'theQuickBrownFox'", - " camelCase('thequickbrownfox'); // 'thequickbrownfox'", - " camelCase('the - quick * brown# fox'); // 'theQuickBrownFox'", - " camelCase('behold theQuickBrownFox'); // 'beholdTheQuickBrownFox'", - " camelCase('Behold theQuickBrownFox'); // 'beholdTheQuickBrownFox'", - " // all caps words are camel-cased", - " camelCase('The quick brown FOX'), 'theQuickBrownFox');", - " // all caps substrings >= 4 chars are camel-cased", - " camelCase('theQUickBrownFox'); // 'theQUickBrownFox'", - " camelCase('theQUIckBrownFox'); // 'theQUIckBrownFox'", - " camelCase('theQUICKBrownFox'); // 'theQuickBrownFox'" - ] - }, - "just-capitalize": { - "packageName": "just-capitalize", - "dir": "string-capitalize", - "description": "Capitalize the first character of a string", - "examples": [ - " import capitalize from 'just-capitalize';", - "", - "/*", - " capitalize('capitals'); // 'Capitals'", - " capitalize('Capitals'); // 'Capitals'", - " capitalize('many words'); // 'Many words'", - " capitalize('!exclaim'); // '!exclaim'", - "*/" - ] - }, - "just-kebab-case": { - "packageName": "just-kebab-case", - "dir": "string-kebab-case", - "description": "Convert a string to kebab case", - "examples": [ - " import kebabCase from 'just-kebab-case';", - "", - " kebabCase('the quick brown fox'); // 'the-quick-brown-fox'", - " kebabCase('the-quick-brown-fox'); // 'the-quick-brown-fox'", - " kebabCase('the_quick_brown_fox'); // 'the-quick-brown-fox'", - " kebabCase('theQuickBrownFox'); // 'the-quick-brown-fox'", - " kebabCase('theQuickBrown Fox'); // 'the-quick-brown-fox'", - " kebabCase('thequickbrownfox'); // 'thequickbrownfox'", - " kebabCase('the - quick * brown# fox'); // 'the-quick-brown-fox'", - " kebabCase('theQUICKBrownFox'); // 'the-q-u-i-c-k-brown-fox'" - ] - }, - "just-left-pad": { - "packageName": "just-left-pad", - "dir": "string-left-pad", - "description": "Add characters to the left of a string such that its total length is n", - "examples": [ - "import leftPad from 'just-left-pad';", - "", - "leftPad('hello', 9); // ' hello'", - "leftPad('hello', 3); // 'hello'", - "leftPad('hello', 9, '.'); // '....hello'", - "leftPad('hello', 9, '..'); // '....hello'", - "leftPad('hello', 10, 'ab'); // 'bababhello'", - "leftPad('hello', 9, '\\uD83D\\uDC04'); // 'πŸ„πŸ„πŸ„πŸ„hello'", - "leftPad('hello', 10, '\\uD83D\\uDC11\\uD83D\\uDC04'), // 'πŸ„πŸ‘πŸ„πŸ‘πŸ„hello'", - "leftPad('hello', 7, 'πŸ„'), // 'πŸ„πŸ„hello'", - "leftPad(null, 7); // throws", - "leftPad([], 4, '*'); // throws", - "leftPad('hello', 4, true); // throws", - "leftPad('hello', -4, true); // throws ", - "leftPad('hello', 2.3, true); // throws " - ] - }, - "just-pascal-case": { - "packageName": "just-pascal-case", - "dir": "string-pascal-case", - "description": "Convert a string to pascal case", - "examples": [ - " import pascalCase from 'just-pascal-case';", - "", - " pascalCase('the quick brown fox'); // 'TheQuickBrownFox'", - " pascalCase('the_quick_brown_fox'); // 'TheQuickBrownFox'", - " pascalCase('the-quick-brown-fox'); // 'TheQuickBrownFox'", - " pascalCase('theQuickBrownFox'); // 'TheQuickBrownFox'", - " pascalCase('thequickbrownfox'); // 'Thequickbrownfox'", - " pascalCase('the - quick * brown# fox'); // 'TheQuickBrownFox'", - " pascalCase('theQUICKBrownFox'); // 'TheQUICKBrownFox'" - ] - }, - "just-prune": { - "packageName": "just-prune", - "dir": "string-prune", - "description": "Prune a string with whole words and a custom suffix", - "examples": [ - " prune('when shall we three meet again', 7); // 'when...'", - " prune('when shall we three meet again', 7, ' (more)'; // 'when (more)'", - " prune('when shall we', 15,); // 'when shall we'", - " prune('when shall we', 15, ' (etc)'); // 'when shall we'", - " prune('when shall we', 7, ' (more)'); // ' (more)'" - ] - }, - "just-replace-all": { - "packageName": "just-replace-all", - "dir": "string-replace-all", - "description": "Replace all occurrences of a string within a string with another string", - "examples": [ - " import replaceAll from 'just-replace-all';", - "", - "/*", - " replaceAll('hello, world', 'l', 'q'); // 'heqqo, worqd'", - " replaceAll('hello, world', 'l', 'qq'); // 'heqqqqo, worqqd'", - " replaceAll('hello, world', 'll', 'q'); // 'heqo, world'", - " replaceAll('hello, world', '', 'q'); // 'hello, world'", - " replaceAll('hello, world', 'l', ''); // 'heo, word'", - " replaceAll('hello, world', null, 'q'); // 'hello, world'", - " replaceAll('hello, world', 'l'); // throw", - " replaceAll('hello, world'); // throw", - " replaceAll(); // throw", - " replaceAll(null, 'l', 'q'); // throw", - " replaceAll('hello, world', null, 'q'); // throw", - " replaceAll('hello, world', 'l', null); // throw", - "*/" - ] - }, - "just-right-pad": { - "packageName": "just-right-pad", - "dir": "string-right-pad", - "description": "Add characters to the right of a string such that its total length is n", - "examples": [ - "import rightPad from 'just-right-pad';", - "", - "rightPad('hello', 9); // 'hello '", - "rightPad('hello', 3); // 'hello'", - "rightPad('hello', 9, '.'); // 'hello....'", - "rightPad('hello', 9, '..'); // 'hello....'", - "rightPad('hello', 10, 'ab'); // 'helloababa'", - "rightPad('hello', 9, '\\uD83D\\uDC04'); // 'helloπŸ„πŸ„πŸ„πŸ„'", - "rightPad('hello', 10, '\\uD83D\\uDC11\\uD83D\\uDC04'), // 'helloπŸ‘πŸ„πŸ‘πŸ„πŸ‘'", - "rightPad('hello', 7, 'πŸ„'), // 'helloπŸ„πŸ„'", - "rightPad(null, 7); // throws", - "rightPad([], 4, '*'); // throws", - "rightPad('hello', 4, true); // throws", - "rightPad('hello', -4, true); // throws ", - "rightPad('hello', 2.3, true); // throws " - ] - }, - "just-snake-case": { - "packageName": "just-snake-case", - "dir": "string-snake-case", - "description": "Convert a string to snake case", - "examples": [ - " import snakeCase from 'just-snake-case';", - "", - " snakeCase('the quick brown fox'); // 'the_quick_brown_fox'", - " snakeCase('the-quick-brown-fox'); // 'the_quick_brown_fox'", - " snakeCase('the_quick_brown_fox'); // 'the_quick_brown_fox'", - " snakeCase('theQuickBrownFox'); // 'the_quick_brown_fox'", - " snakeCase('thequickbrownfox'); // 'thequickbrownfox'", - " snakeCase('the - quick * brown# fox'); // 'the_quick_brown_fox'", - " snakeCase('theQUICKBrownFox'); // 'the_q_u_i_c_k_brown_fox'" - ] - }, - "just-squash": { - "packageName": "just-squash", - "dir": "string-squash", - "description": "Remove all spaces from a string, optionally remove escape sequences too", - "examples": [ - " squash('the cat sat on the mat'); // 'thecatsatonthemat'", - " squash(' the cat sat on the mat '); // 'thecatsatonthemat'", - " squash('\\tthe cat\\n sat \\fon \\vthe \\rmat '); // '\\tthecat\\nsat\\fon\\vthe\\rmat'", - " squash('\\tthe cat\\n sat \\fon \\vthe \\rmat ', true); // 'thecatsatonthemat'", - " squash(`the cat", - "sat on the mat`, true); // thecatsatonthemat" - ] - }, - "just-template": { - "packageName": "just-template", - "dir": "string-template", - "description": "Interpolate a string with variables", - "examples": [ - "import template from 'just-template';", - "", - "var data = {", - " a: {", - " aa: {", - " aaa: 'apple',", - " bbb: 'pear'", - " },", - " bb: 'orange'", - " },", - " b: 'plum'", - "};", - "template('2 {{a.aa.aaa}}s, a {{a.aa.bbb}}, 3 {{a.bb}}s and a {{b}}. Yes 1 {{a.aa.bbb}}.', data);", - "// '2 apples, a pear, 3 oranges and a plum. Yes 1 pear.'" - ] - }, - "just-truncate": { - "packageName": "just-truncate", - "dir": "string-truncate", - "description": "Truncate a string with a custom suffix", - "examples": [ - " truncate('when shall we three meet again', 9); // 'when s...'", - " truncate('when shall we three meet again', 10, ' (etc)'); // 'when (etc)'", - " truncate('when shall we', 15,); // 'when shall we'", - " truncate('when shall we', 15, '(more)'); // 'when shall we'", - " truncate('when shall we', 10, ' (etc etc etc)'); // ' (etc etc etc)'" - ] - }, - "just-deep-map-values": { - "packageName": "just-deep-map-values", - "dir": "object-deep-map-values", - "description": "Returns an object with values at all depths mapped according to the provided function", - "examples": [ - "import deepMapValues from 'just-deep-map-values';", - "", - "const squareFn = (number) => number * number;", - "deepMapValues({ a: 1, b: { c: 2, d: { e: 3 } } }, squareFn); // => { a: 1, b: { c: 4, d: { e: 9 } } }" - ] - } -} diff --git a/package.json b/package.json index 9855db389..fbb322bf3 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "tape": "^4.0.0", "template-mate": "^1.1.0", "test": "^0.6.0", - "typescript": "^4.2.3" + "typescript": "^4.2.3", + "yaml": "^2.3.2" }, "scripts": { "build": "lerna run build --stream $@", diff --git a/packages.yml b/packages.yml new file mode 100644 index 000000000..c1978cace --- /dev/null +++ b/packages.yml @@ -0,0 +1,1551 @@ +just-cartesian-product: + packageName: just-cartesian-product + dir: array-cartesian-product + description: Takes an input of an array of arrays and returns their Cartesian product + examples: | + import cartesianProduct from 'just-cartesian-product'; + + cartesianProduct([[1, 2], ['a', 'b']]); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] + cartesianProduct([[1, 2], ['a', 'b', 'c']]); // [[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c']] + cartesianProduct([]); // [] + cartesianProduct(); // throws +just-compact: + packageName: just-compact + dir: array-compact + description: Returns a copy of an array with falsey values removed + examples: | + import compact from 'just-compact'; + + compact([1, null, 2, undefined, null, NaN, 3, 4, false, 5]); // [1, 2, 3, 4, 5] + compact([1, 2, [], 4, {}]); // [1, 2, [], 4, {}] + compact([]); // [] + compact({}); // throws +just-flatten-it: + packageName: just-flatten-it + dir: array-flatten + description: Return a flattened array + examples: | + import flatten from 'just-flatten-it'; + + flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]]); + // [1, 2, 3, 4, 5, 6, 7, 8, 9] + + flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]], 1); + // [1, [2, 3], [[4, 5], 6, 7, [8, 9]]] +just-group-by: + packageName: just-group-by + dir: array-group-by + description: Return a grouped object from array + examples: | + import groupBy from 'just-group-by'; + + groupBy([6.1, 4.2, 6.3], Math.floor); // { '4': [4.2], '6': [6.1, 6.3] } + groupBy([1,2,3,4,5,6,7,8], function(i) { return i % 2}); // { '0': [2, 4, 6, 8], '1': [1, 3, 5, 7] } +just-index: + packageName: just-index + dir: array-index + description: Return an object from an array, keyed by the value at the given id + examples: | + import index from 'just-index'; + + index([{id: 'first', val: 1}, {id: 'second', val: 2}], 'id'); + // {first: {id: 'first', val: 1}, second: {id: 'second', val: 2}} + + index([{id: 'first', val: 1}, null], 'id'); // {first: {id: 'first', val: 1}} + index([], 'id'); // {} + index([], null); // undefined + index({}, 'id'); // undefined +just-insert: + packageName: just-insert + dir: array-insert + description: Inserts a sub-array into an array starting at the given index. Returns a copy + examples: | + import insert from 'just-insert'; + + insert([1, 2, 5, 6], ['a', 'c', 'e'], 2); // [1, 2, 'a', 'c', 'e', 5, 6] + insert([1, 2, 5, 6], 'a', 2); // [1, 2, 'a', 5, 6] + insert([1, 2, 5, 6], ['a', 'c', 'e'], 0); // ['a', 'c', 'e', 1, 2, 5, 6] + insert([1, 2, 5, 6], ['a', 'c', 'e']); // ['a', 'c', 'e', 1, 2, 5, 6] +just-intersect: + packageName: just-intersect + dir: array-intersect + description: Return the intersect of two arrays + examples: | + import intersect from 'just-intersect'; + + intersect([1, 2, 5, 6], [2, 3, 5, 6]); // [2, 5, 6] + intersect([1, 2, 2, 4, 5], [3, 2, 2, 5, 7]); // [2, 5] +just-last: + packageName: just-last + dir: array-last + description: Return the last member of an array + examples: | + import last from 'just-last'; + + last([1, 2, 3, 4, 5]); // 5 + last([{a: 1}, {b: 1}, {c: 1}]); // {c: 1} + last([true, false, [true, false]]); // [true, false] + last(); // undefined + last([]); // undefined + last(null); // undefined + last(undefined); // undefined +just-mean: + packageName: just-mean + dir: array-mean + description: The mean (average) value in an array + examples: | + import mean from 'just-mean'; + + mean([1, 2, 3, 2, 4, 1]); // 2.1666666667 + mean(3, 2, 1); // 2 + mean([4]); // 4 + mean(['3', 2]); // throws + mean(); // throws +just-median: + packageName: just-median + dir: array-median + description: Return the median value of an array of numbers + examples: | + import median from 'just-median'; + + median([1, 2, 3, 4, 5]); // 3 + median([3, -1, 2]); // 2 + median([9, 14, 14, 200, 15]); // 14 + median(1, 2, 4, 3); // 2.5 + median(['3', 2, 1]); // throws + median(); // throws +just-mode: + packageName: just-mode + dir: array-mode + description: Return the most frequently occuring number(s) + examples: | + import mode from 'just-mode'; + + mode([1, 2, 3, 2]); // 2 + mode(4, 4, 1, 4); // 4 + mode(100, 100, 101, 101); // [100, 101] + mode(4, 3, 2, 1); // [1, 2, 3, 4] + mode(['1', 2, 2, 1, 2]); // throws + mode(null); // throws +just-order-by: + packageName: just-order-by + dir: array-order-by + description: Produces a new array, sorted in given order + examples: | + import orderBy from 'just-order-by'; + + orderBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35] + + orderBy( + [ + { user: 'fabio', details: { city: 'Milan', age: 34 } }, + { user: 'max', details: { city: 'Munich', age: 29 } }, + { user: 'zacarias', details: { city: 'Sao Paulo', age: 44 } }, + { user: 'robert', details: { city: 'Manchester', age: 28 } }, + { user: 'max', details: { city: 'Zurich', age: 38 } }, + ], + [ + { + property(v) { + return v.details.age; + }, + }, + ] + ); + + /* + [ + {user: 'robert', age: 28}, + {user: 'max', age: 29}, + {user: 'fabio', age: 34}, + {user: 'klaus', age: 38}, + {user: 'zacarias', age: 44}, + ] + */ + + orderBy( + [ + {user: 'fabio', age: 34}, + {user: 'max', age: 29}, + {user: 'zacarias', age: 44}, + {user: 'robert', age: 28}, + {user: 'klaus', age: 38}, + ], + [ + { + property: 'user', + }, + ] + ); + + /* + [ + {user: 'fabio', age: 34}, + {user: 'klaus', age: 38}, + {user: 'max', age: 29}, + {user: 'robert', age: 28}, + {user: 'zacarias', age: 44}, + ] + */ + + orderBy( + [ + { user: 'fabio', age: 34 }, + { user: 'max', age: 29 }, + { user: 'zacarias', age: 44 }, + { user: 'moris', age: 28 }, + { user: 'max', age: 38 }, + ], + [ + { + property: 'user', + order: 'desc', + }, + { + property(v) { + return v.age; + }, + }, + ] + ); + + /* + [ + { + user: 'zacarias', + age: 44 + }, + { + user: 'moris', + age: 28 + }, + { + user: 'max', + age: 29 + }, + { + user: 'max', + age: 38 + }, + { + user: 'fabio', + age: 34 + } + ] + */ +just-partition: + packageName: just-partition + dir: array-partition + description: Elements satisfying predicate added to first array, remainder added to second + examples: | + import partition from 'just-partition'; + + partition([1, 5, 2, 4, 3], n => n > 3); // [[5, 4],[1, 2, 3]] + partition(['a', 2, 3, '3'], x => typeof x == 'string'); // [['a', '3'],[2, 3]] + partition([1, 2, 3, 4], x => typeof x == 'number'); // [[1, 2, 3, 4],[]] + partition([1, 2, 3, 4], x => typeof x == 'string'); // [[], [1, 2, 3, 4]] + partition([], n => n > 3); // [[], []] + partition({a: 1, b: 2}, n => n > 1); // throws + partition(null, n => n > 1); // throws + partition(undefined, n => n > 1); // throws +just-percentile: + packageName: just-percentile + dir: array-percentile + description: Return the value at the given percentile (using linear interpolation) + examples: | + import percentile from 'just-percentile'; + + percentile([1, 2, 3], 0); // 1 + percentile([1, 2, 3], 0.5); // 2 + percentile([1, 2, 3], 1); // 3 + + // See https://en.wikipedia.org/wiki/Percentile (linear interpolation method) + percentile([15, 20, 35, 40, 50], 0.05); // 15 + percentile([15, 20, 35, 40, 50], 0.3); // 20 + percentile([15, 20, 35, 40, 50], 0.4); // 27.5 + percentile([15, 20, 35, 40, 50], 0.95); // 50 + + percentile(1, 2, 3, 50); // throws + percentile(['1', 2, 3], 50); // throws + percentile([], 50); // throws +just-permutations: + packageName: just-permutations + dir: array-permutations + description: Returns all permutations of the length N of the elements of the given array + examples: | + import permutations from 'just-permutations'; + + permutations([1, 2, 3]); // [[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]] + permutations([]); // [] + permutations(); // throws +just-pipe: + packageName: just-pipe + dir: function-pipe + description: Pass a value through a pipeline of functions + examples: | + import pipe from 'just-pipe'; + + pipe(3, a => a+1, b => b*2) // 8 + pipe('John Smith', a => a.split(' '), b => b.reverse(), c => c[0]) // 'Smith' +just-random: + packageName: just-random + dir: array-random + description: Return a randomly selected element in an array + examples: | + import random from 'just-random'; + + random([1, 2, 3]); // one of [1, 2, 3], at random +just-range: + packageName: just-range + dir: array-range + description: Generate a range array for numbers + examples: | + import range from 'just-range'; + + range(1, 5); // [1, 2, 3, 4] + range(5); // [0, 1, 2, 3, 4] + range(-5); // [0, -1, -2, -3, -4] + range(0, 20, 5); // [0, 5, 10, 15] +just-remove: + packageName: just-remove + dir: array-remove + description: Removes one array from another + examples: | + import remove from 'just-remove'; + + remove([1, 2, 3, 4, 5, 6], [1, 3, 6]); // [2, 4, 5] +just-shuffle: + packageName: just-shuffle + dir: array-shuffle + description: Return the elements of an array in random order + examples: | + import shuffle from 'just-shuffle'; + + shuffle([1, 2, 3]); + // array with original elements randomly sorted + + shuffle([1, 2, 3], {shuffleAll: true}); + // array with original elements randomly sorted and all in new postions + + shuffle([]); // [] + shuffle([1]); // [1] + shuffle(); // throws + shuffle(undefined); // throws + shuffle(null); // throws + shuffle({}); // throws +just-skewness: + packageName: just-skewness + dir: array-skewness + description: Return the skewness of an array or numeric argument list using Pearson's second skewness coefficient + examples: | + import skewness from 'just-skewness'; + + // Using Pearson's second skewness coefficient + skewness(3, 2, 1); // 0 + skewness([1, 2, 3, 2, 4, 1]); // 0.4276994613841504 + skewness(1, 2, 3, 4, 5, -6); // -0.762000762001143 + skewness([1, 2, 3, 4, 9]); // 0.7705935588815224 + skewness([4]); // throws + skewness(["3", 2]); // throws + skewness(NaN, NaN); // throws + skewness(); // throws +just-sort-by: + packageName: just-sort-by + dir: array-sort-by + description: Produces a new array, sorted in ascending order + examples: | + import sortBy from 'just-sort-by'; + + sortBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35] + + sortBy([ + {user: 'fabio', details: {city: "Milan", age: 34}}, + {user: 'max', details: {city: "Munich", age: 29}}, + {user: 'zacarias', details: {city: "Sao Paulo", age: 44}}, + {user: 'robert', details: {city: "Manchester", age: 28}}, + {user: 'klaus', details: {city: "Zurich", age: 38}}, + ], function(o) { + return o.details.age; + }); + + /* + [ + {user: 'robert', age: 28}, + {user: 'max', age: 29}, + {user: 'fabio', age: 34}, + {user: 'klaus', age: 38}, + {user: 'zacarias', age: 44}, + ] + */ + + sortBy([ + {user: 'fabio', age: 34}, + {user: 'max', age: 29}, + {user: 'zacarias', age: 44}, + {user: 'robert', age: 28}, + {user: 'klaus', age: 38}, + ], 'user'); + /* + [ + {user: 'fabio', age: 34}, + {user: 'klaus', age: 38}, + {user: 'max', age: 29}, + {user: 'robert', age: 28}, + {user: 'zacarias', age: 44}, + ] + */ +just-split: + packageName: just-split + dir: array-split + description: Splits array into groups of n items each + examples: | + import split from 'just-split'; + + split([]); // [] + split([1, 2, 3, 4, 5]); // [[1, 2, 3, 4, 5]] + split([1, 2, 3, 4, 5, 6, 7, 8, 9], 3); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + split([1, 2, 3, 4, 5, 6, 7, 8, 9], '3'); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]] + split(['a', 'b', 'c', 'd', 'e'], 2); // [['a', 'b'], ['c', 'd'], ['e']] + split([1, 2, 3, 4, 5, 6, 7, 8], 3); // [[1, 2, 3], [4, 5, 6], [7, 8]] +just-split-at: + packageName: just-split-at + dir: array-split-at + description: Splits an array into two at a given position + examples: | + import splitAt from 'just-split-at'; + + splitAt([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4, 5]] + splitAt([{a: 1}, {b: 1}, {c: 1}], -1); // [[{a: 1}, {b: 1}], [{c: 1}]] + splitAt([], 2); // [[], []] + splitAt(null, 1); // throws + splitAt(undefined, 1); // throws +just-standard-deviation: + packageName: just-standard-deviation + dir: array-standard-deviation + description: Return the standard deviation of an array or numeric argument list + examples: | + import standardDeviation from 'just-standard-deviation'; + + standardDeviation([1, 2, 3, 2, 4, 1]); // 1.16904519 + standardDeviation(3, 2, 1); // 1 + standardDeviation([100, 100, 100.1, 100]); // 0.05 + standardDeviation(1, 2, 3, 4, 5, -6); // 3.9370039 + standardDeviation([4]); // throws + standardDeviation(["3", 2]); // throws + standardDeviation(NaN, NaN); // throws + standardDeviation(); // throws +just-tail: + packageName: just-tail + dir: array-tail + description: Return all but the first element of an array + examples: | + import tail from 'just-tail'; + + tail([1, 2, 3, 4, 5]); // [2, 3, 4, 5] + tail([{a: 1}, {b: 1}, {c: 1}]); // [{b: 1}, {c: 1}] + tail([true, false, [true, false]]); // [false, [true, false]] + tail([]); // [] + tail(); // undefined + tail(null); // undefined + tail(undefined); // undefined +just-union: + packageName: just-union + dir: array-union + description: Returns the union of two arrays + examples: | + import union from 'just-union'; + + union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 5, 6, 3, 4] +just-unique: + packageName: just-unique + dir: array-unique + description: Dedupes an array + examples: | + import unique from 'just-unique'; + + unique([1, 2, 3, 2, 3, 4, 3, 2, 1, 3]); // [1, 2, 3, 4] + + var a = {a: 3}; + var b = {b: 4}; + var c = {c: 5}; + unique([a, a, b, c, b]); // [a, b, c] + + unique([1, '1', 2, '2', 3, 2]); // [1, '1', 2, '2', 3] + + // declaring sorted array for performance + unique([1, 1, '1', 2, 2, 5, '5', '5'], true); // [1, '1', 2, 5, '6'] + + // declaring strings array for performance + unique(['a', 'c', 'b', 'c', 'a'], false, true); // ['a', 'b', 'c'] +just-variance: + packageName: just-variance + dir: array-variance + description: Return the standard deviation of an array or numeric argument list + examples: | + import variance from 'just-variance'; + + variance([1, 2, 3, 2, 4, 1]); // 1.3666666667 + variance(3, 2, 1); // 1 + variance([100, 100, 100.1, 100]); // 0.0025 + variance(1, 2, 3, 4, 5, -6); // 15.5 + variance([4]); // throws + variance(['3', 2]); // throws + variance(NaN, NaN); // throws + variance(); // throws +just-zip-it: + packageName: just-zip-it + dir: array-zip + description: + Returns an array of grouped elements, taking n-th element from every + given array + examples: | + import zip from 'just-zip-it'; + + zip([1, 2, 3]); // [[1], [2], [3]] + zip([1, 2, 3], ['a', 'b', 'c']); // [[1, 'a'], [2, 'b'], [3, 'c']] + zip([1, 2], ['a', 'b'], [true, false]); //[[1, 'a', true], [2, 'b', false]] + + zip(undefined, {}, false, 1, 'foo'); // [] + zip([1, 2], ['a', 'b'], undefined, {}, false, 1, 'foo'); // [[1, 'a'], [2, 'b']] + + zip([1, 2, 3], ['a', 'b'], [true]); // [[1, 'a', true], [2, 'b', undefined], [3, undefined, undefined]] +just-clone: + packageName: just-clone + dir: collection-clone + description: Deep copies objects, arrays, maps and sets + examples: | + // Deep copies objects and arrays, doesn't clone functions + + import clone from 'just-clone'; + + var arr = [1, 2, 3]; + var subObj = { aa: 1 }; + var obj = { a: 3, b: 5, c: arr, d: subObj }; + var objClone = clone(obj); + arr.push(4); + objClone.d.bb = 2; + obj; // {a: 3, b: 5, c: [1, 2, 3, 4], d: {aa: 1}} + objClone; // {a: 3, b: 5, c: [1, 2, 3], d: {aa: 1, bb: 2}} +just-compare: + packageName: just-compare + dir: collection-compare + description: Compare two collections + examples: | + import compare from 'just-compare'; + + // primitives: value1 === value2 + // functions: value1.toString == value2.toString + // arrays: if length, sequence and values of properties are identical + // objects: if length, names and values of properties are identical + compare([1, [2, 3]], [1, [2, 3]]); // true + compare([1, [2, 3], 4], [1, [2, 3]]); // false + compare({a: 2, b: 3}, {a: 2, b: 3}); // true + compare({a: 2, b: 3}, {b: 3, a: 2}); // true + compare({a: 2, b: 3, c: 4}, {a: 2, b: 3}); // false + compare({a: 2, b: 3}, {a: 2, b: 3, c: 4}); // false + compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}]]); // false + compare([1, [2, {a: 4}], 4], [1, [2, {a: 4}], 4]); // true + compare(NaN, NaN); // true +just-diff: + packageName: just-diff + dir: collection-diff + description: | + Return an object representing the difference between two other objects + Pass converter to format as http://jsonpatch.com + examples: | + import {diff} from 'just-diff'; + + const obj1 = {a: 4, b: 5}; + const obj2 = {a: 3, b: 5}; + const obj3 = {a: 4, c: 5}; + + diff(obj1, obj2); + [ + { "op": "replace", "path": ['a'], "value": 3 }, + ] + + diff(obj2, obj3); + [ + { "op": "remove", "path": ['b'] }, + { "op": "replace", "path": ['a'], "value": 4 }, + { "op": "add", "path": ['c'], "value": 5 } + ] + + // using converter to generate jsPatch standard paths + import {diff, jsonPatchPathConverter} from 'just-diff' + diff(obj1, obj2, jsonPatchPathConverter); + [ + { "op": "replace", "path": '/a', "value": 3 } + ] + + diff(obj2, obj3, jsonPatchPathConverter); + [ + { "op": "remove", "path": '/b' }, + { "op": "replace", "path": '/a', "value": 4 }, + { "op": "add", "path": '/c', "value": 5 } + ] + + // arrays + const obj4 = {a: 4, b: [1, 2, 3]}; + const obj5 = {a: 3, b: [1, 2, 4]}; + const obj6 = {a: 3, b: [1, 2, 4, 5]}; + + diff(obj4, obj5); + [ + { "op": "replace", "path": ['a'], "value": 3 }, + { "op": "replace", "path": ['b', 2], "value": 4 } + ] + + diff(obj5, obj6); + [ + { "op": "add", "path": ['b', 3], "value": 5 } + ] + + // nested paths + const obj7 = {a: 4, b: {c: 3}}; + const obj8 = {a: 4, b: {c: 4}}; + const obj9 = {a: 5, b: {d: 4}}; + + diff(obj7, obj8); + [ + { "op": "replace", "path": ['b', 'c'], "value": 4 } + ] + + diff(obj8, obj9); + [ + { "op": "replace", "path": ['a'], "value": 5 }, + { "op": "remove", "path": ['b', 'c']}, + { "op": "add", "path": ['b', 'd'], "value": 4 } + ] +just-diff-apply: + packageName: just-diff-apply + dir: collection-diff-apply + description: + Apply a diff object to an object. Pass converter to apply a http://jsonpatch.com + standard patch + examples: | + import {diffApply} from 'just-diff-apply'; + + const obj1 = {a: 3, b: 5}; + diffApply(obj1, + [ + { "op": "remove", "path": ['b'] }, + { "op": "replace", "path": ['a'], "value": 4 }, + { "op": "add", "path": ['c'], "value": 5 } + ] + ); + obj1; // {a: 4, c: 5} + + const obj2 = {a: 3, b: 5}; + diffApply(obj2, + [ + { "op": "move", "from": ['a'], "path": ['c']}, + ] + ); + obj2; // {b: 5, c: 3} + + // using converter to apply jsPatch standard paths + // see http://jsonpatch.com + import {diffApply, jsonPatchPathConverter} from 'just-diff-apply' + const obj3 = {a: 3, b: 5}; + diffApply(obj3, [ + { "op": "remove", "path": '/b' }, + { "op": "replace", "path": '/a', "value": 4 }, + { "op": "add", "path": '/c', "value": 5 } + ], jsonPatchPathConverter); + obj3; // {a: 4, c: 5} + + // arrays (array key can be string or numeric) + const obj4 = {a: 4, b: [1, 2, 3]}; + diffApply(obj4, [ + { "op": "replace", "path": ['a'], "value": 3 }, + { "op": "replace", "path": ['b', 2], "value": 4 }, + { "op": "add", "path": ['b', 3], "value": 9 } + ]); + obj4; // {a: 3, b: [1, 2, 4, 9]} + + // nested paths + const obj5 = {a: 4, b: {c: 3}}; + diffApply(obj5, [ + { "op": "replace", "path": ['a'], "value": 5 }, + { "op": "remove", "path": ['b', 'c']}, + { "op": "add", "path": ['b', 'd'], "value": 4 } + ]); + obj5; // {a: 5, b: {d: 4}} +just-flush: + packageName: just-flush + dir: collection-flush + description: Returns a copy of an array or object with null/undefined members removed + examples: | + import flush from 'just-flush'; + + flush([1, undefined, 2, null, 3, NaN, 0]); // [1, 2, 3, NaN, 0] + flush([true, null, false, true, [null], undefined]); // [true, false, true, [null]] + flush({a: 2, b: null, c: 4, d: undefined}); // {a: 2, c: 4} + flush('something'); // undefined + flush(); // undefined +just-pluck-it: + packageName: just-pluck-it + dir: collection-pluck + description: Pluck a property from each member of a collection + examples: | + import pluck from 'just-pluck-it'; + + pluck([{a:1, b:2}, {a:4, b:3}, {a:2, b:5}], 'a'); // [1, 4, 2] + pluck({x: {a:1, b:2}, y: {a:4, b:3}, z: {a:2, b:5}}, 'a'); // {x: 1, y: 4, z: 2} +just-compose: + packageName: just-compose + dir: function-compose + description: Return a function composed of 2 or more functions + examples: | + import compose from 'just-compose'; + + const sqRootBiggest = compose(Math.max, Math.sqrt, Math.trunc); + sqRootBiggest(10, 5); // 3 + sqRootBiggest(7, 0, 16); // 4 +just-curry-it: + packageName: just-curry-it + dir: function-curry + description: Return a curried function + examples: | + import curry from 'just-curry-it'; + + function add(a, b, c) { + return a + b + c; + } + curry(add)(1)(2)(3); // 6 + curry(add)(1)(2)(2); // 5 + curry(add)(2)(4, 3); // 9 + + function add(...args) { + return args.reduce((sum, n) => sum + n, 0) + } + var curryAdd4 = curry(add, 4) + curryAdd4(1)(2, 3)(4); // 10 + + function converter(ratio, input) { + return (input*ratio).toFixed(1); + } + const curriedConverter = curry(converter) + const milesToKm = curriedConverter(1.62); + milesToKm(35); // 56.7 + milesToKm(10); // 16.2 +just-debounce-it: + packageName: just-debounce-it + dir: function-debounce + description: Return a debounced function + examples: | + import debounce from 'just-debounce-it'; + + const fn1 = debounce(() => console.log("Hello"), 500); + fn1(); + fn1(); + fn1(); + // 500ms later logs 'hello' once + + const fn2 = debounce(() => console.log("Hello"), 500, true); + fn2(); // logs hello immediately + fn2(); + fn2(); + // 500ms later logs 'hello' once + + const fn3 = debounce(() => console.log("Hello"), 500); + fn3(); + fn3(); + fn3(); + fn3.cancel(); + // function cancelled before 'hello' is logged + + const fn4 = debounce(() => console.log("Hello"), 500); + fn4(); + fn4(); + fn4(); + fn4.flush(); + // immediately invoke the debounced function +just-demethodize: + packageName: just-demethodize + dir: function-demethodize + description: Turn a method into a standalone function; the first arg becomes `this` + examples: | + import demethodize from 'just-demethodize'; + + const trimFn = demethodize(''.trim); + ['hello ', ' goodbye', 'hello again'].map(trimFn); // ['hello', 'goodbye', 'hello again'] +just-flip: + packageName: just-flip + dir: function-flip + description: Flip first two arguments of a function + examples: | + import flip from 'just-flip'; + + flip(console.log)(1, 2, 3) // 2, 1, 3 + + import map from 'just-map-object'; + import partial from 'just-partial'; + + const numbers = {x: 5, y: 10}; + const flippedMap = flip(map); + const double = partial(flippedMap, (undefined, number) => number * 2); + double(numbers) // {x: 10, y: 20]; +just-memoize: + packageName: just-memoize + dir: function-memoize + description: An implementation of the memoize technique + examples: | + import memoize from 'just-memoize'; + + const sumByOne = memoize(function(value) { + return value + 1; + }); + + sumByOne(10); // Returns value returned by the function + sumByOne(10); // Cache hit! + + sumByOne(20); // Returns value returned by the function + sumByOne(20); // Cache hit! + + // Custom cache key (key defaults to JSON stringified arguments) + var sum = memoize(function(a, b) { + return a + b; + }, function(a, b) { + return `${a}-${b}`; + }); + + sum(10, 10); // Returns value returned by the function + sum(10, 20); // Returns value returned by the function + sum(10, 20); // Cache hit! +just-memoize-last: + packageName: just-memoize-last + dir: function-memoize-last + description: A memoize implementation that only caches the most recent evaluation + examples: | + import memoizeLast from 'just-memoize-last'; + import compare from 'just-compare'; + + const maxValue = memoizeLast(function(arr) { + return Math.max(...arr) + }, function(a, b) { + return compare(a, b) + }); + + maxValue([1,2,3]); // 3 + maxValue([1,2,3]); // cache hit! + maxValue([1,3,4]); // 4 + maxValue([1,2,3]); // 3 +just-once: + packageName: just-once + dir: function-once + description: Create a function that can only be invoked once + examples: | + import once from 'just-once'; + + const fn = once(() => console.log('hello')); + + fn(); + // logs 'hello' + fn(); + // does nothing +just-partial-it: + packageName: just-partial-it + dir: function-partial + description: Return a partial function + examples: | + import partial from 'just-partial-it'; + + const cubedRoot = partial(Math.pow, _, 1/3); + cubedRoot(64); // 4 + + const getRoot = partial(Math.pow, 64); + getRoot(1/2); // 8 +just-throttle: + packageName: just-throttle + dir: function-throttle + description: Return a throttled function + examples: | + import throttle from 'just-throttle'; + + // no matter how many times the function is called, only invoke once within the given interval + // options: + // `leading`: invoke before interval + // `trailing`: invoke afer interval + + const fn1 = throttle(() => console.log('hello'), 500, {leading: true}); + setInterval(fn1, 400); + // logs 'hello' immediately and then every 500ms + + const fn2 = throttle(() => console.log('hello'), 500, {trailing: true}); + setInterval(fn2, 400); + // logs 'hello' after 500ms and then every 500ms + + const fn3 = throttle(() => console.log('hello'), 500, {leading: true, trailing: true}); + // forces trailing to false + + const fn4 = throttle(() => console.log('hello'), 500, { leading: false }); + fn4(); + fn4(); + fn4(); + fn4.cancel(); + // function cancelled before 'hello' is logged + + const fn5 = throttle(() => console.log("Hello"), 500); + fn5(); + fn5(); + fn5(); + fn5.flush(); + // immediately invoke the throttled function +just-clamp: + packageName: just-clamp + dir: number-clamp + description: Restrict a number within a range + examples: | + import clamp from 'just-clamp'; + + var n = 5; + clamp(1, n, 12); // 5 + clamp(3, n, 1); // 3 + clamp(8, n, 9); // 8 + clamp(0, n, 0); // 0 + + var n = -5; + clamp(1, n, 12); // 1 + clamp(-7, n, -8); // -7 + + clamp(NaN, n, 8); // NaN + clamp(3, n, NaN); // NaN + clamp(3, NaN, 8); // NaN + + clamp(undefined, n, 8); // throws + clamp(3, n, 'h'); // throws + clamp(3, false, 8); // throws +just-in-range: + packageName: just-in-range + dir: number-in-range + description: Check if number is within a given range + examples: | + import inRange from 'just-number-in-range'; + + inRange(2, 1, 10); // true + inRange(15, 20); // true + inRange(20, 21, 30); // false + inRange(30, 21, 30); // false + inRange(); // throws + inRange(100); // throws + inRange("js"); // throws +just-is-prime: + packageName: just-is-prime + dir: number-is-prime + description: Check if number is prime + examples: | + import isPrime from 'just-is-prime'; + + isPrime(1); // false + isPrime(2); // true + isPrime(17); // true + isPrime(10); // false + isPrime(); // throws + isPrime(null); // throws + isPrime("js"); // throws + isPrime({}); // throws + isPrime(function() {}); // throws + isPrime([]); // throws +just-modulo: + packageName: just-modulo + dir: number-modulo + description: Modulo of a number and a divisor + examples: | + import modulo from 'just-modulo'; + + modulo(7, 5); // 2 + modulo(17, 23); // 17 + modulo(16.2, 3.8); // 1 + modulo(5.8, 3.4); //2.4 + modulo(4, 0); // 4 + modulo(-7, 5); // 3 + modulo(-2, 15); // 13 + modulo(-5.8, 3.4); // 1 + modulo(12, -1); // NaN + modulo(-3, -8); // NaN + modulo(12, 'apple'); // NaN + modulo('bee', 9); // NaN + modulo(null, undefined); // NaN +just-random-integer: + packageName: just-random-integer + dir: number-random-integer + description: Produces a random integer within a given range + examples: | + import random from 'just-random-integer'; + + random(); // Returns either 0 or 1 + random(5); // Returns a random integer between 0 and 5 (inclusively) + random(3, 10); // Returns a random integer between 3 and 10 (inclusively) + random(-5.8, 10.4); // Returns a random integer between -5 and 10 (inclusively) +just-entries: + packageName: just-entries + dir: object-entries + description: Return object entries as an array of [key, value] pairs + examples: | + import entries from 'just-entries'; + + // Object: + entries({c: 8, a: 4}); // [['c', 8], ['a', 4]] + entries({b: {bb: 4}, a: {aa: 2}}); // [['b', {bb: 4}], ['a', {aa: 2}]] + entries({}); // [] + + // Array: + entries([{c: 8}, {a: 4}]); // [[0, {c: 8}], [1, {a: 4}]] + entries(['Γ€', 'mauvais', 'ouvrier', 'point', 'de', 'bon', 'outil']) + // [[0, 'Γ€'], [1, 'mauvais'] ... [6, 'outil']] + entries([]); // [] +just-extend: + packageName: just-extend + dir: object-extend + description: Extend an object + examples: | + import extend from 'just-extend'; + + var obj = {a: 3, b: 5}; + extend(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8} + obj; // {a: 4, b: 5, c: 8} + + var obj = {a: 3, b: 5}; + extend({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8} + obj; // {a: 3, b: 5} + + var arr = [1, 2, 3]; + var obj = {a: 3, b: 5}; + extend(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]} + arr.push(4); + obj; // {a: 3, b: 5, c: [1, 2, 3, 4]} + + var arr = [1, 2, 3]; + var obj = {a: 3, b: 5}; + extend(true, obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]} + arr.push(4); + obj; // {a: 3, b: 5, c: [1, 2, 3]} + + extend({a: 4, b: 5}); // {a: 4, b: 5} + extend({a: 4, b: 5}, 3); {a: 4, b: 5} + extend({a: 4, b: 5}, true); {a: 4, b: 5} + extend('hello', {a: 4, b: 5}); // throws + extend(3, {a: 4, b: 5}); // throws +just-filter-object: + packageName: just-filter-object + dir: object-filter + description: Filter an object + examples: | + import filter from 'just-filter'; + + // returns a new object containing those original properties for which the predicate returns truthy + filter({a: 3, b: 5, c: 9}, (key, value) => value < 6); // {a: 3, b: 5} + filter({a1: 3, b1: 5, a2: 9}, (key, value) => key[0] == 'a'); // {a1: 3, a2: 9} + filter({a: 3, b: 5, c: null}, (key, value) => value); // {a: 3, b: 5} +just-flip-object: + packageName: just-flip-object + dir: object-flip + description: Flip the keys and values + examples: | + import flip from 'just-flip-object'; + + // flip the key and value + flip({a: 'x', b: 'y', c: 'z'}); // {x: 'a', y: 'b', z: 'c'} + flip({a: 1, b: 2, c: 3}); // {'1': 'a', '2': 'b', '3': 'c'} + flip({a: false, b: true}); // {false: 'a', true: 'b'} +just-has: + packageName: just-has + dir: object-has + description: Return a boolen indicating the existence of a deep property, don't throw if parent is undefined + examples: | + import has from 'just-has'; + + const obj = {a: {aa: {aaa: 2}}, b: 4}; + + has(obj, 'a.aa.aaa'); // true + has(obj, ['a', 'aa', 'aaa']); // true + + has(obj, 'b.bb.bbb'); // false + has(obj, ['b', 'bb', 'bbb']); // false + + has(obj.a, 'aa.aaa'); // true + has(obj.a, ['aa', 'aaa']); // true + + has(obj.b, 'bb.bbb'); // false + has(obj.b, ['bb', 'bbb']); // false + + has(null, 'a'); // false + has(undefined, ['a']); // false + + const obj = {a: {}}; + const sym = Symbol(); + obj.a[sym] = 4; + has(obj.a, sym); // true +just-is-circular: + packageName: just-is-circular + dir: object-is-circular + description: | + Return true if object has a circular reference + NOTE: not supported in IE or microsoft edge + examples: | + import isCircular from 'just-is-circular'; + + const a = {}; + a.b = a; + isCircular(a); // true + + const a = {}; + a.b = { + c: a + }; + isCircular(a); // true + + const a = {}; + a.b = { + c: 4 + }; + isCircular(a); // false + + const a = []; + a.push(a); + isCircular(a); // true + + isCircular({}); // false + isCircular('hi'); // false + isCircular(undefined); // false +just-is-empty: + packageName: just-is-empty + dir: object-is-empty + description: Return true if object has no enumerable key values + examples: | + import isEmpty from 'just-is-empty'; + + isEmpty({a: 3, b: 5}) // false + isEmpty([1, 2]) // false + isEmpty(new Set([1, 2, 2])) // false + isEmpty((new Map()).set('a', 2)) // false + isEmpty({}) // true + isEmpty([]) // true + isEmpty(new Set()) // true + isEmpty(new Map()) // true + isEmpty('abc') // false + isEmpty('') // true + isEmpty(0) // true + isEmpty(1) // true + isEmpty(true) // true + isEmpty(Symbol('abc')); // true + isEmpty(//); // true + isEmpty(new String('abc')); // false + isEmpty(new String('')); // true + isEmpty(new Boolean(true)); // true + isEmpty(null) // true + isEmpty(undefined) // true +just-is-primitive: + packageName: just-is-primitive + dir: object-is-primitive + description: Determine if a value is a primitive value + examples: | + import isPrimitive from 'just-is-primitive'; + + isPrimitive('hi') // true + isPrimitive(3) // true + isPrimitive(true) // true + isPrimitive(false) // true + isPrimitive(null) // true + isPrimitive(undefined) // true + isPrimitive(Symbol()) // true + isPrimitive({}) // false + isPrimitive([]) // false + isPrimitive(function() {}) // false + isPrimitive(new Date()) // false + isPrimitive(/a/) // false +just-map-object: + packageName: just-map-object + dir: object-map + description: Map an object, passing key and value to predicates + examples: | + import map from 'just-map-object'; + + // DEPRECATED: use just-map-values + map({a: 3, b: 5, c: 9}, (key, value) => value + 1); // {a: 4, b: 6, c: 10} + map({a: 3, b: 5, c: 9}, (key, value) => key); // {a: 'a', b: 'b', c: 'c'} + map({a: 3, b: 5, c: 9}, (key, value) => key + value); // {a: 'a3', b: 'b5', c: 'c9'} +just-map-keys: + packageName: just-map-keys + dir: object-map-keys + description: Map an object, predicate updates keys, receives (value, key, object) + examples: | + import map from 'just-map-keys'; + + // predicate updates keys, receives (value, key, object) + map({a: 'cow', b: 'sheep', c: 'pig'}, (value) => value); + // {cow: 'cow', sheep: 'sheep', pig: 'pig'} + map([4, 5, 6], (value, key) => key + 1); // {1: 4, 2: 5, 3: 6} + map({a: 3, b: 5, c: 9}, (value, key) => key + value); // {a3: 3, b5: 5, c9: 9} + map({a: 3, b: 5, c: 9}, (value, key, obj) => obj.b + value + key); + // {'8a': 3, '10b': 5, '14c': 9} +just-map-values: + packageName: just-map-values + dir: object-map-values + description: Map an object, predicate updates values, receives (value, key, object) + examples: | + import map from 'just-map-values'; + + // predicate updates values, receives (value, key, obj) + map({a: 3, b: 5, c: 9}, (value) => value + 1); // {a: 4, b: 6, c: 10} + map({a: 3, b: 5, c: 9}, (value, key) => value + key); // {a: 3a, b: 5b, c: 9c} + map({a: 3, b: 5, c: 9}, (value, key, obj) => obj.b); // {a: 5, b: 5, c: 5} +just-merge: + packageName: just-merge + dir: object-merge + description: Shallow assign. Like just-extend but without deep copy option. + examples: | + import merge from 'just-merge'; + + let obj = {a: 3, b: 5}; + merge(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8} + obj; // {a: 4, b: 5, c: 8} + + let obj = {a: 3, b: 5}; + merge({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8} + obj; // {a: 3, b: 5} + + let arr = [1, 2, 3]; + let obj = {a: 3, b: 5}; + merge(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]} + arr.push[4]; + obj; // {a: 3, b: 5, c: [1, 2, 3, 4]} + + merge({a: 4, b: 5}); // {a: 4, b: 5} + merge(3, {a: 4, b: 5}); // throws + merge({a: 4, b: 5}, 3); // throws + merge({a: 4, b: 5}, {b: 4, c: 5}, 'c'); // throws +just-omit: + packageName: just-omit + dir: object-omit + description: Copy an object but omit the specified keys + examples: | + import omit from 'just-omit'; + + var obj = {a: 3, b: 5, c: 9}; + omit(obj, ['a', 'c']); // {b: 5} + omit(obj, 'a', 'c'); // {b: 5} + omit(obj, ['a', 'b', 'd']); // {c: 9} + omit(obj, ['a', 'a']); // {b: 5, c: 9} +just-pick: + packageName: just-pick + dir: object-pick + description: Copy an object but with only the specified keys + examples: | + import pick from 'just-pick'; + + var obj = { a: 3, b: 5, c: 9 }; + pick(obj, ['a', 'c']); // {a: 3, c: 9} + pick(obj, 'a', 'c'); // {a: 3, c: 9} + pick(obj, ['a', 'b', 'd']); // {a: 3, b: 5} + pick(obj, ['a', 'a']); // {a: 3} +just-reduce-object: + packageName: just-reduce-object + dir: object-reduce + description: Reduce an object + examples: | + import reduce from 'just-reduce-object'; + + // applies a function against an accumulator and each key-value pairs of the + object + // to reduce it to a single value + reduce({a: 3, b: 5, c: 9}, (acc, key, value, index, keys) => { + acc[value] = key; + return acc; + }, {}); // {3: 'a', 5: 'b', 9: 'c'} + + reduce({a: 3, b: 5, c: 9}, (acc, key, value, index, keys) => { + acc += value; + return acc; + }); // 17 +just-safe-get: + packageName: just-safe-get + dir: object-safe-get + description: Get value at property, don't throw if parent is undefined + examples: | + import get from 'just-safe-get'; + + const obj = {a: {aa: {aaa: 2}}, b: 4}; + + get(obj, 'a.aa.aaa'); // 2 + get(obj, ['a', 'aa', 'aaa']); // 2 + + get(obj, 'b.bb.bbb'); // undefined + get(obj, ['b', 'bb', 'bbb']); // undefined + + get(obj.a, 'aa.aaa'); // 2 + get(obj.a, ['aa', 'aaa']); // 2 + + get(obj.b, 'bb.bbb'); // undefined + get(obj.b, ['bb', 'bbb']); // undefined + + get(obj.b, 'bb.bbb', 5); // 5 + get(obj.b, ['bb', 'bbb'], true); // true + + get(null, 'a'); // undefined + get(undefined, ['a']); // undefined + + get(null, 'a', 42); // 42 + get(undefined, ['a'], 42); // 42 + + const obj = {a: {}}; + const sym = Symbol(); + obj.a[sym] = 4; + get(obj.a, sym); // 4 +just-safe-set: + packageName: just-safe-set + dir: object-safe-set + description: Set value at property, create intermediate properties if necessary + examples: | + import set from 'just-safe-set'; + + const obj1 = {}; + set(obj1, 'a.aa.aaa', 4); // true + obj1; // {a: {aa: {aaa: 4}}} + + const obj2 = {}; + set(obj2, ['a', 'aa', 'aaa'], 4); // true + obj2; // {a: {aa: {aaa: 4}}} + + const obj3 = {a: {aa: {aaa: 2}}}; + set(obj3, 'a.aa.aaa', 3); // true + obj3; // {a: {aa: {aaa: 3}}} + + const obj5 = {a: {}}; + const sym = Symbol(); + set(obj5.a, sym, 7); // true + obj5; // {a: {Symbol(): 7}} +just-typeof: + packageName: just-typeof + dir: object-typeof + description: Type inferer + examples: | + import typeOf from 'just-typeof'; + + typeOf({}); // 'object' + typeOf([]); // 'array' + typeOf(function() {}); // 'function' + typeOf(/a/); // 'regexp' + typeOf(new Date()); // 'date' + typeOf(null); // 'null' + typeOf(undefined); // 'undefined' + typeOf('a'); // 'string' + typeOf(1); // 'number' + typeOf(true); // 'boolean' +just-values: + packageName: just-values + dir: object-values + description: Return property values as an array + examples: | + import values from 'just-values'; + + values({a: 4, c: 8}); // [4, 8] + values({a: {aa: 2}, b: {bb: 4}}); // [{aa: 2}, {bb: 4}] + values({}); // [] + values([1, 2, 3]); // [1, 2, 3] + values(function(a, b) {return a + b;}); // [] + values(new String('hello')); // ['h', 'e', 'l', 'l', 'o'] + values(1); // throws exception + values(true); // throws exception + values(undefined); // throws exception + values(null); // throws exception +just-camel-case: + packageName: just-camel-case + dir: string-camel-case + description: Convert a string to camel case + examples: | + import camelCase from 'just-camel-case'; + + camelCase('the quick brown fox'); // 'theQuickBrownFox' + camelCase('the_quick_brown_fox'); // 'theQuickBrownFox' + camelCase('the-quick-brown-fox'); // 'theQuickBrownFox' + camelCase('theQuickBrownFox'); // 'theQuickBrownFox' + camelCase('thequickbrownfox'); // 'thequickbrownfox' + camelCase('the quick * brown# fox'); // 'theQuickBrownFox' + camelCase('behold theQuickBrownFox'); // 'beholdTheQuickBrownFox' + camelCase('Behold theQuickBrownFox'); // 'beholdTheQuickBrownFox' + // all caps words are camel-cased + camelCase('The quick brown FOX'), 'theQuickBrownFox'); + // all caps substrings >= 4 chars are camel-cased + camelCase('theQUickBrownFox'); // 'theQUickBrownFox' + camelCase('theQUIckBrownFox'); // 'theQUIckBrownFox' + camelCase('theQUICKBrownFox'); // 'theQuickBrownFox' +just-capitalize: + packageName: just-capitalize + dir: string-capitalize + description: Capitalize the first character of a string + examples: | + import capitalize from 'just-capitalize'; + + capitalize('capitals'); // 'Capitals' + capitalize('Capitals'); // 'Capitals' + capitalize('many words'); // 'Many words' + capitalize('!exclaim'); // '!exclaim' +just-kebab-case: + packageName: just-kebab-case + dir: string-kebab-case + description: Convert a string to kebab case + examples: | + import kebabCase from 'just-kebab-case'; + + kebabCase('the quick brown fox'); // 'the-quick-brown-fox' + kebabCase('the-quick-brown-fox'); // 'the-quick-brown-fox' + kebabCase('the_quick_brown_fox'); // 'the-quick-brown-fox' + kebabCase('theQuickBrownFox'); // 'the-quick-brown-fox' + kebabCase('theQuickBrown Fox'); // 'the-quick-brown-fox' + kebabCase('thequickbrownfox'); // 'thequickbrownfox' + kebabCase('the quick * brown# fox'); // 'the-quick-brown-fox' + kebabCase('theQUICKBrownFox'); // 'the-q-u-i-c-k-brown-fox' +just-left-pad: + packageName: just-left-pad + dir: string-left-pad + description: Add characters to the left of a string such that its total length is n + examples: | + import leftPad from 'just-left-pad'; + + leftPad('hello', 9); // ' hello' + leftPad('hello', 3); // 'hello' + leftPad('hello', 9, '.'); // '....hello' + leftPad('hello', 9, '..'); // '....hello' + leftPad('hello', 10, 'ab'); // 'bababhello' + leftPad('hello', 9, '\uD83D\uDC04'); // '\U0001F404\U0001F404\U0001F404\U0001F404hello' + leftPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // '\U0001F404\U0001F411\U0001F404\U0001F411\U0001F404hello' + leftPad('hello', 7, '\U0001F404'), // '\U0001F404\U0001F404hello' + leftPad(null, 7); // throws + leftPad([], 4, '*'); // throws + leftPad('hello', 4, true); // throws + leftPad('hello', -4, true); // throws + leftPad('hello', 2.3, true); // throws +just-pascal-case: + packageName: just-pascal-case + dir: string-pascal-case + description: Convert a string to pascal case + examples: | + import pascalCase from 'just-pascal-case'; + + pascalCase('the quick brown fox'); // 'TheQuickBrownFox' + pascalCase('the_quick_brown_fox'); // 'TheQuickBrownFox' + pascalCase('the-quick-brown-fox'); // 'TheQuickBrownFox' + pascalCase('theQuickBrownFox'); // 'TheQuickBrownFox' + pascalCase('thequickbrownfox'); // 'Thequickbrownfox' + pascalCase('the - quick * brown# fox'); // 'TheQuickBrownFox' + pascalCase('theQUICKBrownFox'); // 'TheQUICKBrownFox' +just-prune: + packageName: just-prune + dir: string-prune + description: Prune a string with whole words and a custom suffix + examples: | + import prune from 'just-prune'; + + prune('when shall we three meet again', 7); // 'when...' + prune('when shall we three meet again', 7, ' (more)'); // 'when (more)' + prune('when shall we', 15); // 'when shall we' + prune('when shall we', 15, ' (etc)'); // 'when shall we' + prune('when shall we', 7, ' (more)'); // ' (more)' +just-replace-all: + packageName: just-replace-all + dir: string-replace-all + description: Replace all occurrences of a string within a string with another string + examples: | + import replaceAll from 'just-replace-all'; + + replaceAll('hello, world', 'l', 'q'); // 'heqqo, worqd' + replaceAll('hello, world', 'l', 'qq'); // 'heqqqqo, worqqd' + replaceAll('hello, world', 'll', 'q'); // 'heqo, world' + replaceAll('hello, world', '', 'q'); // 'hello, world' + replaceAll('hello, world', 'l', ''); // 'heo, word' + replaceAll('hello, world', null, 'q'); // 'hello, world' + replaceAll('hello, world', 'l'); // throw + replaceAll('hello, world'); // throw + replaceAll(); // throw + replaceAll(null, 'l', 'q'); // throw + replaceAll('hello, world', null, 'q'); // throw + replaceAll('hello, world', 'l', null); // throw +just-right-pad: + packageName: just-right-pad + dir: string-right-pad + description: Add characters to the right of a string such that its total length is n + examples: | + import rightPad from 'just-right-pad'; + + rightPad('hello', 9); // 'hello ' + rightPad('hello', 3); // 'hello' + rightPad('hello', 9, '.'); // 'hello....' + rightPad('hello', 9, '..'); // 'hello....' + rightPad('hello', 10, 'ab'); // 'helloababa' + rightPad('hello', 9, '\uD83D\uDC04'); // 'hello\U0001F404\U0001F404\U0001F404\U0001F404' + rightPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // 'hello\U0001F411\U0001F404\U0001F411\U0001F404\U0001F411' + rightPad('hello', 7, '\U0001F404'), // 'hello\U0001F404\U0001F404' + rightPad(null, 7); // throws + rightPad([], 4, '*'); // throws + rightPad('hello', 4, true); // throws + rightPad('hello', -4, true); // throws + rightPad('hello', 2.3, true); // throws +just-snake-case: + packageName: just-snake-case + dir: string-snake-case + description: Convert a string to snake case + examples: | + import snakeCase from 'just-snake-case'; + + snakeCase('the quick brown fox'); // 'the_quick_brown_fox' + snakeCase('the-quick-brown-fox'); // 'the_quick_brown_fox' + snakeCase('the_quick_brown_fox'); // 'the_quick_brown_fox' + snakeCase('theQuickBrownFox'); // 'the_quick_brown_fox' + snakeCase('thequickbrownfox'); // 'thequickbrownfox' + snakeCase('the - quick * brown# fox'); // 'the_quick_brown_fox' + snakeCase('theQUICKBrownFox'); // 'the_q_u_i_c_k_brown_fox' +just-squash: + packageName: just-squash + dir: string-squash + description: Remove all spaces from a string, optionally remove escape sequences too + examples: | + import squash from 'just-squash'; + + squash('the cat sat on the mat'); // 'thecatsatonthemat' + squash(' the cat sat on the mat '); // 'thecatsatonthemat' + squash('\tthe cat\n sat \fon \vthe \rmat '); // '\tthecat\nsat\fon\vthe\rmat' + squash('\tthe cat\n sat \fon \vthe \rmat ', true); // 'thecatsatonthemat' + squash(`the cat sat on the mat`, true); // thecatsatonthemat +just-template: + packageName: just-template + dir: string-template + description: Interpolate a string with variables + examples: | + import template from 'just-template'; + + var data = { + a: { + aa: { + aaa: 'apple', + bbb: 'pear' + }, + bb: 'orange' + }, + b: 'plum' + }; + template('2 {{a.aa.aaa}}s, a {{a.aa.bbb}}, 3 {{a.bb}}s and a {{b}}. Yes 1 {{a.aa.bbb}}.', data); + // '2 apples, a pear, 3 oranges and a plum. Yes 1 pear.' +just-truncate: + packageName: just-truncate + dir: string-truncate + description: Truncate a string with a custom suffix + examples: | + import truncate from 'just-truncate'; + + truncate('when shall we three meet again', 9); // 'when s...' + truncate('when shall we three meet again', 10, ' (etc)'); // 'when (etc)' + truncate('when shall we', 15); // 'when shall we' + truncate('when shall we', 15, '(more)'); // 'when shall we' + truncate('when shall we', 10, ' (etc etc etc)'); // ' (etc etc etc)' +just-deep-map-values: + packageName: just-deep-map-values + dir: object-deep-map-values + description: Returns an object with values at all depths mapped according to the provided function + examples: | + import deepMapValues from 'just-deep-map-values'; + + const squareFn = (number) => number * number; + deepMapValues({ a: 1, b: { c: 2, d: { e: 3 } } }, squareFn); // => { a: 1, b: { c: 4, d: { e: 9 } } } diff --git a/scripts/generate-readmes.js b/scripts/generate-readmes.js index c0090fda4..89a0e2bed 100644 --- a/scripts/generate-readmes.js +++ b/scripts/generate-readmes.js @@ -1,13 +1,19 @@ const {readFileSync} = require('fs'); const {renderFile} = require('template-mate'); +const YAML = require('yaml'); // eslint-disable-next-line max-len const DO_NOT_EDIT_PREFIX = '\n\n\n'; -const packageVariables = JSON.parse( - readFileSync('./md-variables.json', 'utf8') +const packageVariables = YAML.parse( + readFileSync('./packages.yml', 'utf8') ); +Object.entries(packageVariables).forEach(([name, data]) => { + packageVariables[name].examples = data.examples.trim(); + packageVariables[name].description = data.description.trim(); +}); + const templates = { local: 'templates/local.template.md', global: 'templates/global.template.md', diff --git a/yarn.lock b/yarn.lock index 44f251258..534006445 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5851,6 +5851,11 @@ yallist@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz" +yaml@^2.3.2: + version "2.3.2" + resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.2.tgz#f522db4313c671a0ca963a75670f1c12ea909144" + integrity sha512-N/lyzTPaJasoDmfV7YTrYCI0G/3ivm/9wdG0aHuheKowWQwGTsK0Eoiw6utmzAnI6pkJa0DUVygvp3spqqEKXg== + yargs-parser@^15.0.1: version "15.0.1" resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-15.0.1.tgz" From 5e946f88f16df1304793abd3c0dd60c96ac68c68 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 27 Sep 2023 16:18:08 -0400 Subject: [PATCH 2/4] fix: match original json data --- packages.yml | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages.yml b/packages.yml index c1978cace..fea0a0b07 100644 --- a/packages.yml +++ b/packages.yml @@ -1248,8 +1248,7 @@ just-reduce-object: examples: | import reduce from 'just-reduce-object'; - // applies a function against an accumulator and each key-value pairs of the - object + // applies a function against an accumulator and each key-value pairs of the object // to reduce it to a single value reduce({a: 3, b: 5, c: 9}, (acc, key, value, index, keys) => { acc[value] = key; @@ -1363,7 +1362,7 @@ just-camel-case: camelCase('the-quick-brown-fox'); // 'theQuickBrownFox' camelCase('theQuickBrownFox'); // 'theQuickBrownFox' camelCase('thequickbrownfox'); // 'thequickbrownfox' - camelCase('the quick * brown# fox'); // 'theQuickBrownFox' + camelCase('the - quick * brown# fox'); // 'theQuickBrownFox' camelCase('behold theQuickBrownFox'); // 'beholdTheQuickBrownFox' camelCase('Behold theQuickBrownFox'); // 'beholdTheQuickBrownFox' // all caps words are camel-cased @@ -1396,7 +1395,7 @@ just-kebab-case: kebabCase('theQuickBrownFox'); // 'the-quick-brown-fox' kebabCase('theQuickBrown Fox'); // 'the-quick-brown-fox' kebabCase('thequickbrownfox'); // 'thequickbrownfox' - kebabCase('the quick * brown# fox'); // 'the-quick-brown-fox' + kebabCase('the - quick * brown# fox'); // 'the-quick-brown-fox' kebabCase('theQUICKBrownFox'); // 'the-q-u-i-c-k-brown-fox' just-left-pad: packageName: just-left-pad @@ -1410,9 +1409,9 @@ just-left-pad: leftPad('hello', 9, '.'); // '....hello' leftPad('hello', 9, '..'); // '....hello' leftPad('hello', 10, 'ab'); // 'bababhello' - leftPad('hello', 9, '\uD83D\uDC04'); // '\U0001F404\U0001F404\U0001F404\U0001F404hello' - leftPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // '\U0001F404\U0001F411\U0001F404\U0001F411\U0001F404hello' - leftPad('hello', 7, '\U0001F404'), // '\U0001F404\U0001F404hello' + leftPad('hello', 9, '\uD83D\uDC04'); // 'πŸ„πŸ„πŸ„πŸ„hello' + leftPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // 'πŸ„πŸ‘πŸ„πŸ‘πŸ„hello' + leftPad('hello', 7, '\uD83D\uDC04'), // 'πŸ„πŸ„hello' leftPad(null, 7); // throws leftPad([], 4, '*'); // throws leftPad('hello', 4, true); // throws @@ -1475,9 +1474,9 @@ just-right-pad: rightPad('hello', 9, '.'); // 'hello....' rightPad('hello', 9, '..'); // 'hello....' rightPad('hello', 10, 'ab'); // 'helloababa' - rightPad('hello', 9, '\uD83D\uDC04'); // 'hello\U0001F404\U0001F404\U0001F404\U0001F404' - rightPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // 'hello\U0001F411\U0001F404\U0001F411\U0001F404\U0001F411' - rightPad('hello', 7, '\U0001F404'), // 'hello\U0001F404\U0001F404' + rightPad('hello', 9, '\uD83D\uDC04'); // 'helloπŸ„πŸ„πŸ„πŸ„' + rightPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // 'helloπŸ‘πŸ„πŸ‘πŸ„πŸ‘' + rightPad('hello', 7, '\uD83D\uDC04'), // 'helloπŸ„πŸ„' rightPad(null, 7); // throws rightPad([], 4, '*'); // throws rightPad('hello', 4, true); // throws From 7d1554b110e60619438d2b3015c30855c25e05cd Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 27 Sep 2023 16:42:10 -0400 Subject: [PATCH 3/4] fix: semicolons, remove commas --- packages.yml | 70 ++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/packages.yml b/packages.yml index fea0a0b07..33ba7bb87 100644 --- a/packages.yml +++ b/packages.yml @@ -285,8 +285,8 @@ just-pipe: examples: | import pipe from 'just-pipe'; - pipe(3, a => a+1, b => b*2) // 8 - pipe('John Smith', a => a.split(' '), b => b.reverse(), c => c[0]) // 'Smith' + pipe(3, a => a+1, b => b*2); // 8 + pipe('John Smith', a => a.split(' '), b => b.reverse(), c => c[0]); // 'Smith' just-random: packageName: just-random dir: array-random @@ -778,7 +778,7 @@ just-flip: examples: | import flip from 'just-flip'; - flip(console.log)(1, 2, 3) // 2, 1, 3 + flip(console.log)(1, 2, 3); // 2, 1, 3 import map from 'just-map-object'; import partial from 'just-partial'; @@ -786,7 +786,7 @@ just-flip: const numbers = {x: 5, y: 10}; const flippedMap = flip(map); const double = partial(flippedMap, (undefined, number) => number * 2); - double(numbers) // {x: 10, y: 20]; + double(numbers); // {x: 10, y: 20]; just-memoize: packageName: just-memoize dir: function-memoize @@ -1117,26 +1117,26 @@ just-is-empty: examples: | import isEmpty from 'just-is-empty'; - isEmpty({a: 3, b: 5}) // false - isEmpty([1, 2]) // false - isEmpty(new Set([1, 2, 2])) // false - isEmpty((new Map()).set('a', 2)) // false - isEmpty({}) // true - isEmpty([]) // true - isEmpty(new Set()) // true - isEmpty(new Map()) // true - isEmpty('abc') // false - isEmpty('') // true - isEmpty(0) // true - isEmpty(1) // true - isEmpty(true) // true + isEmpty({a: 3, b: 5}); // false + isEmpty([1, 2]); // false + isEmpty(new Set([1, 2, 2])); // false + isEmpty((new Map()).set('a', 2)); // false + isEmpty({}); // true + isEmpty([]); // true + isEmpty(new Set()); // true + isEmpty(new Map()); // true + isEmpty('abc'); // false + isEmpty(''); // true + isEmpty(0); // true + isEmpty(1); // true + isEmpty(true); // true isEmpty(Symbol('abc')); // true isEmpty(//); // true isEmpty(new String('abc')); // false isEmpty(new String('')); // true isEmpty(new Boolean(true)); // true - isEmpty(null) // true - isEmpty(undefined) // true + isEmpty(null); // true + isEmpty(undefined); // true just-is-primitive: packageName: just-is-primitive dir: object-is-primitive @@ -1144,18 +1144,18 @@ just-is-primitive: examples: | import isPrimitive from 'just-is-primitive'; - isPrimitive('hi') // true - isPrimitive(3) // true - isPrimitive(true) // true - isPrimitive(false) // true - isPrimitive(null) // true - isPrimitive(undefined) // true - isPrimitive(Symbol()) // true - isPrimitive({}) // false - isPrimitive([]) // false - isPrimitive(function() {}) // false - isPrimitive(new Date()) // false - isPrimitive(/a/) // false + isPrimitive('hi'); // true + isPrimitive(3); // true + isPrimitive(true); // true + isPrimitive(false); // true + isPrimitive(null); // true + isPrimitive(undefined); // true + isPrimitive(Symbol()); // true + isPrimitive({}); // false + isPrimitive([]); // false + isPrimitive(function() {}); // false + isPrimitive(new Date()); // false + isPrimitive(/a/); // false just-map-object: packageName: just-map-object dir: object-map @@ -1410,8 +1410,8 @@ just-left-pad: leftPad('hello', 9, '..'); // '....hello' leftPad('hello', 10, 'ab'); // 'bababhello' leftPad('hello', 9, '\uD83D\uDC04'); // 'πŸ„πŸ„πŸ„πŸ„hello' - leftPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // 'πŸ„πŸ‘πŸ„πŸ‘πŸ„hello' - leftPad('hello', 7, '\uD83D\uDC04'), // 'πŸ„πŸ„hello' + leftPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'); // 'πŸ„πŸ‘πŸ„πŸ‘πŸ„hello' + leftPad('hello', 7, '\uD83D\uDC04'); // 'πŸ„πŸ„hello' leftPad(null, 7); // throws leftPad([], 4, '*'); // throws leftPad('hello', 4, true); // throws @@ -1475,8 +1475,8 @@ just-right-pad: rightPad('hello', 9, '..'); // 'hello....' rightPad('hello', 10, 'ab'); // 'helloababa' rightPad('hello', 9, '\uD83D\uDC04'); // 'helloπŸ„πŸ„πŸ„πŸ„' - rightPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'), // 'helloπŸ‘πŸ„πŸ‘πŸ„πŸ‘' - rightPad('hello', 7, '\uD83D\uDC04'), // 'helloπŸ„πŸ„' + rightPad('hello', 10, '\uD83D\uDC11\uD83D\uDC04'); // 'helloπŸ‘πŸ„πŸ‘πŸ„πŸ‘' + rightPad('hello', 7, '\uD83D\uDC04'); // 'helloπŸ„πŸ„' rightPad(null, 7); // throws rightPad([], 4, '*'); // throws rightPad('hello', 4, true); // throws From f9d537fedb3a5be01bd234eff16328a114372de8 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Sun, 8 Oct 2023 14:30:39 -0400 Subject: [PATCH 4/4] refactor: use strip block chomping indicator --- packages.yml | 170 ++++++++++++++++++------------------ scripts/generate-readmes.js | 5 -- 2 files changed, 85 insertions(+), 90 deletions(-) diff --git a/packages.yml b/packages.yml index 33ba7bb87..35b3248f2 100644 --- a/packages.yml +++ b/packages.yml @@ -2,7 +2,7 @@ just-cartesian-product: packageName: just-cartesian-product dir: array-cartesian-product description: Takes an input of an array of arrays and returns their Cartesian product - examples: | + examples: |- import cartesianProduct from 'just-cartesian-product'; cartesianProduct([[1, 2], ['a', 'b']]); // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] @@ -13,7 +13,7 @@ just-compact: packageName: just-compact dir: array-compact description: Returns a copy of an array with falsey values removed - examples: | + examples: |- import compact from 'just-compact'; compact([1, null, 2, undefined, null, NaN, 3, 4, false, 5]); // [1, 2, 3, 4, 5] @@ -24,7 +24,7 @@ just-flatten-it: packageName: just-flatten-it dir: array-flatten description: Return a flattened array - examples: | + examples: |- import flatten from 'just-flatten-it'; flatten([[1, [2, 3]], [[4, 5], 6, 7, [8, 9]]]); @@ -36,7 +36,7 @@ just-group-by: packageName: just-group-by dir: array-group-by description: Return a grouped object from array - examples: | + examples: |- import groupBy from 'just-group-by'; groupBy([6.1, 4.2, 6.3], Math.floor); // { '4': [4.2], '6': [6.1, 6.3] } @@ -45,7 +45,7 @@ just-index: packageName: just-index dir: array-index description: Return an object from an array, keyed by the value at the given id - examples: | + examples: |- import index from 'just-index'; index([{id: 'first', val: 1}, {id: 'second', val: 2}], 'id'); @@ -59,7 +59,7 @@ just-insert: packageName: just-insert dir: array-insert description: Inserts a sub-array into an array starting at the given index. Returns a copy - examples: | + examples: |- import insert from 'just-insert'; insert([1, 2, 5, 6], ['a', 'c', 'e'], 2); // [1, 2, 'a', 'c', 'e', 5, 6] @@ -70,7 +70,7 @@ just-intersect: packageName: just-intersect dir: array-intersect description: Return the intersect of two arrays - examples: | + examples: |- import intersect from 'just-intersect'; intersect([1, 2, 5, 6], [2, 3, 5, 6]); // [2, 5, 6] @@ -79,7 +79,7 @@ just-last: packageName: just-last dir: array-last description: Return the last member of an array - examples: | + examples: |- import last from 'just-last'; last([1, 2, 3, 4, 5]); // 5 @@ -93,7 +93,7 @@ just-mean: packageName: just-mean dir: array-mean description: The mean (average) value in an array - examples: | + examples: |- import mean from 'just-mean'; mean([1, 2, 3, 2, 4, 1]); // 2.1666666667 @@ -105,7 +105,7 @@ just-median: packageName: just-median dir: array-median description: Return the median value of an array of numbers - examples: | + examples: |- import median from 'just-median'; median([1, 2, 3, 4, 5]); // 3 @@ -118,7 +118,7 @@ just-mode: packageName: just-mode dir: array-mode description: Return the most frequently occuring number(s) - examples: | + examples: |- import mode from 'just-mode'; mode([1, 2, 3, 2]); // 2 @@ -131,7 +131,7 @@ just-order-by: packageName: just-order-by dir: array-order-by description: Produces a new array, sorted in given order - examples: | + examples: |- import orderBy from 'just-order-by'; orderBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35] @@ -237,7 +237,7 @@ just-partition: packageName: just-partition dir: array-partition description: Elements satisfying predicate added to first array, remainder added to second - examples: | + examples: |- import partition from 'just-partition'; partition([1, 5, 2, 4, 3], n => n > 3); // [[5, 4],[1, 2, 3]] @@ -252,7 +252,7 @@ just-percentile: packageName: just-percentile dir: array-percentile description: Return the value at the given percentile (using linear interpolation) - examples: | + examples: |- import percentile from 'just-percentile'; percentile([1, 2, 3], 0); // 1 @@ -272,7 +272,7 @@ just-permutations: packageName: just-permutations dir: array-permutations description: Returns all permutations of the length N of the elements of the given array - examples: | + examples: |- import permutations from 'just-permutations'; permutations([1, 2, 3]); // [[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]] @@ -282,7 +282,7 @@ just-pipe: packageName: just-pipe dir: function-pipe description: Pass a value through a pipeline of functions - examples: | + examples: |- import pipe from 'just-pipe'; pipe(3, a => a+1, b => b*2); // 8 @@ -291,7 +291,7 @@ just-random: packageName: just-random dir: array-random description: Return a randomly selected element in an array - examples: | + examples: |- import random from 'just-random'; random([1, 2, 3]); // one of [1, 2, 3], at random @@ -299,7 +299,7 @@ just-range: packageName: just-range dir: array-range description: Generate a range array for numbers - examples: | + examples: |- import range from 'just-range'; range(1, 5); // [1, 2, 3, 4] @@ -310,7 +310,7 @@ just-remove: packageName: just-remove dir: array-remove description: Removes one array from another - examples: | + examples: |- import remove from 'just-remove'; remove([1, 2, 3, 4, 5, 6], [1, 3, 6]); // [2, 4, 5] @@ -318,7 +318,7 @@ just-shuffle: packageName: just-shuffle dir: array-shuffle description: Return the elements of an array in random order - examples: | + examples: |- import shuffle from 'just-shuffle'; shuffle([1, 2, 3]); @@ -337,7 +337,7 @@ just-skewness: packageName: just-skewness dir: array-skewness description: Return the skewness of an array or numeric argument list using Pearson's second skewness coefficient - examples: | + examples: |- import skewness from 'just-skewness'; // Using Pearson's second skewness coefficient @@ -353,7 +353,7 @@ just-sort-by: packageName: just-sort-by dir: array-sort-by description: Produces a new array, sorted in ascending order - examples: | + examples: |- import sortBy from 'just-sort-by'; sortBy([10, 1, 5, 20, 15, 35, 30, 6, 8]); // [1, 5, 6, 8, 10, 15, 20, 30, 35] @@ -398,7 +398,7 @@ just-split: packageName: just-split dir: array-split description: Splits array into groups of n items each - examples: | + examples: |- import split from 'just-split'; split([]); // [] @@ -411,7 +411,7 @@ just-split-at: packageName: just-split-at dir: array-split-at description: Splits an array into two at a given position - examples: | + examples: |- import splitAt from 'just-split-at'; splitAt([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4, 5]] @@ -423,7 +423,7 @@ just-standard-deviation: packageName: just-standard-deviation dir: array-standard-deviation description: Return the standard deviation of an array or numeric argument list - examples: | + examples: |- import standardDeviation from 'just-standard-deviation'; standardDeviation([1, 2, 3, 2, 4, 1]); // 1.16904519 @@ -438,7 +438,7 @@ just-tail: packageName: just-tail dir: array-tail description: Return all but the first element of an array - examples: | + examples: |- import tail from 'just-tail'; tail([1, 2, 3, 4, 5]); // [2, 3, 4, 5] @@ -452,7 +452,7 @@ just-union: packageName: just-union dir: array-union description: Returns the union of two arrays - examples: | + examples: |- import union from 'just-union'; union([1, 2, 5, 6], [2, 3, 4, 6]); // [1, 2, 5, 6, 3, 4] @@ -460,7 +460,7 @@ just-unique: packageName: just-unique dir: array-unique description: Dedupes an array - examples: | + examples: |- import unique from 'just-unique'; unique([1, 2, 3, 2, 3, 4, 3, 2, 1, 3]); // [1, 2, 3, 4] @@ -481,7 +481,7 @@ just-variance: packageName: just-variance dir: array-variance description: Return the standard deviation of an array or numeric argument list - examples: | + examples: |- import variance from 'just-variance'; variance([1, 2, 3, 2, 4, 1]); // 1.3666666667 @@ -498,7 +498,7 @@ just-zip-it: description: Returns an array of grouped elements, taking n-th element from every given array - examples: | + examples: |- import zip from 'just-zip-it'; zip([1, 2, 3]); // [[1], [2], [3]] @@ -513,7 +513,7 @@ just-clone: packageName: just-clone dir: collection-clone description: Deep copies objects, arrays, maps and sets - examples: | + examples: |- // Deep copies objects and arrays, doesn't clone functions import clone from 'just-clone'; @@ -530,7 +530,7 @@ just-compare: packageName: just-compare dir: collection-compare description: Compare two collections - examples: | + examples: |- import compare from 'just-compare'; // primitives: value1 === value2 @@ -549,10 +549,10 @@ just-compare: just-diff: packageName: just-diff dir: collection-diff - description: | + description: |- Return an object representing the difference between two other objects Pass converter to format as http://jsonpatch.com - examples: | + examples: |- import {diff} from 'just-diff'; const obj1 = {a: 4, b: 5}; @@ -623,7 +623,7 @@ just-diff-apply: description: Apply a diff object to an object. Pass converter to apply a http://jsonpatch.com standard patch - examples: | + examples: |- import {diffApply} from 'just-diff-apply'; const obj1 = {a: 3, b: 5}; @@ -676,7 +676,7 @@ just-flush: packageName: just-flush dir: collection-flush description: Returns a copy of an array or object with null/undefined members removed - examples: | + examples: |- import flush from 'just-flush'; flush([1, undefined, 2, null, 3, NaN, 0]); // [1, 2, 3, NaN, 0] @@ -688,7 +688,7 @@ just-pluck-it: packageName: just-pluck-it dir: collection-pluck description: Pluck a property from each member of a collection - examples: | + examples: |- import pluck from 'just-pluck-it'; pluck([{a:1, b:2}, {a:4, b:3}, {a:2, b:5}], 'a'); // [1, 4, 2] @@ -697,7 +697,7 @@ just-compose: packageName: just-compose dir: function-compose description: Return a function composed of 2 or more functions - examples: | + examples: |- import compose from 'just-compose'; const sqRootBiggest = compose(Math.max, Math.sqrt, Math.trunc); @@ -707,7 +707,7 @@ just-curry-it: packageName: just-curry-it dir: function-curry description: Return a curried function - examples: | + examples: |- import curry from 'just-curry-it'; function add(a, b, c) { @@ -734,7 +734,7 @@ just-debounce-it: packageName: just-debounce-it dir: function-debounce description: Return a debounced function - examples: | + examples: |- import debounce from 'just-debounce-it'; const fn1 = debounce(() => console.log("Hello"), 500); @@ -766,7 +766,7 @@ just-demethodize: packageName: just-demethodize dir: function-demethodize description: Turn a method into a standalone function; the first arg becomes `this` - examples: | + examples: |- import demethodize from 'just-demethodize'; const trimFn = demethodize(''.trim); @@ -775,7 +775,7 @@ just-flip: packageName: just-flip dir: function-flip description: Flip first two arguments of a function - examples: | + examples: |- import flip from 'just-flip'; flip(console.log)(1, 2, 3); // 2, 1, 3 @@ -791,7 +791,7 @@ just-memoize: packageName: just-memoize dir: function-memoize description: An implementation of the memoize technique - examples: | + examples: |- import memoize from 'just-memoize'; const sumByOne = memoize(function(value) { @@ -818,7 +818,7 @@ just-memoize-last: packageName: just-memoize-last dir: function-memoize-last description: A memoize implementation that only caches the most recent evaluation - examples: | + examples: |- import memoizeLast from 'just-memoize-last'; import compare from 'just-compare'; @@ -836,7 +836,7 @@ just-once: packageName: just-once dir: function-once description: Create a function that can only be invoked once - examples: | + examples: |- import once from 'just-once'; const fn = once(() => console.log('hello')); @@ -849,7 +849,7 @@ just-partial-it: packageName: just-partial-it dir: function-partial description: Return a partial function - examples: | + examples: |- import partial from 'just-partial-it'; const cubedRoot = partial(Math.pow, _, 1/3); @@ -861,7 +861,7 @@ just-throttle: packageName: just-throttle dir: function-throttle description: Return a throttled function - examples: | + examples: |- import throttle from 'just-throttle'; // no matter how many times the function is called, only invoke once within the given interval @@ -897,7 +897,7 @@ just-clamp: packageName: just-clamp dir: number-clamp description: Restrict a number within a range - examples: | + examples: |- import clamp from 'just-clamp'; var n = 5; @@ -921,7 +921,7 @@ just-in-range: packageName: just-in-range dir: number-in-range description: Check if number is within a given range - examples: | + examples: |- import inRange from 'just-number-in-range'; inRange(2, 1, 10); // true @@ -935,7 +935,7 @@ just-is-prime: packageName: just-is-prime dir: number-is-prime description: Check if number is prime - examples: | + examples: |- import isPrime from 'just-is-prime'; isPrime(1); // false @@ -952,7 +952,7 @@ just-modulo: packageName: just-modulo dir: number-modulo description: Modulo of a number and a divisor - examples: | + examples: |- import modulo from 'just-modulo'; modulo(7, 5); // 2 @@ -972,7 +972,7 @@ just-random-integer: packageName: just-random-integer dir: number-random-integer description: Produces a random integer within a given range - examples: | + examples: |- import random from 'just-random-integer'; random(); // Returns either 0 or 1 @@ -983,7 +983,7 @@ just-entries: packageName: just-entries dir: object-entries description: Return object entries as an array of [key, value] pairs - examples: | + examples: |- import entries from 'just-entries'; // Object: @@ -1000,7 +1000,7 @@ just-extend: packageName: just-extend dir: object-extend description: Extend an object - examples: | + examples: |- import extend from 'just-extend'; var obj = {a: 3, b: 5}; @@ -1032,7 +1032,7 @@ just-filter-object: packageName: just-filter-object dir: object-filter description: Filter an object - examples: | + examples: |- import filter from 'just-filter'; // returns a new object containing those original properties for which the predicate returns truthy @@ -1043,7 +1043,7 @@ just-flip-object: packageName: just-flip-object dir: object-flip description: Flip the keys and values - examples: | + examples: |- import flip from 'just-flip-object'; // flip the key and value @@ -1054,7 +1054,7 @@ just-has: packageName: just-has dir: object-has description: Return a boolen indicating the existence of a deep property, don't throw if parent is undefined - examples: | + examples: |- import has from 'just-has'; const obj = {a: {aa: {aaa: 2}}, b: 4}; @@ -1081,10 +1081,10 @@ just-has: just-is-circular: packageName: just-is-circular dir: object-is-circular - description: | + description: |- Return true if object has a circular reference NOTE: not supported in IE or microsoft edge - examples: | + examples: |- import isCircular from 'just-is-circular'; const a = {}; @@ -1114,7 +1114,7 @@ just-is-empty: packageName: just-is-empty dir: object-is-empty description: Return true if object has no enumerable key values - examples: | + examples: |- import isEmpty from 'just-is-empty'; isEmpty({a: 3, b: 5}); // false @@ -1141,7 +1141,7 @@ just-is-primitive: packageName: just-is-primitive dir: object-is-primitive description: Determine if a value is a primitive value - examples: | + examples: |- import isPrimitive from 'just-is-primitive'; isPrimitive('hi'); // true @@ -1160,7 +1160,7 @@ just-map-object: packageName: just-map-object dir: object-map description: Map an object, passing key and value to predicates - examples: | + examples: |- import map from 'just-map-object'; // DEPRECATED: use just-map-values @@ -1171,7 +1171,7 @@ just-map-keys: packageName: just-map-keys dir: object-map-keys description: Map an object, predicate updates keys, receives (value, key, object) - examples: | + examples: |- import map from 'just-map-keys'; // predicate updates keys, receives (value, key, object) @@ -1185,7 +1185,7 @@ just-map-values: packageName: just-map-values dir: object-map-values description: Map an object, predicate updates values, receives (value, key, object) - examples: | + examples: |- import map from 'just-map-values'; // predicate updates values, receives (value, key, obj) @@ -1196,7 +1196,7 @@ just-merge: packageName: just-merge dir: object-merge description: Shallow assign. Like just-extend but without deep copy option. - examples: | + examples: |- import merge from 'just-merge'; let obj = {a: 3, b: 5}; @@ -1221,7 +1221,7 @@ just-omit: packageName: just-omit dir: object-omit description: Copy an object but omit the specified keys - examples: | + examples: |- import omit from 'just-omit'; var obj = {a: 3, b: 5, c: 9}; @@ -1233,7 +1233,7 @@ just-pick: packageName: just-pick dir: object-pick description: Copy an object but with only the specified keys - examples: | + examples: |- import pick from 'just-pick'; var obj = { a: 3, b: 5, c: 9 }; @@ -1245,7 +1245,7 @@ just-reduce-object: packageName: just-reduce-object dir: object-reduce description: Reduce an object - examples: | + examples: |- import reduce from 'just-reduce-object'; // applies a function against an accumulator and each key-value pairs of the object @@ -1263,7 +1263,7 @@ just-safe-get: packageName: just-safe-get dir: object-safe-get description: Get value at property, don't throw if parent is undefined - examples: | + examples: |- import get from 'just-safe-get'; const obj = {a: {aa: {aaa: 2}}, b: 4}; @@ -1297,7 +1297,7 @@ just-safe-set: packageName: just-safe-set dir: object-safe-set description: Set value at property, create intermediate properties if necessary - examples: | + examples: |- import set from 'just-safe-set'; const obj1 = {}; @@ -1320,7 +1320,7 @@ just-typeof: packageName: just-typeof dir: object-typeof description: Type inferer - examples: | + examples: |- import typeOf from 'just-typeof'; typeOf({}); // 'object' @@ -1337,7 +1337,7 @@ just-values: packageName: just-values dir: object-values description: Return property values as an array - examples: | + examples: |- import values from 'just-values'; values({a: 4, c: 8}); // [4, 8] @@ -1354,7 +1354,7 @@ just-camel-case: packageName: just-camel-case dir: string-camel-case description: Convert a string to camel case - examples: | + examples: |- import camelCase from 'just-camel-case'; camelCase('the quick brown fox'); // 'theQuickBrownFox' @@ -1375,7 +1375,7 @@ just-capitalize: packageName: just-capitalize dir: string-capitalize description: Capitalize the first character of a string - examples: | + examples: |- import capitalize from 'just-capitalize'; capitalize('capitals'); // 'Capitals' @@ -1386,7 +1386,7 @@ just-kebab-case: packageName: just-kebab-case dir: string-kebab-case description: Convert a string to kebab case - examples: | + examples: |- import kebabCase from 'just-kebab-case'; kebabCase('the quick brown fox'); // 'the-quick-brown-fox' @@ -1401,7 +1401,7 @@ just-left-pad: packageName: just-left-pad dir: string-left-pad description: Add characters to the left of a string such that its total length is n - examples: | + examples: |- import leftPad from 'just-left-pad'; leftPad('hello', 9); // ' hello' @@ -1421,7 +1421,7 @@ just-pascal-case: packageName: just-pascal-case dir: string-pascal-case description: Convert a string to pascal case - examples: | + examples: |- import pascalCase from 'just-pascal-case'; pascalCase('the quick brown fox'); // 'TheQuickBrownFox' @@ -1435,7 +1435,7 @@ just-prune: packageName: just-prune dir: string-prune description: Prune a string with whole words and a custom suffix - examples: | + examples: |- import prune from 'just-prune'; prune('when shall we three meet again', 7); // 'when...' @@ -1447,7 +1447,7 @@ just-replace-all: packageName: just-replace-all dir: string-replace-all description: Replace all occurrences of a string within a string with another string - examples: | + examples: |- import replaceAll from 'just-replace-all'; replaceAll('hello, world', 'l', 'q'); // 'heqqo, worqd' @@ -1466,7 +1466,7 @@ just-right-pad: packageName: just-right-pad dir: string-right-pad description: Add characters to the right of a string such that its total length is n - examples: | + examples: |- import rightPad from 'just-right-pad'; rightPad('hello', 9); // 'hello ' @@ -1486,7 +1486,7 @@ just-snake-case: packageName: just-snake-case dir: string-snake-case description: Convert a string to snake case - examples: | + examples: |- import snakeCase from 'just-snake-case'; snakeCase('the quick brown fox'); // 'the_quick_brown_fox' @@ -1500,7 +1500,7 @@ just-squash: packageName: just-squash dir: string-squash description: Remove all spaces from a string, optionally remove escape sequences too - examples: | + examples: |- import squash from 'just-squash'; squash('the cat sat on the mat'); // 'thecatsatonthemat' @@ -1512,7 +1512,7 @@ just-template: packageName: just-template dir: string-template description: Interpolate a string with variables - examples: | + examples: |- import template from 'just-template'; var data = { @@ -1531,7 +1531,7 @@ just-truncate: packageName: just-truncate dir: string-truncate description: Truncate a string with a custom suffix - examples: | + examples: |- import truncate from 'just-truncate'; truncate('when shall we three meet again', 9); // 'when s...' @@ -1543,7 +1543,7 @@ just-deep-map-values: packageName: just-deep-map-values dir: object-deep-map-values description: Returns an object with values at all depths mapped according to the provided function - examples: | + examples: |- import deepMapValues from 'just-deep-map-values'; const squareFn = (number) => number * number; diff --git a/scripts/generate-readmes.js b/scripts/generate-readmes.js index 89a0e2bed..05904d904 100644 --- a/scripts/generate-readmes.js +++ b/scripts/generate-readmes.js @@ -9,11 +9,6 @@ const packageVariables = YAML.parse( readFileSync('./packages.yml', 'utf8') ); -Object.entries(packageVariables).forEach(([name, data]) => { - packageVariables[name].examples = data.examples.trim(); - packageVariables[name].description = data.description.trim(); -}); - const templates = { local: 'templates/local.template.md', global: 'templates/global.template.md',