Skip to content

Commit

Permalink
refactor: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crimx committed Oct 17, 2023
1 parent e226fb8 commit 92ea9bd
Show file tree
Hide file tree
Showing 9 changed files with 1,463 additions and 182 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"scripts": {
"prepublishOnly": "pnpm run build && echo 'Run the npm publish command inside `dist`.' && exit 1",
"build": "rimraf dist && tsc && node ./scripts/package.js",
"test": "vitest",
"lint": "eslint --ext .ts,.tsx,.js,.mjs . && prettier --check .",
"lint:fix": "eslint --ext .ts,.tsx,.js,.mjs . --fix && prettier -w ."
},
Expand All @@ -32,7 +33,7 @@
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"@vitest/coverage-c8": "^0.33.0",
"@vitest/coverage-v8": "^0.34.1",
"eslint": "^8.47.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-import": "^2.27.5",
Expand Down
115 changes: 31 additions & 84 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const lastIndex = <T>(
*
* @param arr - An array
* @param predicate - A predicate function.
* @param thisArg - If provided, it will be used as the this value for each invocation of predicate. If it is not provided, `undefined` is used instead.
* @param thisArg - If provided, it will be used as the this value for each invocation of predicate. If it is not provided, the first element is returned.
* @returns The first item that matches the predicate, or `None` if no item matches.
*/
export const first = <T>(
Expand All @@ -131,14 +131,14 @@ export const first = <T>(
*
* @param arr - An array
* @param predicate - A predicate function.
* @param thisArg - If provided, it will be used as the this value for each invocation of predicate. If it is not provided, `undefined` is used instead.
* @param thisArg - If provided, it will be used as the this value for each invocation of predicate. If it is not provided, the last element is returned.
* @returns The last item that matches the predicate, or `None` if no item matches.
*/
export const last = <T>(
arr: T[],
predicate: (value: T, index: number, array: T[]) => boolean = truePredicate,
thisArg?: any
): Option<T> => lastIndex(arr, predicate, thisArg).map(valueAtIndex, this);
): Option<T> => lastIndex(arr, predicate, thisArg).map(valueAtIndex, arr);

/**
* Applies function to the elements of iterator and returns the first non-none result.
Expand Down
Loading

0 comments on commit 92ea9bd

Please sign in to comment.