diff --git a/README.MD b/README.MD index 6f8849c..1b952e0 100644 --- a/README.MD +++ b/README.MD @@ -1,25 +1,54 @@ # DenoDash ## A Typescript-First utility library for Deno -### Why yet another utility library? -I'll be honest, I *love* Lodash in my node projects. Even though I could implment many of the features myself, it's just convenient to have it all in a simple package that is pretty standard. But it's not without it's flaws, especially when going from Node to Deno. +### Why yet another utility library? -Lodash was designed in a EMCA 3 kind of world, where things such as "filter" and "slice" were not yet part of the official Javascript prototype. Moving forward, there are a lot of utilities that a utility library can omit. Do we really need _.last when we can just write arr[arr.length - 1]? Or _.compact when we can just write arr.filter(x => !!x)? +I'll be honest, I _love_ Lodash in my node projects. Even though I could +implment many of the features myself, it's just convenient to have it all in a +simple package that is pretty standard. But it's not without it's flaws, +especially when going from Node to Deno. + +Lodash was designed in a EMCA 3 kind of world, where things such as "filter" and +"slice" were not yet part of the official Javascript prototype. Moving forward, +there are a lot of utilities that a utility library can omit. Do we really need +_.last when we can just write arr[arr.length - 1]? Or _.compact when we can just +write arr.filter(x => !!x)? + +Instead of importing Lodash into the new Deno ecosystem, I thought it was a good +idea to write a new utility library - one designed from the ground up to work in +the deno paradigm. That means typescript (with generics where possible) and +stand-alone modules. -Instead of importing Lodash into the new Deno ecosystem, I thought it was a good idea to write a new utility library - one designed from the ground up to work in the deno paradigm. That means typescript (with generics where possible) and stand-alone modules. ## Goals of the project -* Every function can be imported independently, meaning that you don't need to download the whole package for one utility. Just need "get"? Just get "get"! -* Full Typescript Support including generics. While generics are an advanced Typescript topic, the use of generics in a utility library will help with typechecking going forward and prevent nasty errors. -* Only provide what is missing from the core. Functions that can be trivially implmented or are already part of the prototype should be omitted; conversely, helpful utilities not available in other libraries might have a home here. -* Practically Functional. While mutation *within* the utility function is allowed, no utility function should *ever* mutate a parameter passed to it, returning only new variables. These functions will never change your inputs. -* Utility Types as well as utility functions - some function and object constructions are common enough that they can be implemented as named types. Comparator, Iteratee, Predicate, etc. These types are provided to extend the functionality of Typescript's already good library of utility types (Partial, Required, et. al) +- Every function can be imported independently, meaning that you don't need to + download the whole package for one utility. Just need "get"? Just get "get"! +- Full Typescript Support including generics. While generics are an advanced + Typescript topic, the use of generics in a utility library will help with + typechecking going forward and prevent nasty errors. +- Only provide what is missing from the core. Functions that can be trivially + implmented or are already part of the prototype should be omitted; conversely, + helpful utilities not available in other libraries might have a home here. +- Practically Functional. While mutation _within_ the utility function is + allowed, no utility function should _ever_ mutate a parameter passed to it, + returning only new variables. These functions will never change your inputs. +- Utility Types as well as utility functions - some function and object + constructions are common enough that they can be implemented as named types. + Comparator, Iteratee, Predicate, etc. These types are provided to extend the + functionality of Typescript's already good library of utility types (Partial, + Required, et. al) + ### Changing the order -A pattern that I found in Lodash was often that the library offered many functions ending with the suffix "-by" or "-with" that took a function as the *last* parameter, iterating over the arguments provided until it hit a function. This made a lot of sense in the days before spread operators, but it seemed to me that it would be better to put the function first... or *even better*, create a curried function. +A pattern that I found in Lodash was often that the library offered many +functions ending with the suffix "-by" or "-with" that took a function as the +_last_ parameter, iterating over the arguments provided until it hit a function. +This made a lot of sense in the days before spread operators, but it seemed to +me that it would be better to put the function first... or _even better_, create +a curried function. -For example, lodash's "intersectionBy" has the following syntax and examples: +For example, lodash's "intersectionBy" has the following syntax and examples: ```javascript // _.intersectionBy([arrays], [iteratee=_.identity]) @@ -27,394 +56,408 @@ _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); // => [2.1]; ``` -To me, it seemed like a better way to handle this would be: +To me, it seemed like a better way to handle this would be: ```typescript // const intersectionBy = (fn: Iteratee) => (...arrays: T[][]): T[] // or without the generics: // intersectionBy = (fn: Function) => (...arrays: Array>) => Array) -intersectionBy(Math.floor, [2.1, 1.2], [2.3, 3.2]) +intersectionBy(Math.floor, [2.1, 1.2], [2.3, 3.2]); // => [2.1] ``` -At one point I considered using currying, but as this is a utility library, the inefficiency of closures in V8 makes a simple function the way to go for now. +At one point I considered using currying, but as this is a utility library, the +inefficiency of closures in V8 makes a simple function the way to go for now. + ## Current High Priority Needs: + ### Debounce & Throttle -It can be difficult to test Debounce and Throttle, and I'm not 100% sure I got the implementation right. I'd like another pair of eyes on it if it's possible, and some more tests. -## Methods: -### Currently Supported: - -* array - * cartesianProduct - * chunk - * chunkIntoParts - * difference - * differenceBy - * differenceWith - * dropWhile - * dropWhileRight - * findLastIndex - * flatten - * flattenDeep - * flattenDepth - * fromPairs - * intersection - * intersectionBy - * intersectionWith - * lastIndexOf - * partition - Lodash lists this in "Collections" - * partitionBy - Lodash lists this in "Collections" - * shank - like Array.prototype.splice, but returns a new array rather than mutating the old one. - * union - * unionBy - * unionWith - * uniq - * uniqBy - * uniqWith - * unzip - * xor - * zip -* collection - * count - * countBy - * flatMapDeep - * flatMapDepth - * groupBy - * keyBy - * sample - * sampleOne - * shuffle - * sortBy -* function - * after - * before - * debounce - * defer - * memoize - * once - * overArgs - * throttle -* lang - * cloneDeep - * isEqual -* objects - * findKeys - * get - * invert - * mapObject - * omit - * pick -* types - * type Comparator - * type Iteratee - * type ObjectKey - * type Predicate - * type SortComparator - * type Transformer - * type ValueOrArray -* utils - * comparatorChain - * delay - * identity - * mergeSort - * randomOf +It can be difficult to test Debounce and Throttle, and I'm not 100% sure I got +the implementation right. I'd like another pair of eyes on it if it's possible, +and some more tests. + +## Methods: + +### Currently Supported: + +- array + - cartesianProduct + - chunk + - chunkIntoParts + - difference + - differenceBy + - differenceWith + - dropWhile + - dropWhileRight + - findLastIndex + - flatten + - flattenDeep + - flattenDepth + - fromPairs + - intersection + - intersectionBy + - intersectionWith + - lastIndexOf + - partition - Lodash lists this in "Collections" + - partitionBy - Lodash lists this in "Collections" + - shank - like Array.prototype.splice, but returns a new array rather than + mutating the old one. + - union + - unionBy + - unionWith + - uniq + - uniqBy + - uniqWith + - unzip + - xor + - zip +- collection + - count + - countBy + - flatMapDeep + - flatMapDepth + - groupBy + - keyBy + - sample + - sampleOne + - shuffle + - sortBy +- function + - after + - before + - debounce + - defer + - memoize + - once + - overArgs + - throttle +- lang + - cloneDeep + - isEqual +- objects + - findKeys + - get + - invert + - mapObject + - omit + - pick +- types + - type Comparator + - type Iteratee + - type ObjectKey + - type Predicate + - type SortComparator + - type Transformer + - type ValueOrArray +- utils + - comparatorChain + - delay + - identity + - mergeSort + - randomOf ### Roadmap Refactor: -Refactor curried functions into regular functions. - These methods are likely next to be implemented -* utils - * range - * uniqueId -* monad (refered to as "Seq" in lodash) - * monadify - * Monad.map - * Monad.tap - * Monad.value - * Monad.chain -* types - * type Monad -* utils - * toPath - +- utils + - range + - uniqueId +- monad (refered to as "Seq" in lodash) + - monadify + - Monad.map + - Monad.tap + - Monad.value + - Monad.chain +- types + - type Monad +- utils + - toPath + ### Proposed -These methods might be implemented, but they're not high priority. - -* array - * sortedIndex - * sortedIndexBy - * sortedIndexOf - * sortedLastIndex - * sortedLastIndexOf - * sortedUniq - * sortedUniqBy - * xorBy - * xorWith - * zipObject - * zipObjectDeep - * zipWith -* utils - * heapSort -* string - * camelCase - * capitalize - * deburr - * escape - * kebabCase - * lowerFirst - * padEnd - * padStart - * padSides - * snakeCase - * startCase - * unescape - * upperFirst +These methods might be implemented, but they're not high priority. + +- array + - sortedIndex + - sortedIndexBy + - sortedIndexOf + - sortedLastIndex + - sortedLastIndexOf + - sortedUniq + - sortedUniqBy + - xorBy + - xorWith + - zipObject + - zipObjectDeep + - zipWith +- utils + - heapSort +- string + - camelCase + - capitalize + - deburr + - escape + - kebabCase + - lowerFirst + - padEnd + - padStart + - padSides + - snakeCase + - startCase + - unescape + - upperFirst ### Will Not Implement -These are methods currently found in Lodash and/or Underscore which won't be implemented. Most of them are already implimented natively in TS/EMCA 6.0. Some of them are trivial to impliment. ('head(myArray)', for example, can be replaced by 'myArray[0]'). My guide to 'triviality' is that if it would take more characters to import the method from denoland than it would to re-create the function, it's probably trivial. - -However, I may have been overzealous in my trimming, if you think that one of these methods is needed, please create an issue. - -* array - * compact - * concat - * drop - * dropRight - * fill - * findIndex - * first - * head - * indexOf - * initial - * nth - * pull - * pullAll - * pullAllBy - * pullAllWith - * pullAt - * remove - * reverse - * slice - * tail - * take - * takeRight - * takeRightWhile - * takeWhile - * unzipWith - * without -* collection - * each/forEach - * eachRight/forEachRight - * every - * filter - * find - * findLast - * flatMap - * includes - * invokeMap - * map - * orderBy - * reduce - * reduceRight - * reject - * size - * some -* date - * now -* function - * ary - * bind - * bindKey - * curry - * curryRight - * flip - * negate - * partial - * partialRight - * rearg - * rest - * spread - * unary - * wrap -* lang - * castArray - * clone - * cloneDeepWith - * cloneWith - * conformsTo - * eq - * gt - * gte - * isArguments - * isArray - * isArrayBuffer - * isArrayLike - * isArrayLikeObject - * isBoolean - * isBuffer - * isDate - * isElement - * isEmpty - * isEqualWith - * isError - * isFinite - * isFunction - * isInteger - * isLength - * isMap - * isMatch - * isMatchWith - * isNaN - * isNative - * isNil - * isNull - * isNumber - * isObject - * isObjectLike - * isPlainObject - * isRegExp - * isSafeInteger - * isSet - * isString - * isSymbol - * isTypedArray - * isUndefined - * isWeakMap - * isWeakSet - * lt - * lte - * toArray - * toFinite - * toInteger - * toLength - * toNumber - * toPlainObject - * toSafeInteger - * toString -* math - * add - * ceil - * divide - * floor - * max - * maxBy - * mean - * meanBy - * min - * minBy - * multiply - * round - * subtract - * sum - * sumBy -* number - * clamp - * inRange - * random -* objects - * assign - * assignIn - * assignInWith - * assignWith - * at - * create - * defaults - * defaultsDeep - * entries - * entriesIn - * extend - * extendWith - * findKey - * findLastKey - * forIn - * forInRight - * forOwn - * forOwnRight - * functions - * functionsIn - * has - * hasIn - * invertBy - * invoke - * keys - * keysIn - * mapKeys - * mapValues - * merge - * mergeWith - * omitBy - * pickBy - * result - * set - * setWith - * toPairs - * toPairsIn - * transform - * unset - * update - * updateWith - * values - * valuesIn -* string - * endsWith - * escapeRegExp - * lowerCase - * parseInt - * repeat - * replace - * split - * template - * toLower - * toUpper - * trim - * trimEnd - * trimStart - * truncate - * upperCase - * words -* utils - * attempt - * bindAll - * cond - * conforms - * constant - * defaulTo - * flow - * flowRight - * iteratee - * matches - * matchesProperty - * method - * methodOf - * mixin - * noConflict - * noop - * nthArg - * over - * overEvery - * overSome - * property - * proprtyOf - * rangeRight - * runInContext - * stubArray - * stubFalse - * stubObject - * stubString - * stubTrue - * times +These are methods currently found in Lodash and/or Underscore which won't be +implemented. Most of them are already implimented natively in TS/EMCA 6.0. Some +of them are trivial to impliment. ('head(myArray)', for example, can be replaced +by 'myArray[0]'). My guide to 'triviality' is that if it would take more +characters to import the method from denoland than it would to re-create the +function, it's probably trivial. + +However, I may have been overzealous in my trimming, if you think that one of +these methods is needed, please create an issue. + +- array + - compact + - concat + - drop + - dropRight + - fill + - findIndex + - first + - head + - indexOf + - initial + - nth + - pull + - pullAll + - pullAllBy + - pullAllWith + - pullAt + - remove + - reverse + - slice + - tail + - take + - takeRight + - takeRightWhile + - takeWhile + - unzipWith + - without +- collection + - each/forEach + - eachRight/forEachRight + - every + - filter + - find + - findLast + - flatMap + - includes + - invokeMap + - map + - orderBy + - reduce + - reduceRight + - reject + - size + - some +- date + - now +- function + - ary + - bind + - bindKey + - curry + - curryRight + - flip + - negate + - partial + - partialRight + - rearg + - rest + - spread + - unary + - wrap +- lang + - castArray + - clone + - cloneDeepWith + - cloneWith + - conformsTo + - eq + - gt + - gte + - isArguments + - isArray + - isArrayBuffer + - isArrayLike + - isArrayLikeObject + - isBoolean + - isBuffer + - isDate + - isElement + - isEmpty + - isEqualWith + - isError + - isFinite + - isFunction + - isInteger + - isLength + - isMap + - isMatch + - isMatchWith + - isNaN + - isNative + - isNil + - isNull + - isNumber + - isObject + - isObjectLike + - isPlainObject + - isRegExp + - isSafeInteger + - isSet + - isString + - isSymbol + - isTypedArray + - isUndefined + - isWeakMap + - isWeakSet + - lt + - lte + - toArray + - toFinite + - toInteger + - toLength + - toNumber + - toPlainObject + - toSafeInteger + - toString +- math + - add + - ceil + - divide + - floor + - max + - maxBy + - mean + - meanBy + - min + - minBy + - multiply + - round + - subtract + - sum + - sumBy +- number + - clamp + - inRange + - random +- objects + - assign + - assignIn + - assignInWith + - assignWith + - at + - create + - defaults + - defaultsDeep + - entries + - entriesIn + - extend + - extendWith + - findKey + - findLastKey + - forIn + - forInRight + - forOwn + - forOwnRight + - functions + - functionsIn + - has + - hasIn + - invertBy + - invoke + - keys + - keysIn + - mapKeys + - mapValues + - merge + - mergeWith + - omitBy + - pickBy + - result + - set + - setWith + - toPairs + - toPairsIn + - transform + - unset + - update + - updateWith + - values + - valuesIn +- string + - endsWith + - escapeRegExp + - lowerCase + - parseInt + - repeat + - replace + - split + - template + - toLower + - toUpper + - trim + - trimEnd + - trimStart + - truncate + - upperCase + - words +- utils + - attempt + - bindAll + - cond + - conforms + - constant + - defaulTo + - flow + - flowRight + - iteratee + - matches + - matchesProperty + - method + - methodOf + - mixin + - noConflict + - noop + - nthArg + - over + - overEvery + - overSome + - property + - proprtyOf + - rangeRight + - runInContext + - stubArray + - stubFalse + - stubObject + - stubString + - stubTrue + - times ## Authors & Contributors -Right now, this is a solo project of Brian Boyko, but this is being opened up to contributions. +Right now, this is a solo project of Brian Boyko, but this is being opened up to +contributions. ## Changelog -This is still in pre-alpha, with fuller documentation and publishing to deno.land to come. \ No newline at end of file +This is still in pre-alpha, with fuller documentation and publishing to +deno.land to come. diff --git a/src/array.test.ts b/src/array.test.ts index 99675e6..4e0fae8 100644 --- a/src/array.test.ts +++ b/src/array.test.ts @@ -40,9 +40,9 @@ Rhum.testPlan("array/*", () => { () => { Rhum.asserts.assertEquals( partition(["beep", "boop", "foo", "bar"], [true, true, false, true]), - [["beep", "boop", "bar"], ["foo"]] + [["beep", "boop", "bar"], ["foo"]], ); - } + }, ); }); Rhum.testSuite("partitionBy()", () => { @@ -56,9 +56,9 @@ Rhum.testPlan("array/*", () => { "foo", "bar", ]), - [["beep", "boop", "bar"], ["foo"]] + [["beep", "boop", "bar"], ["foo"]], ); - } + }, ); }); Rhum.testSuite("cartesianProduct()", () => { @@ -71,7 +71,7 @@ Rhum.testPlan("array/*", () => { ["y", 1], ["y", 2], ]); - } + }, ); }); }); @@ -193,12 +193,12 @@ Rhum.testSuite("differenceWith()", () => { const actual1 = differenceWith( (obj1, obj2) => obj1.x === obj2.x, objects, - [{ x: 1, y: 2 }] + [{ x: 1, y: 2 }], ); const actual2 = differenceWith( (obj1, obj2) => obj1.y === obj2.y, objects, - [{ x: 3, y: 2 }] + [{ x: 3, y: 2 }], ); Rhum.asserts.assertEquals(actual1, [{ x: 2, y: 1 }]); @@ -215,9 +215,9 @@ Rhum.testSuite("dropWhile()", () => { const testArr = [1, 2, 3, 4, 3, 2, 1]; Rhum.asserts.assertEquals( dropWhile(testArr, (x) => x < 3), - [3, 4, 3, 2, 1] + [3, 4, 3, 2, 1], ); - } + }, ); }); Rhum.testSuite("dropWhileRight()", () => { @@ -227,9 +227,9 @@ Rhum.testSuite("dropWhileRight()", () => { const testArr = [1, 2, 3, 4, 3, 2, 1]; Rhum.asserts.assertEquals( dropWhileRight(testArr, (x) => x < 3), - [1, 2, 3, 4, 3] + [1, 2, 3, 4, 3], ); - } + }, ); }); Rhum.testSuite("findLastIndex()", () => { @@ -237,7 +237,7 @@ Rhum.testSuite("findLastIndex()", () => { const testArr = [1, 2, 3, 4, 3, 2, 1]; Rhum.asserts.assertEquals( findLastIndex(testArr, (x: number) => x === 3), - 4 + 4, ); }); }); @@ -270,7 +270,7 @@ Rhum.testSuite("fromPairs()", () => { ["b", 2], ]; Rhum.asserts.assertEquals(fromPairs(testArr), { a: 1, b: 2 }); - } + }, ); }); Rhum.testSuite("intersection()", () => { @@ -282,7 +282,7 @@ Rhum.testSuite("intersection()", () => { [2, 3], ]; Rhum.asserts.assertEquals(intersection(...testArrs), [2]); - } + }, ); }); Rhum.testSuite("intersectionBy()", () => { @@ -291,7 +291,7 @@ Rhum.testSuite("intersectionBy()", () => { () => { Rhum.asserts.assertEquals( intersectionBy(Math.floor, [2.1, 1.2], [2.3, 3.4]), - [2.1] + [2.1], ); Rhum.asserts.assertEquals( intersectionBy( @@ -300,11 +300,11 @@ Rhum.testSuite("intersectionBy()", () => { [ { x: 2, y: 7 }, { x: 1, y: 35 }, - ] + ], ), - [{ x: 1, y: 7 }] + [{ x: 1, y: 7 }], ); - } + }, ); }); Rhum.testSuite("intersectionWith()", () => { @@ -323,11 +323,11 @@ Rhum.testSuite("intersectionWith()", () => { intersectionWith( (a, b) => JSON.stringify(a) === JSON.stringify(b), objects, - others + others, ), - [{ x: 1, y: 2 }] + [{ x: 1, y: 2 }], ); - } + }, ); }); Rhum.testSuite("zip()", () => { @@ -360,7 +360,7 @@ Rhum.testSuite("shank", () => { ]); Rhum.asserts.assertEquals(namesNoBravo, ["alpha", "charlie"]); Rhum.asserts.assertEquals(names, ["alpha", "bravo", "charlie"]); - } + }, ); }); Rhum.testSuite("union()", () => { @@ -368,7 +368,7 @@ Rhum.testSuite("union()", () => { "Creates an array of unique values, in order, from all given arrays", () => { Rhum.asserts.assertEquals(union([2, 1, 3], [4, 3, 7]), [2, 1, 3, 4, 7]); - } + }, ); }); Rhum.testSuite("unionBy()", () => { @@ -387,14 +387,14 @@ Rhum.testSuite("unionBy()", () => { { x: 2, y: 9 }, { x: 1, y: 30 }, { x: 2, y: 44 }, - ] + ], ), [ { x: 1, y: 7 }, { x: 2, y: 9 }, - ] + ], ); - } + }, ); }); Rhum.testSuite("unionWith()", () => { @@ -413,15 +413,15 @@ Rhum.testSuite("unionWith()", () => { unionWith( (a, b) => JSON.stringify(a) === JSON.stringify(b), objects, - others + others, ), [ { x: 1, y: 2 }, { x: 2, y: 1 }, { x: 1, y: 1 }, - ] + ], ); - } + }, ); }); Rhum.testSuite("uniq()", () => { @@ -443,9 +443,9 @@ Rhum.testSuite("uniqBy()", () => { { x: 2 }, { x: 1 }, ]), - [{ x: 1 }, { x: 2 }] + [{ x: 1 }, { x: 2 }], ); - } + }, ); }); Rhum.testSuite("uniqWith()", () => { @@ -459,14 +459,14 @@ Rhum.testSuite("uniqWith()", () => { { x: 1, y: 2 }, { x: 2, y: 1 }, { x: 1, y: 2 }, - ] + ], ), [ { x: 1, y: 2 }, { x: 2, y: 1 }, - ] + ], ); - } + }, ); }); Rhum.testSuite("unzip()", () => { @@ -480,7 +480,7 @@ Rhum.testSuite("unzip()", () => { ["a", "b"], [1, 2], [true, false], - ] + ], ); }); }); diff --git a/src/array/cartesianProduct.ts b/src/array/cartesianProduct.ts index 5f8aeb5..5a9b1b5 100644 --- a/src/array/cartesianProduct.ts +++ b/src/array/cartesianProduct.ts @@ -1,16 +1,16 @@ export const cartesianProduct = (a: T[], b: U[]): [T, U][] => { - const output: [T, U][] = []; - for(const aElem of a){ - for(const bElem of b){ + const output: [T, U][] = []; + for (const aElem of a) { + for (const bElem of b) { output.push([aElem, bElem]); } } return output; -} +}; export default cartesianProduct; /* cartesianProduct(['x', 'y'], [1, 2]); // [['x', 1], ['x', 2], ['y', 1], ['y', 2]] -*/ \ No newline at end of file +*/ diff --git a/src/array/chunk.ts b/src/array/chunk.ts index d0a4ee4..bd13ea7 100644 --- a/src/array/chunk.ts +++ b/src/array/chunk.ts @@ -9,4 +9,4 @@ export const chunk = (arr: T[], size = 1): T[][] => { return output; }; -export default chunk; \ No newline at end of file +export default chunk; diff --git a/src/array/chunkIntoParts.ts b/src/array/chunkIntoParts.ts index cd0dc84..2f0ce07 100644 --- a/src/array/chunkIntoParts.ts +++ b/src/array/chunkIntoParts.ts @@ -1,8 +1,8 @@ -import chunk from './chunk.ts'; +import chunk from "./chunk.ts"; export const chunkIntoParts = (arr: T[], parts = 1): T[][] => { - const size = Math.ceil(arr.length / parts); - return chunk(arr, size); -} + const size = Math.ceil(arr.length / parts); + return chunk(arr, size); +}; -export default chunkIntoParts; \ No newline at end of file +export default chunkIntoParts; diff --git a/src/array/differenceWith.ts b/src/array/differenceWith.ts index 517f5fd..5c25176 100644 --- a/src/array/differenceWith.ts +++ b/src/array/differenceWith.ts @@ -1,7 +1,10 @@ import type { Comparator } from "../types/Comparator.d.ts"; export const differenceWith = ( - comparator: Comparator, a: T[], b: T[]) => { + comparator: Comparator, + a: T[], + b: T[], +) => { const diffs: T[] = []; for (const val of a) { if (!b.some((bVal) => comparator(val, bVal))) { diff --git a/src/array/dropWhile.ts b/src/array/dropWhile.ts index c75cb9b..1496798 100644 --- a/src/array/dropWhile.ts +++ b/src/array/dropWhile.ts @@ -2,14 +2,14 @@ import { Predicate } from "../types/Predicate.d.ts"; export const dropWhile = ( arr: T[], - predicate: Predicate + predicate: Predicate, ): T[] => { const l = arr.length; let cursor = 0; while (cursor < l && predicate(arr[cursor])) { - cursor += 1 + cursor += 1; } return arr.slice(cursor); }; -export default dropWhile; \ No newline at end of file +export default dropWhile; diff --git a/src/array/dropWhileRight.ts b/src/array/dropWhileRight.ts index 4022fdf..acdc7e1 100644 --- a/src/array/dropWhileRight.ts +++ b/src/array/dropWhileRight.ts @@ -2,7 +2,7 @@ import { Predicate } from "../types/Predicate.d.ts"; export const dropWhileRight = ( arr: T[], - predicate: Predicate + predicate: Predicate, ): T[] => { const l = arr.length; let i = l - 1; @@ -12,4 +12,4 @@ export const dropWhileRight = ( return arr.slice(0, i + 1); }; -export default dropWhileRight; \ No newline at end of file +export default dropWhileRight; diff --git a/src/array/findLastIndex.ts b/src/array/findLastIndex.ts index fbad0a5..9eb5adc 100644 --- a/src/array/findLastIndex.ts +++ b/src/array/findLastIndex.ts @@ -2,7 +2,7 @@ import { Predicate } from "../types/Predicate.d.ts"; export const findLastIndex = ( arr: T[], - predicate: Predicate + predicate: Predicate, ): number => { const l = arr.length; let i = l - 1; @@ -12,4 +12,4 @@ export const findLastIndex = ( return i; }; -export default findLastIndex; \ No newline at end of file +export default findLastIndex; diff --git a/src/array/flatten.ts b/src/array/flatten.ts index 5e5bbd1..b5245cc 100644 --- a/src/array/flatten.ts +++ b/src/array/flatten.ts @@ -1,5 +1,5 @@ -import flattenDepth from './flattenDepth.ts'; +import flattenDepth from "./flattenDepth.ts"; export const flatten = (arr: any[]) => flattenDepth(arr, 1); -export default flatten; \ No newline at end of file +export default flatten; diff --git a/src/array/flattenDeep.ts b/src/array/flattenDeep.ts index 9b82322..0038402 100644 --- a/src/array/flattenDeep.ts +++ b/src/array/flattenDeep.ts @@ -1,6 +1,6 @@ -import flattenDepth from './flattenDepth.ts'; +import flattenDepth from "./flattenDepth.ts"; export const flattenDeep = (arr: any[]) => flattenDepth(arr, Number.MAX_SAFE_INTEGER); -export default flattenDeep; \ No newline at end of file +export default flattenDeep; diff --git a/src/array/flattenDepth.ts b/src/array/flattenDepth.ts index 1dc06c9..5ea4665 100644 --- a/src/array/flattenDepth.ts +++ b/src/array/flattenDepth.ts @@ -1,4 +1,3 @@ - export const flattenDepth = (arr: any[], level = 1, currLevel = 1) => { const clone = arr.slice(); if (level === 0) { @@ -10,10 +9,10 @@ export const flattenDepth = (arr: any[], level = 1, currLevel = 1) => { output = output.concat( Array.isArray(elem) && currLevel < level ? flattenDepth(elem, level, currLevel + 1) - : elem + : elem, ); } return output; }; -export default flattenDepth; \ No newline at end of file +export default flattenDepth; diff --git a/src/array/fromPairs.ts b/src/array/fromPairs.ts index f1d41b0..ed54690 100644 --- a/src/array/fromPairs.ts +++ b/src/array/fromPairs.ts @@ -1,5 +1,5 @@ export const fromPairs = ( - arr: Array + arr: Array, ): Record => { const record: Record = {} as Record; for (const tuple of arr) { @@ -12,4 +12,4 @@ export const fromPairs = ( return record; }; -export default fromPairs; \ No newline at end of file +export default fromPairs; diff --git a/src/array/intersection.ts b/src/array/intersection.ts index ad5fab5..b9c9494 100644 --- a/src/array/intersection.ts +++ b/src/array/intersection.ts @@ -1,6 +1,7 @@ import intersectionBy from "./intersectionBy.ts"; import identity from "../utils/identity.ts"; -export const intersection = (...arrays: T[][]) => intersectionBy(identity, ...arrays) +export const intersection = (...arrays: T[][]) => + intersectionBy(identity, ...arrays); -export default intersection; \ No newline at end of file +export default intersection; diff --git a/src/array/intersectionWith.ts b/src/array/intersectionWith.ts index 2a04edc..3e5d9fb 100644 --- a/src/array/intersectionWith.ts +++ b/src/array/intersectionWith.ts @@ -1,6 +1,7 @@ import type { Comparator } from "../types/Comparator.d.ts"; -const intersectionWith = (comparator: Comparator, +const intersectionWith = ( + comparator: Comparator, ...arrays: T[][] ): T[] => { const baseArray = arrays[0]; diff --git a/src/array/lastIndexOf.ts b/src/array/lastIndexOf.ts index f917d97..8716ef3 100644 --- a/src/array/lastIndexOf.ts +++ b/src/array/lastIndexOf.ts @@ -3,4 +3,4 @@ import findLastIndex from "./findLastIndex.ts"; export const lastIndexOf = (arr: T[], target: T) => findLastIndex(arr, (elem: T): boolean => elem === target); -export default lastIndexOf; \ No newline at end of file +export default lastIndexOf; diff --git a/src/array/partitionBy.ts b/src/array/partitionBy.ts index d4faaa9..ce80088 100644 --- a/src/array/partitionBy.ts +++ b/src/array/partitionBy.ts @@ -1,6 +1,6 @@ export const partitionBy = ( fn: (val: T, i: number) => boolean, - arr: T[] + arr: T[], ) => { const trueArray: T[] = []; const falseArray: T[] = []; diff --git a/src/array/shank.ts b/src/array/shank.ts index 60c7df6..9522fce 100644 --- a/src/array/shank.ts +++ b/src/array/shank.ts @@ -1,10 +1,15 @@ /* Works exactly like Array.prototype.splice, but returns a new array, rather than mutating the original. */ -export const shank = (arr: T[], index = 0, delCount = 0, ...elements: T[]): T[] => +export const shank = ( + arr: T[], + index = 0, + delCount = 0, + ...elements: T[] +): T[] => arr .slice(0, index) .concat(elements) .concat(arr.slice(index + delCount)); -export default shank; \ No newline at end of file +export default shank; diff --git a/src/array/uniq.ts b/src/array/uniq.ts index a98bfc2..114fdd0 100644 --- a/src/array/uniq.ts +++ b/src/array/uniq.ts @@ -1,6 +1,6 @@ -import identity from '../utils/identity.ts'; -import unionBy from './unionBy.ts'; +import identity from "../utils/identity.ts"; +import unionBy from "./unionBy.ts"; export const uniq = (arr: T[]): T[] => unionBy(identity, arr); -export default uniq; \ No newline at end of file +export default uniq; diff --git a/src/array/uniqBy.ts b/src/array/uniqBy.ts index 0783a48..9e08787 100644 --- a/src/array/uniqBy.ts +++ b/src/array/uniqBy.ts @@ -1,6 +1,7 @@ import type { Iteratee } from "../types/Iteratee.d.ts"; import unionBy from "./unionBy.ts"; -export const uniqBy = (iteratee: Iteratee, ...args: T[][]) => unionBy(iteratee, ...args); +export const uniqBy = (iteratee: Iteratee, ...args: T[][]) => + unionBy(iteratee, ...args); export default uniqBy; diff --git a/src/array/uniqWith.ts b/src/array/uniqWith.ts index fd1d2a8..916870f 100644 --- a/src/array/uniqWith.ts +++ b/src/array/uniqWith.ts @@ -1,6 +1,7 @@ import type { Comparator } from "../types/Comparator.d.ts"; import unionWith from "./unionWith.ts"; -export const uniqBy = (comparator: Comparator, ...args: T[][]) => unionWith(comparator, ...args); +export const uniqBy = (comparator: Comparator, ...args: T[][]) => + unionWith(comparator, ...args); export default uniqBy; diff --git a/src/array/unzip.ts b/src/array/unzip.ts index e7921fd..16b641f 100644 --- a/src/array/unzip.ts +++ b/src/array/unzip.ts @@ -1,5 +1,5 @@ -import zip from './zip.ts'; +import zip from "./zip.ts"; -const unzip = (arrays: any[][]):any[][] => zip(...arrays); +const unzip = (arrays: any[][]): any[][] => zip(...arrays); export default unzip; diff --git a/src/array/zip.ts b/src/array/zip.ts index d35bb4b..40157a7 100644 --- a/src/array/zip.ts +++ b/src/array/zip.ts @@ -6,4 +6,4 @@ const zip = (...arrays: any[][]) => { return output; }; -export default zip; \ No newline at end of file +export default zip; diff --git a/src/collection.test.ts b/src/collection.test.ts index cd464ee..b202158 100644 --- a/src/collection.test.ts +++ b/src/collection.test.ts @@ -23,13 +23,13 @@ Rhum.testPlan("collection/*", () => { }); Rhum.asserts.assertEquals( countBy((elem: string) => elem.length, ["one", "two", "three"]), - { "3": 2, "5": 1 } + { "3": 2, "5": 1 }, ); Rhum.asserts.assertEquals( countBy(identity, ["foo", "bar", "foo", "bar", "foo", "baz"]), - { bar: 2, baz: 1, foo: 3 } + { bar: 2, baz: 1, foo: 3 }, ); - } + }, ); }); Rhum.testSuite("count()", () => { @@ -38,16 +38,16 @@ Rhum.testPlan("collection/*", () => { () => { Rhum.asserts.assertEquals( count(["foo", "bar", "foo", "bar", "foo", "baz"]), - { bar: 2, baz: 1, foo: 3 } + { bar: 2, baz: 1, foo: 3 }, ); - } + }, ); }); Rhum.testSuite("flatMapDeep()", () => { Rhum.testCase("should created a deeply flattened flatmap", () => { Rhum.asserts.assertEquals( flatMapDeep((x: number) => [[x * 2]], [1, 2, 3, 4]), - [2, 4, 6, 8] + [2, 4, 6, 8], ); }); }); @@ -60,9 +60,9 @@ Rhum.testPlan("collection/*", () => { [ [1, 1], [2, 2], - ] + ], ); - } + }, ); }); Rhum.testSuite("groupBy()", () => { @@ -84,9 +84,9 @@ Rhum.testPlan("collection/*", () => { { even: [2, 4], odd: [1, 3, 5], - } + }, ); - } + }, ); }); Rhum.testSuite("keyBy()", () => { @@ -106,13 +106,13 @@ Rhum.testPlan("collection/*", () => { { a: { dir: "left", code: 97 }, d: { dir: "right", code: 100 }, - } + }, ); Rhum.asserts.assertEquals(keyBy("dir", testArray), { left: { dir: "left", code: 97 }, right: { dir: "right", code: 100 }, }); - } + }, ); }); Rhum.testSuite("sortBy()", () => { @@ -130,29 +130,29 @@ Rhum.testPlan("collection/*", () => { sortBy( testArray, (a: TestType, b: TestType): number => a.user.localeCompare(b.user), - (a: TestType, b: TestType): number => a.age - b.age + (a: TestType, b: TestType): number => a.age - b.age, ), [ { user: "barney", age: 34 }, { user: "barney", age: 36 }, { user: "fred", age: 40 }, { user: "fred", age: 48 }, - ] + ], ); Rhum.asserts.assertEquals( sortBy( testArray, (a: TestType, b: TestType): number => a.user.localeCompare(b.user), - (a: TestType, b: TestType): number => b.age - a.age + (a: TestType, b: TestType): number => b.age - a.age, ), [ { user: "barney", age: 36 }, { user: "barney", age: 34 }, { user: "fred", age: 48 }, { user: "fred", age: 40 }, - ] + ], ); - } + }, ); }); Rhum.testSuite("sample()", () => { diff --git a/src/collection/count.ts b/src/collection/count.ts index e81806a..b33155c 100644 --- a/src/collection/count.ts +++ b/src/collection/count.ts @@ -1,8 +1,8 @@ -import identity from '../utils/identity.ts'; +import identity from "../utils/identity.ts"; import countBy from "./countBy.ts"; export const count = ( - arr: T[] + arr: T[], ): Record => countBy(identity, arr); -export default count; \ No newline at end of file +export default count; diff --git a/src/collection/countBy.ts b/src/collection/countBy.ts index 55fc124..dc2ff61 100644 --- a/src/collection/countBy.ts +++ b/src/collection/countBy.ts @@ -1,14 +1,15 @@ import type { Iteratee } from "../types/Iteratee.d.ts"; -export const countBy = (iteratee: Iteratee, - arr: T[] +export const countBy = ( + iteratee: Iteratee, + arr: T[], ): Record => { const output: Record = {}; - for(const elem of arr){ + for (const elem of arr) { const key = iteratee(elem).toString(); output[key] = output[key] === undefined ? 1 : output[key] + 1; } return output; }; -export default countBy +export default countBy; diff --git a/src/collection/flatMapDeep.ts b/src/collection/flatMapDeep.ts index b485fcd..f13078a 100644 --- a/src/collection/flatMapDeep.ts +++ b/src/collection/flatMapDeep.ts @@ -1,8 +1,7 @@ import flatMapDepth from "./flatMapDepth.ts"; import type { Iteratee } from "../types/Iteratee.d.ts"; // Array.prototype.flatMap does not have Internet Explorer 11 support. -export const flatMapDeep = (iteratee: Iteratee, - arr: T[] -): U[] => flatMapDepth(iteratee, arr, Number.MAX_SAFE_INTEGER); +export const flatMapDeep = (iteratee: Iteratee, arr: T[]): U[] => + flatMapDepth(iteratee, arr, Number.MAX_SAFE_INTEGER); export default flatMapDeep; diff --git a/src/collection/flatMapDepth.ts b/src/collection/flatMapDepth.ts index 6c5095d..48d7f71 100644 --- a/src/collection/flatMapDepth.ts +++ b/src/collection/flatMapDepth.ts @@ -5,7 +5,7 @@ import { Iteratee } from "../types/Iteratee.d.ts"; export const flatMapDepth = ( iteratee: Iteratee, arr: T[], - depth: number = Number.MAX_SAFE_INTEGER + depth: number = Number.MAX_SAFE_INTEGER, ): U[] => flattenDepth(arr.map(iteratee), depth); export default flatMapDepth; diff --git a/src/collection/groupBy.ts b/src/collection/groupBy.ts index b8a69f9..f9e9939 100644 --- a/src/collection/groupBy.ts +++ b/src/collection/groupBy.ts @@ -1,7 +1,8 @@ import type { Iteratee } from "../types/Iteratee.d.ts"; -export const groupBy = (iteratee: Iteratee, - arr: T[] +export const groupBy = ( + iteratee: Iteratee, + arr: T[], ): Record => { const output: Record> = {}; for (const elem of arr) { diff --git a/src/collection/keyBy.ts b/src/collection/keyBy.ts index fd80332..96227b2 100644 --- a/src/collection/keyBy.ts +++ b/src/collection/keyBy.ts @@ -2,10 +2,11 @@ import type { Iteratee } from "../types/Iteratee.d.ts"; export const keyBy = >( argument: Iteratee | string, - arr: T[] + arr: T[], ): Record => { - const iter = - typeof argument === "string" ? (x: T) => x[argument].toString() : argument; + const iter = typeof argument === "string" + ? (x: T) => x[argument].toString() + : argument; const output: Record = {}; for (const elem of arr) { const key = iter(elem).toString(); diff --git a/src/collection/sample.ts b/src/collection/sample.ts index ae290e1..928e854 100644 --- a/src/collection/sample.ts +++ b/src/collection/sample.ts @@ -1,17 +1,17 @@ -import randomOf from '../utils/randomOf.ts'; +import randomOf from "../utils/randomOf.ts"; export const sample = (array: T[], sampleSize: number = 1): T[] => { const clone = array.slice(); const l = array.length; let r: number; // random number; let temp: T; // storage; - for(let i = 0; i < sampleSize; i++){ + for (let i = 0; i < sampleSize; i++) { r = randomOf(l); temp = clone[r]; clone[r] = clone[i]; - clone[i] = temp; + clone[i] = temp; } return clone.slice(0, sampleSize); -} +}; -export default sample; \ No newline at end of file +export default sample; diff --git a/src/collection/shuffle.ts b/src/collection/shuffle.ts index f8e64b1..859befb 100644 --- a/src/collection/shuffle.ts +++ b/src/collection/shuffle.ts @@ -1,17 +1,17 @@ -import randomOf from '../utils/randomOf.ts'; +import randomOf from "../utils/randomOf.ts"; export const shuffle = (array: T[]): T[] => { const clone = array.slice(); const l = array.length; let r: number; // random number; let temp: T; // storage; - for(let i = 0; i < l; i++){ + for (let i = 0; i < l; i++) { r = randomOf(l); temp = clone[r]; clone[r] = clone[i]; - clone[i] = temp; + clone[i] = temp; } return clone; -} +}; -export default shuffle; \ No newline at end of file +export default shuffle; diff --git a/src/function.test.ts b/src/function.test.ts index 7c1ef2b..a77a1cf 100644 --- a/src/function.test.ts +++ b/src/function.test.ts @@ -25,7 +25,7 @@ Rhum.testPlan("function/*", async () => { logAfterThree(i); } Rhum.asserts.assertEquals(log, [2, 3, 4, 5, 6, 7, 8, 9]); - } + }, ); }); Rhum.testSuite("before()", async () => { @@ -41,7 +41,7 @@ Rhum.testPlan("function/*", async () => { logAfterThree(i); } Rhum.asserts.assertEquals(log, [2, 3, 4, 5, 6, 7, 8, 9]); - } + }, ); }); @@ -58,7 +58,7 @@ Rhum.testPlan("function/*", async () => { Rhum.asserts.assertStrictEquals( counter, 1, - "incr was called immediately" + "incr was called immediately", ); await delay(64); Rhum.asserts.assertStrictEquals(counter, 2); @@ -90,7 +90,7 @@ Rhum.testPlan("function/*", async () => { Rhum.asserts.assertStrictEquals( result, 1, - "throttled functions return their value" + "throttled functions return their value", ); Rhum.asserts.assertStrictEquals(counter, 1); }); @@ -155,7 +155,7 @@ Rhum.testPlan("function/*", async () => { await delay(96); Rhum.asserts.assertEquals(true, counter > lastCount); - } + }, ); Rhum.testCase( @@ -173,7 +173,7 @@ Rhum.testPlan("function/*", async () => { await delay(96); Rhum.asserts.assertStrictEquals(counter, 1); - } + }, ); Rhum.testCase( @@ -198,7 +198,7 @@ Rhum.testPlan("function/*", async () => { await delay(100); Rhum.asserts.assertStrictEquals(counter, 2); - } + }, ); Rhum.testCase("one more throttle with leading: false test", async () => { @@ -241,7 +241,7 @@ Rhum.testPlan("function/*", async () => { await delay(96); Rhum.asserts.assertStrictEquals(counter, 2); - } + }, ); }); Rhum.testSuite("debounce()", () => { @@ -292,7 +292,7 @@ Rhum.testPlan("function/*", async () => { Rhum.asserts.assertStrictEquals(expected, 3); expected = beforeIncr(); Rhum.asserts.assertStrictEquals(expected, 3); - } + }, ); }); Rhum.testSuite("memoize()", () => { @@ -360,7 +360,7 @@ Rhum.testPlan("function/*", async () => { }, true); await delay(50); Rhum.asserts.assertStrictEquals(deferred, true); - } + }, ); }); Rhum.testSuite("once()", () => { @@ -390,11 +390,11 @@ Rhum.testPlan("function/*", async () => { Rhum.asserts.assertEquals( overArgs((x: number, y: number) => [x, y], [square, double], 9, 3), - [81, 6] + [81, 6], ); Rhum.asserts.assertEquals( overArgs((x: number, y: number) => [x, y], [square, double], 10, 5), - [100, 10] + [100, 10], ); }); }); diff --git a/src/function/after.ts b/src/function/after.ts index 358eadc..38c28f8 100644 --- a/src/function/after.ts +++ b/src/function/after.ts @@ -1,11 +1,11 @@ export const after = (n: number, fn: Function) => { let count = 1; return (...args: any[]): void | any => { - if(count >= n){ + if (count >= n) { return fn(...args); } count += 1; - } -} + }; +}; -export default after; \ No newline at end of file +export default after; diff --git a/src/function/defer.ts b/src/function/defer.ts index 10b6fa9..bcb0d66 100644 --- a/src/function/defer.ts +++ b/src/function/defer.ts @@ -1,5 +1,5 @@ -export const defer = (fn: Function, ...args: any[]):void => { +export const defer = (fn: Function, ...args: any[]): void => { setTimeout(() => fn(...args), 0); -} +}; -export default defer; \ No newline at end of file +export default defer; diff --git a/src/function/memoize.ts b/src/function/memoize.ts index 4ecb15a..02affc2 100644 --- a/src/function/memoize.ts +++ b/src/function/memoize.ts @@ -5,7 +5,7 @@ const normalHashingFunction: HashingFunction = (args: any[]): string => export const memoize = ( fn: Function, - hashingFn: HashingFunction = normalHashingFunction + hashingFn: HashingFunction = normalHashingFunction, ) => { const cache: Record = {}; return (...args: any[]) => { @@ -16,4 +16,4 @@ export const memoize = ( }; }; -export default memoize; \ No newline at end of file +export default memoize; diff --git a/src/function/once.ts b/src/function/once.ts index 56408be..9305900 100644 --- a/src/function/once.ts +++ b/src/function/once.ts @@ -1,5 +1,5 @@ -import before from './before.ts'; +import before from "./before.ts"; -export const once = (fn: Function) => before(1, fn); +export const once = (fn: Function) => before(1, fn); -export default once; \ No newline at end of file +export default once; diff --git a/src/function/overArgs.ts b/src/function/overArgs.ts index c40c9af..fa187f2 100644 --- a/src/function/overArgs.ts +++ b/src/function/overArgs.ts @@ -2,7 +2,7 @@ export const overArgs = (fn: Function, mapFuncs: Function[], ...args: any[]) => fn( ...args.map((arg: any, i: number) => mapFuncs[i] === undefined ? arg : mapFuncs[i](arg) - ) + ), ); export default overArgs; diff --git a/src/function/throttle.ts b/src/function/throttle.ts index 661f79d..dfa117c 100644 --- a/src/function/throttle.ts +++ b/src/function/throttle.ts @@ -6,7 +6,7 @@ interface ThrottleOptions { export const throttle = ( func: Function, wait = 0, - options: ThrottleOptions = { leading: true, trailing: true } + options: ThrottleOptions = { leading: true, trailing: true }, ) => { let timeout: ReturnType; let result: any; @@ -17,16 +17,16 @@ export const throttle = ( previous = options.leading === false ? 0 : Date.now(); timeout = 0; result = func(...args); - if(!timeout){ + if (!timeout) { args = []; } }; const throttled = (...currentArgs: any[]) => { const now = Date.now(); - if (!previous && options.leading === false){ + if (!previous && options.leading === false) { previous = now; - } + } let remaining = wait - (now - previous); args = currentArgs; if (remaining <= 0 || remaining > wait) { @@ -37,7 +37,7 @@ export const throttle = ( previous = now; result = func(...currentArgs); if (!timeout) { - args = []; + args = []; } } else if (!timeout && options.trailing !== false) { timeout = setTimeout(later, remaining); @@ -55,5 +55,4 @@ export const throttle = ( return throttled; }; - -export default throttle; \ No newline at end of file +export default throttle; diff --git a/src/lang.test.ts b/src/lang.test.ts index 5d302a7..f2e584d 100644 --- a/src/lang.test.ts +++ b/src/lang.test.ts @@ -124,7 +124,7 @@ Rhum.testPlan("lang/*", () => { Rhum.asserts.assertStrictEquals(isEqual(obj1, obj2), false); - obj2 = {...obj1, 'newPropThatDoesntExistOnObj1': 'sf'} + obj2 = { ...obj1, "newPropThatDoesntExistOnObj1": "sf" }; Rhum.asserts.assertStrictEquals(isEqual(obj1, obj2), false); }); diff --git a/src/lang/cloneDeep.ts b/src/lang/cloneDeep.ts index ff8d82a..a08f7c4 100644 --- a/src/lang/cloneDeep.ts +++ b/src/lang/cloneDeep.ts @@ -26,7 +26,7 @@ const cloneDeep = (value: any): any => { } return clone; } - throw new Error(`You've tried to clone something that can't be cloned`) + throw new Error(`You've tried to clone something that can't be cloned`); }; -export default cloneDeep; \ No newline at end of file +export default cloneDeep; diff --git a/src/lang/isEqual.ts b/src/lang/isEqual.ts index 02003b6..49b1af7 100644 --- a/src/lang/isEqual.ts +++ b/src/lang/isEqual.ts @@ -10,7 +10,7 @@ const isEqual: Comparator = (a, b) => { if (Number.isNaN(a)) { return Number.isNaN(b); } - + // primatives if ( [ @@ -40,7 +40,7 @@ const isEqual: Comparator = (a, b) => { } // objects if (typeA === "object") { - if(a === null){ + if (a === null) { return b === null; } const aEntries = Object.entries(a); @@ -48,7 +48,7 @@ const isEqual: Comparator = (a, b) => { return isEqual(aEntries, bEntries); } throw new Error( - `You've tried running isEqual on something isEqual isn't meant for` + `You've tried running isEqual on something isEqual isn't meant for`, ); }; diff --git a/src/object.test.ts b/src/object.test.ts index 2f4d650..c25b58c 100644 --- a/src/object.test.ts +++ b/src/object.test.ts @@ -5,7 +5,7 @@ import invert from "./object/invert.ts"; import findKeys from "./object/findKeys.ts"; import get from "./object/get.ts"; import pick from "./object/pick.ts"; -import omit from './object/omit.ts'; +import omit from "./object/omit.ts"; Rhum.testPlan("object/*", () => { Rhum.testSuite("mapObject()", () => { @@ -15,8 +15,9 @@ Rhum.testPlan("object/*", () => { two: 2, three: 3, }; - const returned = mapObject(testObj, (n: number): string => - (n * n * 100).toString() + const returned = mapObject( + testObj, + (n: number): string => (n * n * 100).toString(), ); Rhum.asserts.assertEquals(returned, { one: "100", @@ -29,7 +30,7 @@ Rhum.testPlan("object/*", () => { Rhum.testCase("should invert an objects keys and values", () => { Rhum.asserts.assertEquals( invert({ Moe: "Moses", Larry: "Louis", Curly: "Jerome" }), - { Moses: "Moe", Louis: "Larry", Jerome: "Curly" } + { Moses: "Moe", Louis: "Larry", Jerome: "Curly" }, ); }); }); @@ -37,11 +38,11 @@ Rhum.testPlan("object/*", () => { Rhum.testCase("should find all keys where the value holds true", () => { Rhum.asserts.assertEquals( findKeys({ a: 1, b: 2, c: 3 }, (x: number) => x % 2 === 1), - ["a", "c"] + ["a", "c"], ); Rhum.asserts.assertEquals( findKeys({ c: 1, b: 2, a: 3 }, (x: number) => x % 2 === 1), - ["a", "c"] + ["a", "c"], ); }); }); @@ -59,7 +60,7 @@ Rhum.testPlan("object/*", () => { Rhum.testCase("should get objects by a path", () => { Rhum.asserts.assertStrictEquals( get(testObj, ["a", "c", "e", 2, "baz"], "nope"), - "quux" + "quux", ); }); Rhum.testCase("should return whole objects", () => { @@ -71,11 +72,11 @@ Rhum.testPlan("object/*", () => { Rhum.testCase("should a default if path does not exist", () => { Rhum.asserts.assertStrictEquals( get(testObj, ["a", "q", "c"], "nope"), - "nope" + "nope", ); Rhum.asserts.assertStrictEquals( get(testObj, ["a", "b", "c"], "nope"), - "nope" + "nope", ); }); Rhum.testCase("should work with strings", () => { @@ -88,7 +89,7 @@ Rhum.testPlan("object/*", () => { Rhum.testCase("should work with a mix of arrays and strings", () => { Rhum.asserts.assertStrictEquals( get(testObj, ["a.c", "e", 2, "baz"], "nope"), - "quux" + "quux", ); }); }); diff --git a/src/object/findKeys.ts b/src/object/findKeys.ts index fb45b9d..2fea4eb 100644 --- a/src/object/findKeys.ts +++ b/src/object/findKeys.ts @@ -1,13 +1,16 @@ -import type {Predicate} from '../types/Predicate.d.ts' +import type { Predicate } from "../types/Predicate.d.ts"; -export const findKeys = (obj: Record, predicate: Predicate): string[] => { +export const findKeys = ( + obj: Record, + predicate: Predicate, +): string[] => { let output: string[] = []; - for(let key in obj){ - if(predicate(obj[key])){ - output.push(key) + for (let key in obj) { + if (predicate(obj[key])) { + output.push(key); } } return output.sort(); -} +}; -export default findKeys; \ No newline at end of file +export default findKeys; diff --git a/src/object/get.ts b/src/object/get.ts index d39907b..d24bc52 100644 --- a/src/object/get.ts +++ b/src/object/get.ts @@ -2,7 +2,7 @@ import type { ValueOrArray } from "../types/ValueOrArray.d.ts"; const simpleGet = ( obj: Record | undefined, - path: Array + path: Array, ): any => { let cursor = obj; @@ -16,7 +16,7 @@ const simpleGet = ( }; const parsePath = ( - path: ValueOrArray | string + path: ValueOrArray | string, ): Array => { if (typeof path === "string") { path = path.split(".") as ValueOrArray; @@ -41,7 +41,7 @@ const parsePath = ( export const get = ( obj: Record, path: string | Array, - retValueIfUndef?: any + retValueIfUndef?: any, ): any => { const result: any = simpleGet(obj, parsePath(path)); if (result === undefined) { diff --git a/src/object/invert.ts b/src/object/invert.ts index 5c7e70d..c3efcf3 100644 --- a/src/object/invert.ts +++ b/src/object/invert.ts @@ -19,12 +19,14 @@ export const invert = (obj: Record) => Object.entries(obj).reduce( (pv: Record, [k, v]: [string, any]) => ({ ...pv, - [stringifyKey( - v, - `Value of property ${k} is not serializable to string` - )]: k, + [ + stringifyKey( + v, + `Value of property ${k} is not serializable to string`, + ) + ]: k, }), - {} + {}, ); export default invert; diff --git a/src/object/mapObject.ts b/src/object/mapObject.ts index 20a0e61..c7c83ea 100644 --- a/src/object/mapObject.ts +++ b/src/object/mapObject.ts @@ -3,14 +3,14 @@ import type { Transformer } from "../types/Transformer.d.ts"; export const mapObject = ( obj: Record, - fn: Transformer + fn: Transformer, ) => Object.entries(obj).reduce( (pv: Record, [k, v]: [ObjectKey, T]) => ({ ...pv, [k]: fn(v), }), - {} + {}, ); export default mapObject; diff --git a/src/object/omit.ts b/src/object/omit.ts index 7b25bfd..4928efd 100644 --- a/src/object/omit.ts +++ b/src/object/omit.ts @@ -2,10 +2,10 @@ import pick from "./pick.ts"; export const omit = ( obj: Record, - props: Array + props: Array, ): Record => { const getProps = Object.keys(obj).filter( - (p: string | number) => !props.includes(p) + (p: string | number) => !props.includes(p), ); return pick(obj, getProps); }; diff --git a/src/object/pick.ts b/src/object/pick.ts index 2a1fd9c..1f90785 100644 --- a/src/object/pick.ts +++ b/src/object/pick.ts @@ -1,11 +1,14 @@ -export const pick = (obj: Record, props: Array): Record => { - const newObj: Record = {}; - for(let prop of props){ - if(obj[prop] !== undefined){ - newObj[prop] = obj[prop] +export const pick = ( + obj: Record, + props: Array, +): Record => { + const newObj: Record = {}; + for (let prop of props) { + if (obj[prop] !== undefined) { + newObj[prop] = obj[prop]; } } return newObj; -} +}; -export default pick; \ No newline at end of file +export default pick; diff --git a/src/types/Comparator.d.ts b/src/types/Comparator.d.ts index ccb9996..7dabbe0 100644 --- a/src/types/Comparator.d.ts +++ b/src/types/Comparator.d.ts @@ -1 +1 @@ -export type Comparator = (a1: T, b1: T) => boolean; \ No newline at end of file +export type Comparator = (a1: T, b1: T) => boolean; diff --git a/src/types/Predicate.d.ts b/src/types/Predicate.d.ts index 4f30ab5..2e381e5 100644 --- a/src/types/Predicate.d.ts +++ b/src/types/Predicate.d.ts @@ -1 +1 @@ -export type Predicate = (x: T) => boolean; \ No newline at end of file +export type Predicate = (x: T) => boolean; diff --git a/src/types/SortComparator.d.ts b/src/types/SortComparator.d.ts index 63f414d..b15a307 100644 --- a/src/types/SortComparator.d.ts +++ b/src/types/SortComparator.d.ts @@ -1 +1 @@ -export type SortComparator = (a1: T, b1: T) => number; \ No newline at end of file +export type SortComparator = (a1: T, b1: T) => number; diff --git a/src/types/ValueOrArray.d.ts b/src/types/ValueOrArray.d.ts index e097fb2..f6ef2ed 100644 --- a/src/types/ValueOrArray.d.ts +++ b/src/types/ValueOrArray.d.ts @@ -1 +1 @@ -export type ValueOrArray = T | Array>; \ No newline at end of file +export type ValueOrArray = T | Array>; diff --git a/src/utils.test.ts b/src/utils.test.ts index db2189e..baa53b0 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -25,8 +25,8 @@ Rhum.testPlan("utils/*", () => { testArr.sort( comparatorChain( (a: NameAge, b: NameAge) => a.age - b.age, - (a: NameAge, b: NameAge) => a.name.localeCompare(b.name) - ) + (a: NameAge, b: NameAge) => a.name.localeCompare(b.name), + ), ), [ { @@ -41,7 +41,7 @@ Rhum.testPlan("utils/*", () => { age: 25, name: "carl", }, - ] + ], ); }); }); diff --git a/src/utils/TODO.md b/src/utils/TODO.md index 4cf61ef..055ef4d 100644 --- a/src/utils/TODO.md +++ b/src/utils/TODO.md @@ -2,5 +2,5 @@ ## TODO -* range() -* uniqueId() \ No newline at end of file +- range() +- uniqueId() diff --git a/src/utils/comparatorChain.ts b/src/utils/comparatorChain.ts index ed22a21..5b72220 100644 --- a/src/utils/comparatorChain.ts +++ b/src/utils/comparatorChain.ts @@ -1,18 +1,19 @@ import type { SortComparator } from "../types/SortComparator.d.ts"; -export const comparatorChain = (...comparators: SortComparator[]) => ( - a: T, - b: T -) => { - const l = comparators.length; - let depth = 0; - let result = 0; +export const comparatorChain = (...comparators: SortComparator[]) => + ( + a: T, + b: T, + ) => { + const l = comparators.length; + let depth = 0; + let result = 0; - while (result === 0 && depth < l) { - result = comparators[depth](a, b); - depth += 1; - } - return result; -}; + while (result === 0 && depth < l) { + result = comparators[depth](a, b); + depth += 1; + } + return result; + }; -export default comparatorChain; \ No newline at end of file +export default comparatorChain; diff --git a/src/utils/delay.ts b/src/utils/delay.ts index 679c838..1dddbdb 100644 --- a/src/utils/delay.ts +++ b/src/utils/delay.ts @@ -5,4 +5,4 @@ export const delay = (time: number, fn?: Function, ...args: any[]) => }, time); }); -export default delay; \ No newline at end of file +export default delay; diff --git a/src/utils/identity.ts b/src/utils/identity.ts index 3952f13..e6dc599 100644 --- a/src/utils/identity.ts +++ b/src/utils/identity.ts @@ -1,3 +1,3 @@ -export const identity = (x: T): T => x; +export const identity = (x: T): T => x; -export default identity; \ No newline at end of file +export default identity; diff --git a/src/utils/randomOf.ts b/src/utils/randomOf.ts index 4bd1633..ecc3fed 100644 --- a/src/utils/randomOf.ts +++ b/src/utils/randomOf.ts @@ -1,3 +1,4 @@ -export const randomOf = (max: number): number => Math.floor((Math.random() * max)); +export const randomOf = (max: number): number => + Math.floor((Math.random() * max)); export default randomOf; diff --git a/testing_deps.ts b/testing_deps.ts index 7fc3f56..272e23e 100644 --- a/testing_deps.ts +++ b/testing_deps.ts @@ -1 +1 @@ -export { Rhum } from "https://deno.land/x/rhum@v1.1.7/mod.ts"; \ No newline at end of file +export { Rhum } from "https://deno.land/x/rhum@v1.1.7/mod.ts";