-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6d787ab
Showing
26 changed files
with
3,163 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[*] | ||
indent_size=2 | ||
indent_style=space | ||
end_of_line=lf | ||
charset=utf-8 | ||
insert_final_newline=true | ||
trim_trailing_whitespace=true |
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 @@ | ||
* text=auto eol=lf |
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,10 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: npm | ||
directory: / | ||
schedule: | ||
interval: daily | ||
- package-ecosystem: github-actions | ||
directory: / | ||
schedule: | ||
interval: weekly |
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,43 @@ | ||
name: Publish Package | ||
on: | ||
release: | ||
types: [published] | ||
jobs: | ||
Publish: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: ">=8.10" | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20.x | ||
registry-url: "https://registry.npmjs.org" | ||
cache: pnpm | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Test | ||
run: pnpm test | ||
|
||
- name: Run ESLint | ||
run: pnpm lint:ci | ||
|
||
- name: Run Prettier | ||
run: pnpm prettier:ci | ||
|
||
# Important as this is a type package. | ||
- name: Type Converage | ||
run: pnpm type-coverage | ||
|
||
- name: Publish to npm | ||
run: pnpm publish --access public --no-git-checks | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
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,54 @@ | ||
name: Style | ||
|
||
on: | ||
push: {} | ||
pull_request: {} | ||
|
||
jobs: | ||
Style: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [20.x] | ||
|
||
permissions: | ||
checks: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
with: | ||
version: ">=8.10" | ||
|
||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: pnpm | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Test | ||
run: pnpm test | ||
|
||
- name: Type Converage | ||
run: pnpm type-coverage | ||
|
||
- name: Run ESLint | ||
run: pnpm lint:ci -- --output-file .eslint_report.json --format json | ||
continue-on-error: true | ||
|
||
- name: Annotate ESLint Results | ||
uses: ataylorme/eslint-annotate-action@v3-beta | ||
with: | ||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" | ||
report-json: .eslint_report.json | ||
fail-on-warning: true | ||
markdown-report-on-step-summary: true | ||
|
||
- name: Run Prettier | ||
run: pnpm prettier:ci |
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,7 @@ | ||
node_modules/ | ||
dist/ | ||
.type-coverage/ | ||
|
||
.eslint_report.json | ||
.eslintcache | ||
*.tsbuildinfo |
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,20 @@ | ||
.github/ | ||
.type-coverage/ | ||
.vscode/ | ||
src/ | ||
tests/ | ||
|
||
.editorconfig | ||
.eslintcache | ||
.gitattributes | ||
.gitignore | ||
.nvmrc | ||
.prettierignore | ||
.prettierignore | ||
.prettierrc.js | ||
.tsbuildinfo | ||
eslint.config.js | ||
tsconfig.eslint.json | ||
tsconfig.json | ||
*.js.map | ||
*.tsbuildinfo |
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,3 @@ | ||
engine-strict=true | ||
provenance=true | ||
side-effects-cache=false |
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 @@ | ||
v20 |
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,6 @@ | ||
tsconfig.json | ||
|
||
# Ignore files for PNPM, NPM and YARN | ||
pnpm-lock.yaml | ||
package-lock.json | ||
yarn.lock |
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 @@ | ||
/** | ||
* @file The prettier config. | ||
*/ | ||
|
||
import {options} from "./eslint.config.js"; | ||
import {prettierConfigGenerator} from "@logicer/prettier-config"; | ||
|
||
export default prettierConfigGenerator(options); |
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,7 @@ | ||
{ | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint", | ||
"codezombiech.gitignore", | ||
"esbenp.prettier-vscode" | ||
] | ||
} |
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,10 @@ | ||
{ | ||
"prettier.prettierPath": "./node_modules/prettier", | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"[typescript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"typescript.updateImportsOnFileMove.enabled": "always", | ||
"markdown.extension.toc.levels": "2..6", | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Logicer | ||
|
||
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. |
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,110 @@ | ||
# Logicer's ESLint Base Configuration | ||
|
||
[![npm (scoped)](https://img.shields.io/npm/v/%40logicer/util-types)](https://www.npmjs.com/package/@logicer/util-types) | ||
[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/Logicer16/util-types/style.yml)](https://github.com/Logicer16/util-types/actions) | ||
[![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/m/Logicer16/util-types)](https://github.com/Logicer16/util-types/graphs/contributors) | ||
[![Type Coverage](https://img.shields.io/badge/dynamic/json.svg?label=type%20coverage&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2FLogicer16%2Futil-types%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage) | ||
|
||
A set of custom utility types to help supplement those provided by typescript. | ||
|
||
Contents: | ||
|
||
- [Install](#install) | ||
- [Exports](#exports) | ||
- [IntRange](#intrange) | ||
- [UnionMax](#unionmax) | ||
- [Arithmetic](#arithmetic) | ||
- [Unsafe](#unsafe) | ||
- [Limitations](#limitations) | ||
|
||
## Install | ||
|
||
```sh | ||
npm install --save-dev typescript @logicer/util-types | ||
``` | ||
|
||
## Exports | ||
|
||
### IntRange | ||
|
||
Generate a union of numbers within a certain range. Accepts a start to the range (inclusive) and an end to the range (exclusive). If start is greater than end, `number` will be returned. | ||
|
||
The number of items in the resulting union is limited to 7260 due to other [typescript limitations](#limitations). If the range exceeds this limit, `number` will be returned instead. | ||
|
||
```ts | ||
import type {IntRange} from "@logicer/util-types"; | ||
|
||
// 1 | 2 | 3 | 4 | 5 | ||
type Numbers = IntRange<1, 6>; | ||
|
||
// 1 | 2 | 3 | 4 | ... | 47 | 48 | 49 | 50 | ||
type BigNumbers = IntRange<1, 51>; | ||
|
||
// 1 | 2 | 3 | 4 | ... | 497 | 498 | 499 | 500 | ||
type BiggerNumbers = IntRange<1, 501>; | ||
|
||
// Exceeds typescript's usual depth limit of 1000 in types | ||
// 1 | 2 | 3 | 4 | ... | 4997 | 4998 | 4999 | 5000 | ||
type BiggestNumbers = IntRange<1, 5001>; | ||
|
||
// Can be any number as long as it doesn't exceed the item count limit | ||
// 9001 | 9002 | 9003 | 9004 | ... | 9997 | 9998 | 9999 | 10000 | ||
type OverNineThousand = IntRange<9001, 10000>; | ||
``` | ||
|
||
### UnionMax | ||
|
||
Find the greatest number in a union of numeric type literals. Accepts a union of numeric type literal and lower bound to begin searching at (inclusive). If the lower bound is greater than the lowest value in the union, `number` will be returned. | ||
|
||
The number of items to search is limited to 6328 due to other [typescript limitations](#limitations). If the largest value is not found before this limit is reached, `number` will be returned instead. | ||
|
||
```ts | ||
import type {UnionMax} from "@logicer/util-types"; | ||
|
||
// 5 | ||
type NumbersMax = UnionMax<1 | 2 | 3 | 4 | 5>; | ||
|
||
// 50 | ||
type BigNumbersMax = UnionMax<10 | 20 | 30 | 40 | 50>; | ||
|
||
// 500 | ||
type BiggerNumbersMax = UnionMax<100 | 200 | 300 | 400 | 500>; | ||
|
||
// Exceeds typescript's usual depth limit of 1000 in types | ||
// 5000 | ||
type BiggestNumbersMax = UnionMax<1000 | 2000 | 3000 | 4000 | 5000>; | ||
|
||
// Can be any number as long as it doesn't exceed the item count limit | ||
// 9050 | ||
type OverNineThousandMax = UnionMax<9010 | 9020 | 9030 | 9040 | 9050, 9000>; | ||
|
||
// Returns as soon as the greatest value is found. | ||
// Hence prevents hitting the search limit. | ||
// 1000000 | ||
type EarlyExit = UnionMax<1 | 1000000>; | ||
``` | ||
|
||
### Arithmetic | ||
|
||
Re-exports the types from [`ts-arithmetic`](https://github.com/Logicer16/ts-arithmetic) | ||
|
||
### Unsafe | ||
|
||
> [!WARNING] | ||
> Unsafe contains internal types used to produces the types exported by this package. Use at your own risk. | ||
## Limitations | ||
|
||
Typescript has a [5 million total type instantiation limit](https://github.com/microsoft/TypeScript/pull/32079/files) when resolving each type. This is the sum of the instances included in a definition of a type and those needed to resolve any parameters. This means that if even though a type is under this limit if used alone, it may exceed this limit if used with other types. For example: | ||
|
||
```ts | ||
import type {UnionMax, IntRange} from "@logicer/util-types"; | ||
|
||
// Works without error | ||
type range = IntRange<0, 6000>; | ||
// Note: must iterate from 0 to 6000 | ||
type max = UnionMax<5999 | 6000>; | ||
|
||
// Typescript throws TS2589: Type instantiation is excessively deep and possibly infinite. | ||
type instanceLimited = UnionMax<range>; | ||
``` |
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,73 @@ | ||
/** | ||
* @file The eslint config. | ||
*/ | ||
// Espree is yet to support import-attributes | ||
// eslint-disable-next-line import/namespace, import/no-deprecated | ||
import {ConfigGenerator} from "@logicer/eslint-plugin"; | ||
|
||
/** | ||
* @type {import("@logicer/eslint-plugin").ConfigOptions} | ||
*/ | ||
export const options = { | ||
javascript: true, | ||
jsdoc: true, | ||
prettier: true, | ||
typescript: true | ||
}; | ||
|
||
const generator = new ConfigGenerator(options); | ||
|
||
/** | ||
* @type {import("eslint").Linter.FlatConfigFileSpec[]} | ||
Check failure on line 21 in eslint.config.js GitHub Actions / Style (20.x)
|
||
*/ | ||
const ignores = [ | ||
"node_modules/**/*", | ||
".type-coverage/**/*", | ||
|
||
"**/.eslint_report.json", | ||
"**/.eslintcache" | ||
]; | ||
|
||
/** | ||
* @type {import("eslint").Linter.FlatConfig[]} | ||
Check failure on line 32 in eslint.config.js GitHub Actions / Style (20.x)
|
||
*/ | ||
const eslintPluginConfigs = [ | ||
{ | ||
languageOptions: { | ||
ecmaVersion: 2024, | ||
parserOptions: { | ||
ecmaVersion: 2024, | ||
project: ["./tsconfig.json"], | ||
sourceType: "module" | ||
} | ||
}, | ||
settings: { | ||
"import/parsers": { | ||
// Temporary until https://github.com/import-js/eslint-plugin-import/pull/2829 | ||
espree: [".js", ".jsx", ".cjs", ".mjs"] | ||
}, | ||
"import/resolver": { | ||
typescript: { | ||
project: ["tsconfig.json"] | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
rules: { | ||
"@typescript-eslint/naming-convention": "off" | ||
} | ||
} | ||
]; | ||
|
||
/** | ||
* @type {import("eslint").Linter.FlatConfig[]} | ||
Check failure on line 64 in eslint.config.js GitHub Actions / Style (20.x)
|
||
*/ | ||
const config = [ | ||
{ignores}, | ||
...(await generator.config), | ||
...eslintPluginConfigs, | ||
...(await generator.endConfig) | ||
]; | ||
|
||
export default config; |
Oops, something went wrong.