-
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 f76b3e3
Showing
11 changed files
with
193 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,2 @@ | ||
node_modules | ||
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) 2022 John K | ||
|
||
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,3 @@ | ||
# @laffed/gadgets | ||
|
||
Helpful utility types, aliases and methods |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
{ | ||
"name": "@laffed/gadgets", | ||
"version": "1.0.0", | ||
"description": "Typescript Gadgets", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib/**/*" | ||
], | ||
"scripts": { | ||
"build": "tsc -p tsconfig.json", | ||
"prepare": "npm run build", | ||
"version": "git add -A", | ||
"postversion": "git push && git push --tags" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://[email protected]:laffed/gadgets.git" | ||
}, | ||
"author": "laffed", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/laffed/gadgets/issues" | ||
}, | ||
"homepage": "https://github.com/laffed/gadgets/issues#readme", | ||
"devDependencies": { | ||
"@types/node": "^18.7.14", | ||
"typescript": "^4.8.2" | ||
} | ||
} |
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 {} |
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 {} |
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 @@ | ||
export * from './constants'; | ||
export * from './enums'; | ||
export * from './types'; | ||
export * from './methods'; |
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 { Entry } from '../types'; | ||
|
||
type Entries = <T extends object>(object: T) => ReadonlyArray<Entry<T>>; | ||
export const entries: Entries = <T extends object>(obj: T) => Object.entries(obj) as unknown as ReadonlyArray<Entry<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,43 @@ | ||
export type ImmutablePrimitive = undefined | null | boolean | string | number | Function; | ||
|
||
export type Immutable<T> = | ||
T extends ImmutablePrimitive ? T : | ||
T extends Array<infer U> ? ImmutableArray<U> : | ||
T extends Map<infer K, infer V> ? ImmutableMap<K, V> : | ||
T extends Set<infer M> ? ImmutableSet<M> : ImmutableObject<T>; | ||
|
||
export type ImmutableArray<T> = ReadonlyArray<Immutable<T>>; | ||
export type ImmutableMap<K, V> = ReadonlyMap<Immutable<K>, Immutable<V>>; | ||
export type ImmutableSet<T> = ReadonlySet<Immutable<T>>; | ||
export type ImmutableObject<T> = { readonly [K in keyof T]: Immutable<T[K]> }; | ||
|
||
export type OrNull<T> = T | null; | ||
|
||
export type Flavoring<Flavor> = { | ||
_type?: Flavor; | ||
} | ||
export type Flavor<T, Flavor> = T & Flavoring<Flavor>; | ||
|
||
export type TupleEntry<T extends readonly unknown[], I extends unknown[] = [], R = never> = | ||
T extends readonly [infer Head, ...infer Tail] ? | ||
TupleEntry<Tail, [...I, unknown], R | [`${I['length']}`, Head]> : | ||
R; | ||
|
||
export type ObjectEntry<T> = | ||
T extends object ? | ||
{ [K in keyof T]: [K, Required<T>[K]] }[keyof T] extends infer E ? | ||
E extends [infer K, infer V] ? | ||
K extends string | number ? | ||
[`${K}`, V] : | ||
never : | ||
never : | ||
never : | ||
never; | ||
|
||
export type Entry<T extends object> = | ||
T extends readonly [unknown, ...unknown[]] ? | ||
TupleEntry<T> : | ||
T extends ReadonlyArray<infer U> ? | ||
[`${number}`, U] : | ||
ObjectEntry<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,33 @@ | ||
{ | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "./lib", | ||
"target": "ESNext", | ||
"types": [ | ||
"node", | ||
], | ||
"allowJs": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
"isolatedModules": true, | ||
"declarationMap": true, | ||
"declaration": true | ||
}, | ||
"include": [ | ||
"src" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
], | ||
"ts-node": { | ||
"transpileOnly": true, | ||
"files": true, | ||
"compilerOptions": { | ||
"rootDir": "." | ||
} | ||
} | ||
} |