Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonneal committed Sep 12, 2024
0 parents commit f249a64
Show file tree
Hide file tree
Showing 22 changed files with 3,322 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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 ts-standard-install
- uses: pre-commit/action@v3.0.1
30 changes: 30 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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
registry-url: https://npm.pkg.github.com
cache: pnpm
- run: just ts-standard-install
- run: just ts-standard-build
- run: just ts-standard-publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: test

on:
push:
branches: [ main ]

jobs:
ts-standard-test:
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 ts-standard-install
- run: just ts-standard-test-cov
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage
dist
docs
node_modules
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
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
30 changes: 30 additions & 0 deletions eslint.config.mjs
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",
},
},
);
37 changes: 37 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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-install:
@just ts-standard install

ts-standard-test:
@just ts-standard test

ts-standard-test-cov:
@just ts-standard test-cov

ts-standard-build:
@just ts-standard build

ts-standard-publish:
@just ts-standard publish
3 changes: 3 additions & 0 deletions libs/tagup-ts-standard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @tagup/tagup-ts-standard

TypeScript utilities
12 changes: 12 additions & 0 deletions libs/tagup-ts-standard/ex/filter.ex.ts
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));
15 changes: 15 additions & 0 deletions libs/tagup-ts-standard/ex/shared.ex.ts
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) { }
18 changes: 18 additions & 0 deletions libs/tagup-ts-standard/ex/type.ex.ts
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);
27 changes: 27 additions & 0 deletions libs/tagup-ts-standard/package.json
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"
}
}
25 changes: 25 additions & 0 deletions libs/tagup-ts-standard/src/filter.ts
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;
}
8 changes: 8 additions & 0 deletions libs/tagup-ts-standard/src/index.ts
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';
29 changes: 29 additions & 0 deletions libs/tagup-ts-standard/src/type.ts
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;
28 changes: 28 additions & 0 deletions libs/tagup-ts-standard/test/filter.test.ts
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);
})
})
31 changes: 31 additions & 0 deletions libs/tagup-ts-standard/tsconfig.json
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"
]
}
Loading

0 comments on commit f249a64

Please sign in to comment.