Skip to content

Commit

Permalink
feat: new toolbox package
Browse files Browse the repository at this point in the history
  • Loading branch information
Zamralik committed May 24, 2024
1 parent 2ff17ed commit b51a5e6
Show file tree
Hide file tree
Showing 27 changed files with 692 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@
{
"allowAsThisParameter": true,
"allowInGenericTypeArguments": [
"Promise"
"Promise",
"Generator"
]
}
],
Expand Down
147 changes: 147 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,153 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm --filter ts-predicate ci:publish

## Toolbox

lint-toolbox:
needs: setup
runs-on: ubuntu-latest
# if: ${{ needs.setup.outputs.ts-files-changed == 'true' }}
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: PNPM installation
uses: pnpm/action-setup@v3
id: pnpm-install
with:
version: 8
run_install: false

- name: Dependencies cache unpacking
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Building workspace dependencies
run: pnpm --filter ts-predicate ci:build

- name: Package dependencies installation
run: pnpm install --filter toolbox

- name: Lint with ESlint
run: pnpm --filter toolbox ci:lint

typescript-syntax-check-toolbox:
needs: setup
runs-on: ubuntu-latest
# if: ${{ needs.setup.outputs.ts-files-changed == 'true' }}
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: PNPM installation
uses: pnpm/action-setup@v3
id: pnpm-install
with:
version: 8
run_install: false

- name: Dependencies cache unpacking
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Building workspace dependencies
run: pnpm --filter ts-predicate ci:build

- name: Package dependencies installation
run: pnpm install --filter toolbox

- name: Check TypeScript syntax
run: pnpm --filter toolbox ci:ts:check

test-toolbox:
needs: setup
runs-on: ubuntu-latest
# if: ${{ needs.setup.outputs.ts-files-changed == 'true' }}
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: PNPM installation
uses: pnpm/action-setup@v3
id: pnpm-install
with:
version: 8
run_install: false

- name: Dependencies cache unpacking
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Building workspace dependencies
run: pnpm --filter ts-predicate ci:build

- name: Package dependencies installation
run: pnpm install --filter toolbox

- name: Test with Node Test runner
run: pnpm --filter toolbox ci:test:unit

