-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from chuvikovd/typescript
Typescript
- Loading branch information
Showing
13 changed files
with
176 additions
and
771 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ version: 2.1 | |
orbs: | ||
node: circleci/[email protected] | ||
jobs: | ||
build-and-test: | ||
test-and-build: | ||
executor: | ||
name: node/default | ||
steps: | ||
|
@@ -11,7 +11,8 @@ jobs: | |
steps: | ||
- run: yarn | ||
- run: yarn test | ||
- run: yarn build | ||
workflows: | ||
build-and-test: | ||
jobs: | ||
- build-and-test | ||
test-and-build: | ||
jobs: | ||
- test-and-build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
coverage | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!dist/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## 2.0.0 (March 27, 2020) | ||
|
||
* Rewritten with typescript | ||
|
||
### Breaking changes | ||
|
||
* Syntax for sort array changed from `['column-order']` to `[['column', 'order']]`. `order` now must be uppercased. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
type SortArray<T> = [keyof T, 'ASC' | 'DESC'][] | ||
type GetColumnValue<T> = (column: keyof T, value: T[keyof T]) => any | ||
|
||
const sort = <T>( | ||
a: T, | ||
b: T, | ||
columns: SortArray<T>, | ||
getColumnValue?: GetColumnValue<T> | ||
): -1 | 0 | 1 => { | ||
const [item, ...others] = columns | ||
const [column, orderBy] = item | ||
const valueA = getColumnValue ? getColumnValue(column, a[column]) : a[column] | ||
const valueB = getColumnValue ? getColumnValue(column, b[column]) : b[column] | ||
|
||
if (orderBy === 'ASC') { | ||
if (valueA > valueB) return 1 | ||
if (valueA < valueB) return -1 | ||
if (others.length) return sort(a, b, others, getColumnValue) | ||
return 0 | ||
} else { | ||
if (valueB > valueA) return 1 | ||
if (valueB < valueA) return -1 | ||
if (others.length) return sort(a, b, others, getColumnValue) | ||
return 0 | ||
} | ||
} | ||
|
||
const multiColumnSort = <T>( | ||
arr: T[], | ||
sortArr: [keyof T, 'ASC' | 'DESC'][], | ||
getColumnValue?: GetColumnValue<T> | ||
): T[] => [...arr].sort((a, b) => sort(a, b, sortArr, getColumnValue)) | ||
|
||
export default multiColumnSort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
module.exports = { | ||
transform: { | ||
'^.+\\.js$': 'babel-jest' | ||
} | ||
preset: 'ts-jest', | ||
testEnvironment: 'node' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"outDir": "dist", | ||
"declaration": true, | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"resolveJsonModule": true | ||
}, | ||
"include": ["index.ts"] | ||
} |
Oops, something went wrong.