Skip to content

Commit

Permalink
refactor: migrate codebase to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
yobacca committed Nov 13, 2022
1 parent c75472a commit c2199b0
Show file tree
Hide file tree
Showing 145 changed files with 6,297 additions and 15,043 deletions.
1 change: 0 additions & 1 deletion .browserlistrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ie >= 11
last 1 Edge version
last 1 Firefox version
last 1 Chrome version
Expand Down
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@2.2.0/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
9 changes: 0 additions & 9 deletions .editorconfig

This file was deleted.

2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
flow-typed/**/*.js
dist/
lib/
docs/
106 changes: 69 additions & 37 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,75 @@
{
"parser": "babel-eslint",
"extends": ["airbnb-base", "prettier"],
"plugins": ["flowtype"],
"parser": "@typescript-eslint/parser",
"extends": [
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:node/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript"
],
"plugins": ["import"],
"settings": {
"node": {
"tryExtensions": [".json", ".node", ".ts"]
}
},
"rules": {
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"arrow-parens": 0,
"flowtype/boolean-style": [2, "boolean"],
"flowtype/define-flow-type": 1,
"flowtype/no-dupe-keys": 2,
"flowtype/object-type-delimiter": 2,
"flowtype/require-valid-file-annotation": [
2,
"always",
{ "annotationStyle": "line" }
"import/order": [
1,
{
"groups": [
["builtin", "external"],
"internal",
["sibling", "parent", "index"]
],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
],
"flowtype/space-before-type-colon": [2, "never"],
"flowtype/space-after-type-colon": [2, "always"],
"flowtype/union-intersection-spacing": [2, "always"],
"import/no-extraneous-dependencies": 0,
"no-control-regex": 0,
"no-confusing-arrow": 0,
"no-duplicate-imports": 0,
"no-else-return": 0,
"no-param-reassign": ["error", { "props": false }],
"no-prototype-builtins": 0,
"no-restricted-syntax": 0,
"no-unused-vars": [2, { "varsIgnorePattern": "^_+$" }],
"symbol-description": 0
},
"env": {
"browser": true,
"jest": true,
"node": true
"@typescript-eslint/consistent-type-assertions": [
"warn",
{
"assertionStyle": "never"
}
],
"@typescript-eslint/explicit-function-return-type": [
"error",
{
"allowExpressions": true,
"allowTypedFunctionExpressions": true,
"allowHigherOrderFunctions": true
}
],
"@typescript-eslint/no-unused-vars": [
"warn",
{
"args": "after-used",
"ignoreRestSiblings": true,
"argsIgnorePattern": "^_"
}
],
"@typescript-eslint/consistent-type-imports": [
"warn",
{ "prefer": "type-imports" }
],
"node/no-unsupported-features/es-syntax": [
"error",
{
"ignores": ["dynamicImport", "modules"]
}
],
"node/no-missing-import": ["off"],
"no-unused-vars": "off"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": true
"overrides": [
{
"files": ["**/__tests__/**"],
"plugins": ["jest"],
"extends": ["plugin:jest/recommended"]
}
}
]
}
12 changes: 0 additions & 12 deletions .flowconfig

This file was deleted.

4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ coverage/
.DS_Store

# generated files
iife/
cjs/
esm/
dist/

# logs
npm-debug.log*
Expand Down
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn lint-staged
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

3 changes: 3 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
Empty file added CHANGELOG.md
Empty file.
File renamed without changes.
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ In addition to the efficient and fast `orderBy()` method `natural-orderby` also
- [Getting Started](#getting-started)
- [Usage](#usage)
- [API Reference](#api-reference)
- [Flow Type Definitions](#flow-type-definitions)
- [TypeScript Declarations](#typescript-declarations)
- [Credits](#credits)
- [License](#license)

Expand Down Expand Up @@ -137,18 +137,18 @@ It also avoids the high overhead caused by [`Array.prototype.sort()`](https://de
#### Syntax

<!-- prettier-ignore -->
```javascript
```typescript
orderBy<T>(
collection: Array<T>,
identifiers?: ?Array<Identifier<T>> | ?Identifier<T>,
orders?: ?Array<Order> | ?Order
collection: ReadonlyArray<T>,
identifiers?: ReadonlyArray<Identifier<T>> | Identifier<T> | null,
orders?: ReadonlyArray<Order> | Order | null
): Array<T>
```

| Type | Value |
| :-------------- | :------------------------------------------------------------------------------- |
| `Identifier<T>` | <code>string &#124; (value: T) => mixed)</code> |
| `Order` | <code>'asc' &#124; 'desc' &#124; (valueA: mixed, valueB: mixed) => number</code> |
| Type | Value |
| :-------------- | :----------------------------------------------------------------------------------- |
| `Identifier<T>` | <code>string &#124; number &#124; (value: T) => unknown</code> |
| `Order` | <code>'asc' &#124; 'desc' &#124; (valueA: unknown, valueB: unknown) => number</code> |

#### Description

Expand Down Expand Up @@ -337,10 +337,10 @@ Creates a compare function that defines the natural sort order and which may be
compare(options?: CompareOptions): CompareFn
```

| Type | Value |
| :--------------- | :---------------------------------------------------- |
| `CompareOptions` | <code>{ order?: 'asc' &#124; 'desc' }</code> |
| `CompareFn` | <code>(valueA: mixed, valueB: mixed) => number</code> |
| Type | Value |
| :--------------- | :-------------------------------------------------------- |
| `CompareOptions` | <code>{ order?: 'asc' &#124; 'desc' }</code> |
| `CompareFn` | <code>(valueA: unknown, valueB: unknown) => number</code> |

#### Description

Expand Down Expand Up @@ -517,13 +517,9 @@ users.sort((a, b) => compare()(a.lastLogin.ip, b.lastLogin.ip));
// ]
```

## Flow Type Definitions
`natural-orderby` has first-class [Flow](https://flow.org/) support with zero configuration to assist you in finding type errors while using our modules.
## TypeScript Declarations

`natural-orderby` has also [TypeScript](https://www.typescriptlang.org/) support and provides TypeScript declarations.
`natural-orderby` is completely written in [TypeScript](https://www.typescriptlang.org/) and provides TypeScript declarations.

## Credits

Expand All @@ -533,4 +529,4 @@ Inspired by [The Alphanum Algorithm](http://www.davekoelle.com/alphanum.html) fr

Licensed under the MIT License, Copyright © 2018 - present Olaf Ennen.

See [LICENSE](./LICENSE) for more information.
See [LICENSE](./LICENSE.md) for more information.
11 changes: 0 additions & 11 deletions babel.config.js

This file was deleted.

4 changes: 3 additions & 1 deletion .commitlintrc.js → commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
const configuration = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
Expand All @@ -8,3 +8,5 @@ module.exports = {
],
},
};

module.exports = configuration;
9 changes: 9 additions & 0 deletions docs/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2018 - present Olaf Ennen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49 changes: 36 additions & 13 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ People sort strings containing numbers differently than most sorting algorithms,

In addition to the efficient and fast `orderBy()` method `natural-orderby` also provides the method `compare()`, which may be passed to [`Array.prototype.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort).

## Contents

- [Getting Started](#getting-started)
- [Usage](#usage)
- [API Reference](#api-reference)
- [TypeScript Declarations](#typescript-declarations)
- [Credits](#credits)
- [License](#license)

---

## Getting Started
Expand Down Expand Up @@ -74,7 +83,7 @@ const users = [
},
];

orderBy(
const sortedUsers = orderBy(
users,
[v => v.datetime, v => v.ip],
['desc', 'asc']
Expand Down Expand Up @@ -128,18 +137,18 @@ It also avoids the high overhead caused by [`Array.prototype.sort()`](https://de
#### Syntax

<!-- prettier-ignore -->
```javascript
```typescript
orderBy<T>(
collection: Array<T>,
identifiers?: ?Array<Identifier<T>> | ?Identifier<T>,
orders?: ?Array<Order> | ?Order
collection: ReadonlyArray<T>,
identifiers?: ReadonlyArray<Identifier<T>> | Identifier<T> | null,
orders?: ReadonlyArray<Order> | Order | null
): Array<T>
```

| Type | Value |
| :-------------- | :------------------------------------------------------------------------------- |
| `Identifier<T>` | <code>string &#124; (value: T) => mixed)</code> |
| `Order` | <code>'asc' &#124; 'desc' &#124; (valueA: mixed, valueB: mixed) => number</code> |
| Type | Value |
| :-------------- | :----------------------------------------------------------------------------------- |
| `Identifier<T>` | <code>string &#124; number &#124; (value: T) => unknown</code> |
| `Order` | <code>'asc' &#124; 'desc' &#124; (valueA: unknown, valueB: unknown) => number</code> |

#### Description

Expand Down Expand Up @@ -328,10 +337,10 @@ Creates a compare function that defines the natural sort order and which may be
compare(options?: CompareOptions): CompareFn
```

| Type | Value |
| :--------------- | :---------------------------------------------------- |
| `CompareOptions` | <code>{ order?: 'asc' &#124; 'desc' }</code> |
| `CompareFn` | <code>(valueA: mixed, valueB: mixed) => number</code> |
| Type | Value |
| :--------------- | :-------------------------------------------------------- |
| `CompareOptions` | <code>{ order?: 'asc' &#124; 'desc' }</code> |
| `CompareFn` | <code>(valueA: unknown, valueB: unknown) => number</code> |

#### Description

Expand Down Expand Up @@ -507,3 +516,17 @@ users.sort((a, b) => compare()(a.lastLogin.ip, b.lastLogin.ip));
// },
// ]
```

## TypeScript Declarations

`natural-orderby` is completely written in [TypeScript](https://www.typescriptlang.org/) and provides TypeScript declarations.

## Credits

Inspired by [The Alphanum Algorithm](http://www.davekoelle.com/alphanum.html) from Dave Koelle.

## License

Licensed under the MIT License, Copyright © 2018 - present Olaf Ennen.

See [LICENSE](./LICENSE.md) for more information.

0 comments on commit c2199b0

Please sign in to comment.