-
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
Showing
27 changed files
with
692 additions
and
2 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
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
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
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,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 | ||
} |
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,5 @@ | ||
{ | ||
"extends": [ | ||
"../../.eslintrc.json" | ||
] | ||
} |
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) 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. |
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,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" | ||
] | ||
} |
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 @@ | ||
export * from "./utility/_index.mjs"; |
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,2 @@ | ||
export * from "./json/_index.mjs"; | ||
export * from "./indent/_index.mjs"; |
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 @@ | ||
export * from "./indent.utility.mjs"; |
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,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 }; |
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,2 @@ | ||
export * from "./definition/_index.mjs"; | ||
export * from "./json.utility.mjs"; |
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 @@ | ||
export * from "./type/_index.mjs"; |
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,2 @@ | ||
export * from "./json-object.type.mjs"; | ||
export * from "./json-value.type.mjs"; |
5 changes: 5 additions & 0 deletions
5
packages/toolbox/src/utility/json/definition/type/json-object.type.mts
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,5 @@ | ||
import type { JSONValueType } from "./json-value.type.mjs"; | ||
|
||
type JSONObjectType = Record<string, JSONValueType>; | ||
|
||
export type { JSONObjectType }; |
11 changes: 11 additions & 0 deletions
11
packages/toolbox/src/utility/json/definition/type/json-value.type.mts
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,11 @@ | ||
type JSONValueType = ( | ||
| Array<JSONValueType> | ||
| bigint | ||
| boolean | ||
| number | ||
| string | ||
| { [key: string]: JSONValueType } | ||
| null | ||
); | ||
|
||
export type { JSONValueType }; |
Oops, something went wrong.