Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
11f6d3b
Remove domain-specific modules
przemyslawzalewski Dec 12, 2019
231ecfe
Add typings and tests for array module
przemyslawzalewski Dec 12, 2019
87115b6
Always regenerate markdown docs from json
przemyslawzalewski Dec 12, 2019
2a3040c
Regenerate docs
przemyslawzalewski Dec 12, 2019
605407b
Add typings and tests for async module
przemyslawzalewski Dec 12, 2019
59d178d
Regenerate async module docs
przemyslawzalewski Dec 12, 2019
cc6d407
Regenerate code
przemyslawzalewski Dec 12, 2019
eeaea0b
Refactor base64url module
przemyslawzalewski Dec 12, 2019
df2fa92
Restructure base64URL module and cover it with tests
przemyslawzalewski Dec 13, 2019
fee2c3f
Regenerate code and documentation
przemyslawzalewski Dec 13, 2019
eb768de
Add typings and tests for math module
przemyslawzalewski Dec 13, 2019
0346e2e
Regenerate math module docs
przemyslawzalewski Dec 13, 2019
a20ad09
Add typings and tests for the string module
przemyslawzalewski Dec 13, 2019
763eab8
Regenerated string module docs
przemyslawzalewski Dec 13, 2019
9af383f
Add typings and tests for web module
przemyslawzalewski Dec 13, 2019
48db792
Regenerate web module docs
przemyslawzalewski Dec 13, 2019
afaa95a
Add regex escape typings and tests
przemyslawzalewski Dec 13, 2019
ffd0d3a
Delete complex and mostly not needed parsePathname function
przemyslawzalewski Dec 13, 2019
e9403f4
Add typings and tests for query module
przemyslawzalewski Dec 13, 2019
3d7e6bc
Regenerate code and documentation
przemyslawzalewski Dec 13, 2019
1352c32
Fix serialize true value encoding
przemyslawzalewski Dec 13, 2019
4b3920e
Add typings and tests for file module
przemyslawzalewski Dec 13, 2019
4af4bb7
Regenerate docs and code
przemyslawzalewski Dec 13, 2019
50eb59d
Add base tests for diff function
przemyslawzalewski Dec 13, 2019
8453d8e
Do not treat infinities as valid numbers
przemyslawzalewski Dec 13, 2019
f95809b
Add typings and tests for assert module
przemyslawzalewski Dec 13, 2019
13bac75
Regenerate code and docs
przemyslawzalewski Dec 13, 2019
3182ea0
Add typings and tests for function module
przemyslawzalewski Dec 13, 2019
1f3740e
Regenerate docs
przemyslawzalewski Dec 13, 2019
6c25017
Fix byt->but typo
przemyslawzalewski Dec 13, 2019
f1713e0
Add typings and tests for vector2 module
przemyslawzalewski Dec 13, 2019
b93cf29
Regenerate vector2 docs
przemyslawzalewski Dec 13, 2019
2884561
Cover vector2 module
przemyslawzalewski Dec 13, 2019
4c0aae4
Regenerate docs and code
przemyslawzalewski Dec 13, 2019
97cd24c
Cover default values of vector2 module
przemyslawzalewski Dec 13, 2019
dc93535
Regenerate code
przemyslawzalewski Dec 13, 2019
8715f00
Reference Array.reverse instead of Array.sort
przemyslawzalewski Dec 13, 2019
285ebfe
Add empty arrays equality test
przemyslawzalewski Dec 13, 2019
4e1aa8c
Remove leftov er test case
przemyslawzalewski Dec 13, 2019
4cc504a
Add UTF-8 file name test case
przemyslawzalewski Dec 13, 2019
92eb3b9
Remove non-meaningful postfixes
przemyslawzalewski Dec 13, 2019
cfa0beb
Regenerate docs
przemyslawzalewski Dec 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
214 changes: 208 additions & 6 deletions README.md

Large diffs are not rendered by default.

76 changes: 72 additions & 4 deletions array/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# any

Checks if the given array is not empty (contains at least one element).
Checks if the given array is present and it is not empty (contains at least one element).

## Type signature

```
(xs: any[]) => boolean
(xs?: any[]) => boolean
```

## Examples
Expand Down Expand Up @@ -39,78 +39,146 @@ Checks if given arguments are all `Arrays`.

# differs

Checks if two arrays are not equal.

# duplicates

Lists all the duplicated values in the given array.

# empty

Empty array.

# exact

Takes exactly the given count of elements.

# except

Filters out the given value.

# filterInPlace

Filters the given array with the given predicate just like Array.filter but does it in-place thus mutates the original array.

# find

Finds an element by a predicate function within given array, otherwise returns the given fallback value or undefined when fallback is not present.

# first

Returns the first element or undefined when there are no elements in the given array.

# flatMap

Maps and flattens the result.

