-
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 97b556d
Showing
21 changed files
with
3,314 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,43 @@ | ||
name: lint | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ConorMacBride/install-package@v1 | ||
with: | ||
apt: just | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
- uses: pnpm/action-setup@v4 | ||
with: | ||
version: 9.9.0 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '22.7.0' | ||
cache: 'pnpm' | ||
- run: just workspace i | ||
- uses: pre-commit/action@v3.0.1 | ||
|
||
test-ts-standard: | ||
runs-on: ubuntu-24.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ConorMacBride/install-package@v1 | ||
with: | ||
apt: just | ||
- uses: pnpm/action-setup@v4 | ||
with: | ||
version: 9.9.0 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '22.7.0' | ||
cache: 'pnpm' | ||
- run: just workspace i | ||
- run: just ts-standard-test-cov |
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 @@ | ||
name: publish | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
ts-standard-publish: | ||
runs-on: ubuntu-24.04 | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: ConorMacBride/install-package@v1 | ||
with: | ||
apt: just | ||
- uses: pnpm/action-setup@v4 | ||
with: | ||
version: 9.9.0 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '22.7.0' | ||
cache: 'pnpm' | ||
- run: just ts-standard-build | ||
|
||
# - run: npm publish | ||
# env: | ||
# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
# - uses: actions/setup-node@v4 | ||
# with: | ||
# node-version: '22.7.0' | ||
# registry-url: 'https://npm.pkg.github.com' |
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,4 @@ | ||
coverage | ||
dist | ||
docs | ||
node_modules |
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,15 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: check-added-large-files | ||
- id: check-json | ||
- id: check-yaml | ||
- id: end-of-file-fixer | ||
- id: trailing-whitespace | ||
- repo: local | ||
hooks: | ||
- id: lint | ||
name: lint | ||
language: system | ||
entry: just lint |
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,30 @@ | ||
import eslintConfigPrettier from "eslint-config-prettier"; | ||
import simpleImportSort from "eslint-plugin-simple-import-sort"; | ||
import typescriptEslint from 'typescript-eslint'; | ||
|
||
export default typescriptEslint.config( | ||
...typescriptEslint.configs.strictTypeChecked, | ||
...typescriptEslint.configs.stylisticTypeChecked, | ||
eslintConfigPrettier, | ||
{ | ||
ignores: ['**/*.{js,mjs}', '**/dist/*', '**/coverage/*'], | ||
}, | ||
{ | ||
languageOptions: { | ||
parserOptions: { | ||
project: ['./libs/**/tsconfig.json'], | ||
// @ts-expect-error | ||
tsconfigRootDir: import.meta.dirname, | ||
}, | ||
}, | ||
}, | ||
{ | ||
plugins: { | ||
"simple-import-sort": simpleImportSort, | ||
}, | ||
rules: { | ||
"simple-import-sort/imports": "error", | ||
"simple-import-sort/exports": "error", | ||
}, | ||
}, | ||
); |
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,31 @@ | ||
set positional-arguments | ||
|
||
default: | ||
@just --list | ||
|
||
pc: | ||
@pre-commit run --all-files | ||
|
||
lint *args='': | ||
@pnpm lint | ||
|
||
lint-fix: | ||
@pnpm lint-fix | ||
|
||
docs-build: | ||
@pnpm docs-build | ||
|
||
workspace *args='': | ||
@pnpm workspace $@ | ||
|
||
ts-standard *args='': | ||
@pnpm ts-standard $@ | ||
|
||
ts-standard-build: | ||
@just ts-standard build | ||
|
||
ts-standard-test: | ||
@just ts-standard test | ||
|
||
ts-standard-test-cov: | ||
@just ts-standard test-cov |
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 @@ | ||
# @tagup/tagup-ts-standard | ||
|
||
TypeScript utilities |
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 @@ | ||
/** | ||
* Example type usage for `@/filter` module | ||
* | ||
* @module | ||
*/ | ||
|
||
import { isNonNullable } from "@/filter"; | ||
|
||
import { is } from "./shared.ex"; | ||
|
||
// isNonNullable | ||
is<string[]>(["hello", "there", null, undefined].filter(isNonNullable)); |
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,15 @@ | ||
/** | ||
* Shared utilities for type examples | ||
* | ||
* @module | ||
*/ | ||
|
||
/** | ||
* Type check value against type parameter. | ||
* | ||
* @typeParam T - type | ||
* | ||
* @param _ - to check | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unnecessary-type-parameters, @typescript-eslint/no-unused-vars | ||
export function is<T>(_: T) { } |
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,18 @@ | ||
/** | ||
* Example type usage for "@/type" module | ||
* | ||
* @module | ||
*/ | ||
|
||
import { Nullable, Opt } from "@/type"; | ||
|
||
import { is } from "./shared.ex"; | ||
|
||
// Opt<T> | ||
is<Opt<string>>("hello"); | ||
is<Opt<string>>(null); | ||
|
||
// Nullable<T> | ||
is<Nullable<string>>("hello"); | ||
is<Nullable<string>>(null); | ||
is<Nullable<string>>(undefined); |
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,27 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/package.json", | ||
"name": "@tagup/tagup-ts-standard", | ||
"description": "TypeScript utilities", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"main": "./dist/tagup-ts-standard.js", | ||
"types": "./dist/src/index.d.ts", | ||
"scripts": { | ||
"build": "tsc && vite build", | ||
"test": "vitest run", | ||
"test-cov": "vitest run --coverage" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.5.4", | ||
"@vitest/coverage-v8": "^2.0.5", | ||
"typescript": "^5.5.3", | ||
"vite": "^5.4.1", | ||
"vite-plugin-dts": "^4.2.1", | ||
"vite-tsconfig-paths": "^5.0.1", | ||
"vitest": "^2.0.5" | ||
}, | ||
"dependencies": { | ||
"dist": "link:/Users/jacksonneal/dev/projects/standards/libs/tagup-ts-standard/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,25 @@ | ||
/** | ||
* Utility functions for filtering and type checking | ||
* | ||
* @module | ||
*/ | ||
|
||
import { Nullable } from "@/type"; | ||
|
||
/** | ||
* Check if a value is not `null` and not `undefined`. | ||
* | ||
* @typeParam T - type of value to check | ||
* | ||
* @param value - to check | ||
* @returns whether value is not `null` and not `undefined` | ||
* | ||
* @example | ||
* const isString = isNonNullable<string>("hello"); // true | ||
* const isNull = isNonNullable(null); // false | ||
* const isUndefined = isNonNullable(undefined); // false | ||
* const nonNullables: number[] = [1, 2, null, undefined].filter(isNonNullable); // [1, 2] | ||
*/ | ||
export function isNonNullable<T>(value: Nullable<T>): value is NonNullable<T> { | ||
return value != null; | ||
} |
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 @@ | ||
/** | ||
* TypeScript utilities | ||
* | ||
* @module tagup-ts-standard | ||
*/ | ||
|
||
export { isNonNullable } from '@/filter'; | ||
export type { Nullable, Opt } from '@/type'; |
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,29 @@ | ||
/** | ||
* Utility types | ||
* | ||
* @module | ||
*/ | ||
|
||
/** | ||
* Optional type that may be `T` or `null` | ||
* | ||
* @typeParam T - non-null type | ||
* | ||
* @example | ||
* const optString: Opt<string> = "hello"; | ||
* const optNull: Opt<string> = null; | ||
*/ | ||
export type Opt<T> = T | null; | ||
|
||
/** | ||
* Nullable type that may be `Opt<T>` or `undefined`, | ||
* opposite of the typescript builtin `NonNullable<T>` | ||
* | ||
* @typeParam T - non-null type | ||
* | ||
* @example | ||
* const nullableString: Nullable<string> = "hello"; | ||
* const nullableNull: Nullable<string> = null; | ||
* const nullableUndefined: Nullable<string> = undefined; | ||
*/ | ||
export type Nullable<T> = Opt<T> | undefined; |
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,28 @@ | ||
/** | ||
* Unit tests for "@/filter" module | ||
* | ||
* @module | ||
*/ | ||
|
||
import { describe } from 'node:test'; | ||
|
||
import { expect, test } from 'vitest' | ||
|
||
import { isNonNullable } from '@'; | ||
|
||
void describe('isNonNullable', () => { | ||
test.each([ | ||
["hello", true], | ||
[null, false], | ||
[undefined, false], | ||
])('isNonNullable(%o) -> %o', (value, expected) => { | ||
expect(isNonNullable(value)).toBe(expected); | ||
}); | ||
|
||
test.each([ | ||
[[], []], | ||
[["hello", null, "there", undefined], ["hello", "there"]], | ||
])('%o.filter(isNonNullable) -> %o', (value, expected) => { | ||
expect(value.filter(isNonNullable)).toStrictEqual(expected); | ||
}) | ||
}) |
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,31 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig.json", | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"lib": [ | ||
"ESNext", | ||
"DOM" | ||
], | ||
"paths": { | ||
"@": [ | ||
"./src" | ||
], | ||
"@/*": [ | ||
"./src/*" | ||
] | ||
}, | ||
"moduleResolution": "bundler", | ||
"isolatedModules": true, | ||
"moduleDetection": "force", | ||
"noEmit": true, | ||
"allowJs": false, | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"include": [ | ||
"**/*.ts" | ||
] | ||
} |
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,28 @@ | ||
import { resolve } from 'path' | ||
import { defineConfig } from 'vite' | ||
import dts from 'vite-plugin-dts' | ||
|
||
export default defineConfig({ | ||
build: { lib: { entry: resolve(__dirname, 'src/index.ts'), formats: ['es'] } }, | ||
resolve: { | ||
alias: { | ||
'@': resolve(__dirname, 'src') | ||
} | ||
}, | ||
plugins: [dts()], | ||
test: { | ||
coverage: { | ||
exclude: [ | ||
'ex', | ||
'dist', | ||
'vite.config.ts' | ||
], | ||
thresholds: { | ||
lines: 100, | ||
functions: 100, | ||
branches: 100, | ||
statements: 100 | ||
} | ||
} | ||
}, | ||
}) |
Oops, something went wrong.