- name: Upload reports as artifact
uses: actions/upload-artifact@v3
with:
name: reports
path: |
reports/*
publish-toolbox:
if: ${{ github.ref == 'refs/heads/main' && ! failure() && ! cancelled() && github.event_name == 'push' }}
needs:
[
spell-check-global,
lint-toolbox,
typescript-syntax-check-toolbox,
test-toolbox,
]
runs-on: ubuntu-latest
environment: npm
steps:
- name: Check out repository code
uses: actions/checkout@v4

- uses: actions/setup-node@v3
with:
node-version: "18.x"
registry-url: "https://registry.npmjs.org"

- name: PNPM installation
uses: pnpm/action-setup@v3
id: pnpm-install
with:
version: 8
run_install: false

- name: Dependencies cache unpacking
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Building workspace dependencies
run: pnpm --filter ts-predicate ci:build

- name: Package dependencies installation
run: pnpm install --filter toolbox

- name: Package build
run: pnpm --filter toolbox ci:build

- name: Publish package
id: package-version
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm --filter toolbox ci:publish

## AWS Signature v4

lint-aws-signature-v4:
Expand Down
2 changes: 1 addition & 1 deletion packages/architectura/src/utility/json/json-utility.mts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class JSONUtility
// @ts-expect-error: key is unused
(key: string, value: unknown): unknown =>
{
if (isString(value) && /^\d+n$/.test(value))
if (isString(value) && /^-?\d+n$/.test(value))
{
return BigInt(value.slice(0, -1));
}
Expand Down
22 changes: 22 additions & 0 deletions packages/toolbox/.c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"src": "./tmp/test-build/src",
"exclude": [
"**/test/**",
"**/Types/**/*.*",
"**/_index.js"
],
"extension": [
".js"
],
"reporter": [
"html"
],
"report-dir": "./reports/c8",
"skip-full": true,
"check-coverage": true,
"all": true,
"statements": 100,
"branches": 100,
"functions": 100,
"lines": 100
}
5 changes: 5 additions & 0 deletions packages/toolbox/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"../../.eslintrc.json"
]
}
21 changes: 21 additions & 0 deletions packages/toolbox/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Benjamin Blum (@Zamralik)

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.
76 changes: 76 additions & 0 deletions packages/toolbox/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "@vitruvius-labs/toolbox",
"version": "0.1.0",
"description": "Utility library",
"author": {
"name": "VitruviusLabs"
},
"contributors": [
"Nicolas \"SmashingQuasar\" Lebacq <contact@vitruvius-labs.com>",
"Benjamin Blum <benjamin.blum.98@gmail.com>"
],
"homepage": "https://github.com/VitruviusLabs/typescript/tree/main/packages/toolbox#readme",
"bugs": "https://github.com/VitruviusLabs/typescript/issues",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/VitruviusLabs/typescript.git"
},
"publishConfig": {
"access": "public",
"registry": " https://registry.npmjs.org"
},
"type": "module",
"exports": {
".": {
"import": "./build/esm/_index.mjs",
"types": "./build/types/_index.d.mts"
},
"./json": {
"import": "./build/esm/utility/json/_index.mjs",
"types": "./build/types/utility/json/_index.d.mts"
},
"./indent": {
"import": "./build/esm/utility/indent/_index.mjs",
"types": "./build/types/utility/indent/_index.d.mts"
}
},
"files": [
"build"
],
"engines": {
"node": ">=18.0.0"
},
"scripts": {
"clean": "rm -rf reports coverage build dist lib .eslintcache tmp",
"compile": "tsc -p tsconfig.build.json",
"build": "pnpm clean && pnpm compile",
"eslint:check": "eslint ./src ./test",
"eslint:fix": "eslint ./src ./test --fix",
"test:unit": "pnpm test:unit:build && pnpm test:unit:run",
"test:unit:build": "tsc -p tsconfig.test.json",
"test:unit:run": "node --test tmp/test-build/test",
"test:unit:only": "pnpm test:unit:build && pnpm test:unit:run:only",
"test:unit:run:only": "node --test --test-only tmp/test-build/test",
"test:unit:coverage": "NODE_V8_COVERAGE=./reports/node-coverage node --experimental-test-coverage --test ./tmp/test-build/test",
"test:unit:stryker": "pnpm test:unit",
"test:mutation": "stryker run",
"ts:check": "tsc -p tsconfig.json --noEmit",
"spell:check": "cspell -c ../../.vscode/cspell.json .",
"ci:lint": "pnpm eslint:check",
"ci:ts:check": "pnpm ts:check",
"ci:spell:check": "pnpm spell:check",
"ci:test:unit": "pnpm test:unit",
"ci:full": "pnpm ci:lint && pnpm ci:ts:check && pnpm ci:spell:check && pnpm ci:test:unit",
"ci:publish": "pnpm publish --access public",
"ci:publish:dry": "pnpm publish --access public --dry-run --no-git-checks",
"ci:build": "pnpm build"
},
"dependencies": {
"@vitruvius-labs/ts-predicate": "workspace:^"
},
"keywords": [
"toolbox",
"utility"
]
}
1 change: 1 addition & 0 deletions packages/toolbox/src/_index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./utility/_index.mjs";
2 changes: 2 additions & 0 deletions packages/toolbox/src/utility/_index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./json/_index.mjs";
export * from "./indent/_index.mjs";
1 change: 1 addition & 0 deletions packages/toolbox/src/utility/indent/_index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./indent.utility.mjs";
53 changes: 53 additions & 0 deletions packages/toolbox/src/utility/indent/indent.utility.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Indent utility
*
* @sealed
*/
class IndentUtility
{
/**
* Prune indent
*
* @remarks
* - Blank lines are trimmed
* - The indent of the first non-blank line is removed from all lines
* - Doesn't try to be smart about mixed tabs and spaces.
* - Preserve leading and trailing lines
*/
public static Prune(text: string): string
{
const TEXT: string = text.replaceAll(/^[\t ]+$/gm, "");

const MATCH: RegExpExecArray | null = /^[\t ]+/m.exec(TEXT);

if (MATCH === null)
{
return TEXT;
}

const INDENT: string = MATCH[0];

if (INDENT === "")
{
return TEXT;
}

return TEXT.replaceAll(new RegExp(`^${INDENT}`, "gm"), "");
}

/**
* Prune indent and trim
*
* @remarks
* - Blank lines are trimmed
* - The indent of the first non-blank line is removed from all lines
* - Doesn't try to be smart about mixed tabs and spaces.
* - Remove leading and trailing lines
*/
public static PruneTrim(text: string): string
{
return IndentUtility.Prune(text).trim();
}
}

export { IndentUtility };
2 changes: 2 additions & 0 deletions packages/toolbox/src/utility/json/_index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./definition/_index.mjs";
export * from "./json.utility.mjs";
1 change: 1 addition & 0 deletions packages/toolbox/src/utility/json/definition/_index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./type/_index.mjs";
2 changes: 2 additions & 0 deletions packages/toolbox/src/utility/json/definition/type/_index.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./json-object.type.mjs";
export * from "./json-value.type.mjs";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { JSONValueType } from "./json-value.type.mjs";

type JSONObjectType = Record<string, JSONValueType>;

export type { JSONObjectType };
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type JSONValueType = (
| Array<JSONValueType>
| bigint
| boolean
| number
| string
| { [key: string]: JSONValueType }
| null
);

export type { JSONValueType };
Loading

0 comments on commit b51a5e6

Please sign in to comment.