# flatten

Flattens the nested arrays by a single level.

# intersection

Finds common items between both arrays.

# is

# last

Returns the last element or undefined when there are no elements in the given array.

# lengthDiffers

Checks if lengths of given arrays differ.

# map

Maps the given array with the given functions.

# midpoint

Returns the middle element or the right one when the number of elements is even.

# minMax

Computes minimum and maximum of the given array in a single run.

# multiple

Checks if the given array contains more than one element.

# none

Checks if the given array is empty.

# partition

Partitions the given array to the ones that pass the given predicate function and the ones that do not. By [convention of the Haskell's Data.Either](http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-Either.html), values that pass the predicate are placed at right.

# range

Generates an array of numbers from 0 to n - 1.

# repeat

Repeats the given element by given count of times.

# reverse

Reverses the given array without mutating it (in contrast to Array.reverse).

# reverseIf

# rotate
Reverses the given array when enabled.

# second

Returns the second element or undefined when there are less than two elements in the given array.

# secondToLast

Returns the second to last element or undefined when there are less than two elements in the given array.

# shift

Shifts the given array to the left and circulates the elements back by modulo of the array's length.

# shuffle

Shuffles the given array in random order with Math.random as the default.

# shuffleInPlace

Shuffles the given array in-place in random order with Math.random as the default.

# single

Checks if the given array contains exactly one element.

# skip

Skips the given count of elements from the given array.

# sort

Sorts the given array without mutating it.

# sum

Sums the given array of numbers.

# take

# transpose
Takes up to given count of elements.

# unique

Returns only unique elements of the given array.

# zip

Zips given arrays together into pairs.

# zipWith

Zips given arrays together with the given function.
4 changes: 2 additions & 2 deletions array/any.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "any",
"description": "Checks if the given array is not empty (contains at least one element).",
"signature": "(xs: any[]) => boolean",
"description": "Checks if the given array is present and it is not empty (contains at least one element).",
"signature": "(xs?: any[]) => boolean",
"examples": [
{
"language": "javascript",
Expand Down
4 changes: 2 additions & 2 deletions array/any.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# any

Checks if the given array is not empty (contains at least one element).
Checks if the given array is present and it is not empty (contains at least one element).

## Type signature

```
(xs: any[]) => boolean
(xs?: any[]) => boolean
```

## Examples
Expand Down
3 changes: 2 additions & 1 deletion array/any.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ describe("any", () => {
expect(any([])).toBe(false);
});

it("returns false if the given argument is falsy", () => {
it("returns false if the given array is missing or the argument is falsy", () => {
expect(any()).toBe(false);
expect(any(null)).toBe(false);
expect(any(undefined)).toBe(false);
});
Expand Down
2 changes: 1 addition & 1 deletion array/any.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default (xs: any[]): boolean => (xs ? xs.length > 0 : false);
export default (xs?: any[]): boolean => (xs ? xs.length > 0 : false);
4 changes: 2 additions & 2 deletions array/difference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import difference from "./difference.ts";

describe("difference", () => {
it.skip("TODO", () => {
expect(difference()).toBeDefined();
it("skips all the elements present in the second array and keeps the rest", () => {
expect(difference([1, 2, 3, 4, 5, 6], [2, 4])).toEqual([1, 3, 5, 6]);
});
});
2 changes: 1 addition & 1 deletion array/difference.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default (xs, ys) => {
export default (xs: any[], ys: any[]) => {
const zs = new Set(ys);

return xs.filter(x => !zs.has(x));
Expand Down
4 changes: 2 additions & 2 deletions array/differs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default (xs, ys) =>
(!xs && ys) ||
(!ys && xs) ||
Boolean(!xs && ys) ||
Boolean(!ys && xs) ||
xs.length !== ys.length ||
xs.some((x, index) => x !== ys[index]);
2 changes: 1 addition & 1 deletion array/differs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "differs",
"description": "TODO: Fill short description here.",
"description": "Checks if two arrays are not equal.",
"signature": "TODO: Fill type signature here.",
"examples": [
{
Expand Down
2 changes: 2 additions & 0 deletions array/differs.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# differs

Checks if two arrays are not equal.
19 changes: 17 additions & 2 deletions array/differs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
import differs from "./differs.ts";

describe("differs", () => {
it.skip("TODO", () => {
expect(differs()).toBeDefined();
it("short-circuits over length differences", () => {
expect(differs([1, 2, 3], [1, 2])).toBe(true);
expect(differs([2, 3], [1, 2, 5])).toBe(true);
});

it("short-circuits over parameter presence", () => {
expect(differs(null, [1, 2])).toBe(true);
expect(differs([2, 3], undefined)).toBe(true);
});

it("compares elements index-wise", () => {
expect(differs([1, 2, 3], [1, 2, 3])).toBe(false);
expect(differs([1, 2, 3], [1, 67, 3])).toBe(true);
});

it("assumes empty arrays equal", () => {
expect(differs([], [])).toBe(false);
});
});
6 changes: 3 additions & 3 deletions array/differs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default (xs, ys) =>
(!xs && ys) ||
(!ys && xs) ||
export default (xs?: any[], ys?: any[]) =>
Boolean(!xs && ys) ||
Boolean(!ys && xs) ||
xs.length !== ys.length ||
xs.some((x, index) => x !== ys[index]);
2 changes: 1 addition & 1 deletion array/duplicates.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "duplicates",
"description": "TODO: Fill short description here.",
"description": "Lists all the duplicated values in the given array.",
"signature": "TODO: Fill type signature here.",
"examples": [
{
Expand Down
2 changes: 2 additions & 0 deletions array/duplicates.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# duplicates

Lists all the duplicated values in the given array.
12 changes: 10 additions & 2 deletions array/duplicates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
import duplicates from "./duplicates.ts";

describe("duplicates", () => {
it.skip("TODO", () => {
expect(duplicates()).toBeDefined();
it("returns duplicated values", () => {
expect(duplicates([1, 2, 3, 4, 3, 5, 6, 7])).toEqual([3]);
});

it("returns all the duplicated values when there are any", () => {
expect(duplicates([1, 2, 3, 4, 3, 4, 3, 6])).toEqual([3, 4, 3]);
});

it("return an empty array when there are no duplicated", () => {
expect(duplicates([1, 2, 3, 4, 5, 6, 7, 8])).toEqual([]);
});
});
2 changes: 1 addition & 1 deletion array/duplicates.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export default xs =>
export default (xs: any[]) =>
xs.filter((value, index, self) => self.indexOf(value) !== index);
2 changes: 1 addition & 1 deletion array/empty.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "empty",
"description": "TODO: Fill short description here.",
"description": "Empty array.",
"signature": "TODO: Fill type signature here.",
"examples": [
{
Expand Down
2 changes: 2 additions & 0 deletions array/empty.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# empty

Empty array.
8 changes: 6 additions & 2 deletions array/empty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import empty from "./empty.ts";

describe("empty", () => {
it.skip("TODO", () => {
expect(empty()).toBeDefined();
it("equals to the empty array", () => {
expect(empty).toEqual([]);
});

it("keeps the same reference", () => {
expect(empty).not.toBe([]);
});
});
2 changes: 1 addition & 1 deletion array/exact.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import range from "./range.js";

export default n => xs => range(n).map(index => xs[index]);
export default count => xs => range(count).map(index => xs[index]);
2 changes: 1 addition & 1 deletion array/exact.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "exact",
"description": "TODO: Fill short description here.",
"description": "Takes exactly the given count of elements.",
"signature": "TODO: Fill type signature here.",
"examples": [
{
Expand Down
2 changes: 2 additions & 0 deletions array/exact.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# exact

Takes exactly the given count of elements.
4 changes: 2 additions & 2 deletions array/exact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import exact from "./exact.ts";

describe("exact", () => {
it.skip("TODO", () => {
expect(exact()).toBeDefined();
it("takes exactly the given count of items and fills blanks with undefined values", () => {
expect(exact(5)([1, 2, 3])).toEqual([1, 2, 3, undefined, undefined]);
});
});
3 changes: 2 additions & 1 deletion array/exact.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import range from "./range";

export default n => xs => range(n).map(index => xs[index]);
export default (count: number) => (xs: any[]) =>
range(count).map(index => xs[index]);
2 changes: 1 addition & 1 deletion array/except.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "except",
"description": "TODO: Fill short description here.",
"description": "Filters out the given value.",
"signature": "TODO: Fill type signature here.",
"examples": [
{
Expand Down
2 changes: 2 additions & 0 deletions array/except.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# except

Filters out the given value.
8 changes: 6 additions & 2 deletions array/except.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import except from "./except.ts";

describe("except", () => {
it.skip("TODO", () => {
expect(except()).toBeDefined();
it("filters out the given value", () => {
expect(except(2)([1, 2, 3, 4, 5])).toEqual([1, 3, 4, 5]);
});

it("filters out multiple occurrences of the given value", () => {
expect(except(2)([1, 2, 2, 4, 2])).toEqual([1, 4]);
});
});
2 changes: 1 addition & 1 deletion array/except.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default y => xs => xs.filter(x => x !== y);
export default (y: any) => (xs: any[]) => xs.filter(x => x !== y);
2 changes: 1 addition & 1 deletion array/filterInPlace.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filterInPlace",
"description": "TODO: Fill short description here.",
"description": "Filters the given array with the given predicate just like Array.filter but does it in-place thus mutates the original array.",
"signature": "TODO: Fill type signature here.",
"examples": [
{
Expand Down
Loading