@laudebugs/types 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/LICENSE +7 -0
- package/README.md +26 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/lib/constructable.d.ts +1 -0
- package/dist/lib/constructable.js +2 -0
- package/dist/lib/deep-partial.d.ts +3 -0
- package/dist/lib/deep-partial.js +2 -0
- package/dist/lib/filtered-keys.d.ts +2 -0
- package/dist/lib/filtered-keys.js +6 -0
- package/dist/lib/filtered-type.d.ts +3 -0
- package/dist/lib/filtered-type.js +2 -0
- package/dist/lib/get-constructor-params.d.ts +2 -0
- package/dist/lib/get-constructor-params.js +7 -0
- package/dist/lib/get-enum-values.d.ts +16 -0
- package/dist/lib/get-enum-values.js +20 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/index.js +23 -0
- package/dist/lib/value-of.d.ts +1 -0
- package/dist/lib/value-of.js +2 -0
- package/package.json +15 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Entries up to 0.2.5 were generated by [@jscutlery/semver](https://github.com/jscutlery/semver); later ones are written by hand.
|
|
4
|
+
|
|
5
|
+
## 0.3.0 (2026-12-02)
|
|
6
|
+
|
|
7
|
+
- The package has its code again: 0.2.1 on npm held only `package.json`.
|
|
8
|
+
- Files moved under `dist/`, and the build is CommonJS only. Importing the package by name works from `require` and from ES modules; imports of files inside 0.1.0 no longer resolve.
|
|
9
|
+
- `getEnumValues` is available from `latest` for the first time.
|
|
10
|
+
- Known problems: `DeepPartial` does not make keys optional, `filterKeys` declares the wrong return type, and `getEnumValues` also returns the names of a numeric enum.
|
|
11
|
+
|
|
12
|
+
## [0.2.5](https://github.com/laudebugs/laudebugs/compare/types-0.2.4...types-0.2.5) (2024-02-05)
|
|
13
|
+
|
|
14
|
+
### ⚙️ Chores
|
|
15
|
+
|
|
16
|
+
- update types ([31b6aa4](https://github.com/laudebugs/laudebugs/commit/31b6aa478f0bc763061b61f4d2e587dab062a63f))
|
|
17
|
+
|
|
18
|
+
## [0.2.4](https://github.com/laudebugs/laudebugs/compare/types-0.2.3...types-0.2.4) (2024-02-05)
|
|
19
|
+
|
|
20
|
+
### 🤖 Continuous Integration
|
|
21
|
+
|
|
22
|
+
- update publish script ([6865019](https://github.com/laudebugs/laudebugs/commit/686501943eccc27cfa56db55288e51648cf21838))
|
|
23
|
+
|
|
24
|
+
## [0.2.3](https://github.com/laudebugs/laudebugs/compare/types-0.2.2...types-0.2.3) (2024-02-05)
|
|
25
|
+
|
|
26
|
+
### ⚙️ Chores
|
|
27
|
+
|
|
28
|
+
- run nx repair ([839afa5](https://github.com/laudebugs/laudebugs/commit/839afa5132d6fcf61c123deeb0b095812690fc01))
|
|
29
|
+
- **types:** release version 0.2.3 ([32e0879](https://github.com/laudebugs/laudebugs/commit/32e0879d9f84b6e55fa130ff1bc23b3b07e5389e))
|
|
30
|
+
|
|
31
|
+
### 🤖 Continuous Integration
|
|
32
|
+
|
|
33
|
+
- **types:** update project.json ([a1a1696](https://github.com/laudebugs/laudebugs/commit/a1a16966d4f625c3201ccae6af27cafd8a311d58))
|
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) 2023-present, Laudebugs
|
|
2
|
+
|
|
3
|
+
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:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# TypeScript type utilities
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm i @laudebugs/types
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Version 0.2.1 on npm was published without its code; use 0.3.0 or later.
|
|
10
|
+
|
|
11
|
+
## Utility types
|
|
12
|
+
|
|
13
|
+
| Type | What it is |
|
|
14
|
+
| -------------------- | ------------------------------------------------------------------------------------ |
|
|
15
|
+
| `Constructable<T>` | A class or constructor that builds a `T` |
|
|
16
|
+
| `DeepPartial<T>` | Meant to make every nested key optional. At present it returns the same shape as `T` |
|
|
17
|
+
| `FilteredType<T, C>` | The keys of `T` whose values extend `C` |
|
|
18
|
+
| `ValueOf<T>` | The union of the values of `T` |
|
|
19
|
+
|
|
20
|
+
## Helpers
|
|
21
|
+
|
|
22
|
+
| Function | What it returns |
|
|
23
|
+
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `getEnumValues(enum)` | The values of a string enum. For a numeric enum it also returns the names |
|
|
25
|
+
| `filterKeys(object, pattern)` | The keys of the object that match the regular expression. Its declared return type is wrong for most objects |
|
|
26
|
+
| `getConstructorParams(class)` | The names inside the first parentheses of the class's source text. That is the constructor's parameters only when nothing with parentheses comes before it |
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./lib"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Constructable<T> = new (...args: any[]) => T;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConstructorParams = getConstructorParams;
|
|
4
|
+
function getConstructorParams(target) {
|
|
5
|
+
const params = target.toString().match(/\(([^)]*)\)/)?.[1];
|
|
6
|
+
return params?.split(',').map((param) => param.trim()) ?? [];
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get an array of enum values
|
|
3
|
+
*
|
|
4
|
+
* @param enumObject An enum object
|
|
5
|
+
* @example
|
|
6
|
+
* enum MyEnum {
|
|
7
|
+
* First = 'First',
|
|
8
|
+
* Second = 'Second',
|
|
9
|
+
* Third = 'Third',
|
|
10
|
+
* }
|
|
11
|
+
*
|
|
12
|
+
* const values = getEnumValues(MyEnum)
|
|
13
|
+
* // values = ['First', 'Second', 'Third']
|
|
14
|
+
* @returns An array of enum values
|
|
15
|
+
*/
|
|
16
|
+
export declare const getEnumValues: <E extends Record<string, any>>(enumObject: E) => E[keyof E][];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Get an array of enum values
|
|
4
|
+
*
|
|
5
|
+
* @param enumObject An enum object
|
|
6
|
+
* @example
|
|
7
|
+
* enum MyEnum {
|
|
8
|
+
* First = 'First',
|
|
9
|
+
* Second = 'Second',
|
|
10
|
+
* Third = 'Third',
|
|
11
|
+
* }
|
|
12
|
+
*
|
|
13
|
+
* const values = getEnumValues(MyEnum)
|
|
14
|
+
* // values = ['First', 'Second', 'Third']
|
|
15
|
+
* @returns An array of enum values
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.getEnumValues = void 0;
|
|
19
|
+
const getEnumValues = (enumObject) => Object.keys(enumObject).map((key) => enumObject[key]);
|
|
20
|
+
exports.getEnumValues = getEnumValues;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constructable"), exports);
|
|
18
|
+
__exportStar(require("./deep-partial"), exports);
|
|
19
|
+
__exportStar(require("./filtered-keys"), exports);
|
|
20
|
+
__exportStar(require("./filtered-type"), exports);
|
|
21
|
+
__exportStar(require("./get-constructor-params"), exports);
|
|
22
|
+
__exportStar(require("./get-enum-values"), exports);
|
|
23
|
+
__exportStar(require("./value-of"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ValueOf<T> = T[keyof T];
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@laudebugs/types",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Small TypeScript utility types and helpers.",
|
|
4
5
|
"type": "commonjs",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
7
8
|
"files": [
|
|
8
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"CHANGELOG.md"
|
|
9
11
|
],
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/laudebugs/laudebugs
|
|
14
|
+
"url": "git+https://github.com/laudebugs/laudebugs.git",
|
|
15
|
+
"directory": "packages/types"
|
|
13
16
|
},
|
|
14
17
|
"keywords": [
|
|
15
18
|
"typescript",
|
|
@@ -21,5 +24,13 @@
|
|
|
21
24
|
"bugs": {
|
|
22
25
|
"url": "https://github.com/laudebugs/laudebugs/issues"
|
|
23
26
|
},
|
|
24
|
-
"homepage": "https://github.com/laudebugs/laudebugs/tree/main/packages/types"
|
|
27
|
+
"homepage": "https://github.com/laudebugs/laudebugs/tree/main/packages/types",
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
|
|
33
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
34
|
+
"test": "vitest run"
|
|
35
|
+
}
|
|
25
36
|
}
|