utilium 0.7.4 → 0.7.6

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/dist/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from './random.js';
6
6
  export * from './string.js';
7
7
  export * from './struct.js';
8
8
  export * from './types.js';
9
+ export * as version from './version.js';
package/dist/index.js CHANGED
@@ -6,3 +6,4 @@ export * from './random.js';
6
6
  export * from './string.js';
7
7
  export * from './struct.js';
8
8
  export * from './types.js';
9
+ export * as version from './version.js';
@@ -0,0 +1,24 @@
1
+ export type Sep = '_' | '-';
2
+ export type Part = `${number}.${number}.${number}`;
3
+ export type Full = Part | `${Part}${Sep}${string}${Sep | '.'}${Part | number}`;
4
+ type Type<S extends string, Acc extends string = ''> = S extends `${infer First}${infer Rest}` ? (First extends Sep | '.' ? Acc : Type<Rest, `${Acc}${First}`>) : Acc;
5
+ export type Parse<T extends Full, StripCore extends boolean> = T extends `${infer Core}${Sep}${infer Rest}` ? Rest extends `${infer U}` ? {
6
+ full: T;
7
+ core: Core;
8
+ type: Type<U>;
9
+ pre: U extends `${Type<U>}${Sep | '.'}${infer Pre}` ? Pre : '';
10
+ display: `${StripCore extends true ? Core extends '1.0.0' ? '' : `${Core} ` : `${Core} `}${Capitalize<Type<U>>}${U extends `${Type<U>}${Sep | '.'}${infer Pre}` ? ` ${Pre}` : ''}`;
11
+ } : never : T extends Part ? {
12
+ full: T;
13
+ core: T;
14
+ display: T;
15
+ } : never;
16
+ export declare const regex: RegExp;
17
+ /**
18
+ * Parses a semver version, including compile-time results
19
+ * @param full the full version to parse
20
+ * @param stripCore Whether to strip the leading core version in the display version when the core version is 1.0.0 (default false)
21
+ */
22
+ export declare function parse<const T extends Full>(full: T): Parse<T, false>;
23
+ export declare function parse<const T extends Full, const S extends boolean>(full: T, stripCore: S): Parse<T, S>;
24
+ export {};
@@ -0,0 +1,7 @@
1
+ import { capitalize } from './string.js';
2
+ export const regex = /^(?<core>\d+\.\d+\.\d+)(?:[-_](?<type>[^-_.]+)[-_.](?<pre>\d*(?:\.\d+)*))?/;
3
+ export function parse(full, stripCore) {
4
+ const { type, pre, core } = regex.exec(full).groups;
5
+ const display = type ? `${stripCore && core == '1.0.0' ? '' : core + ' '}${capitalize(type)}${pre ? ` ${pre}` : ''}` : core;
6
+ return { full, core, pre, type, display };
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "description": "Typescript utilies",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/readme.md CHANGED
@@ -1,3 +1,12 @@
1
1
  # Utilium
2
2
 
3
- A bunch of utilies for Typescript that I have found to be very useful
3
+ A bunch of utilies for Typescript. This includes:
4
+
5
+ - Structs (using decorators)
6
+ - Compile-time math types
7
+ - Debugging types
8
+ - Convenience types and functions for strings and objects
9
+ - RNG functions
10
+ - `List`, a class that combines the best aspects of `Set` and arrays
11
+ - `JSONFileMap` and `FolderMap`
12
+ - Version utilities
package/src/index.ts CHANGED
@@ -6,3 +6,4 @@ export * from './random.js';
6
6
  export * from './string.js';
7
7
  export * from './struct.js';
8
8
  export * from './types.js';
9
+ export * as version from './version.js';
package/src/version.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { capitalize } from './string.js';
2
+
3
+ export type Sep = '_' | '-';
4
+
5
+ export type Part = `${number}.${number}.${number}`;
6
+
7
+ export type Full = Part | `${Part}${Sep}${string}${Sep | '.'}${Part | number}`;
8
+
9
+ type Type<S extends string, Acc extends string = ''> = S extends `${infer First}${infer Rest}` ? (First extends Sep | '.' ? Acc : Type<Rest, `${Acc}${First}`>) : Acc;
10
+
11
+ export type Parse<T extends Full, StripCore extends boolean> = T extends `${infer Core}${Sep}${infer Rest}`
12
+ ? Rest extends `${infer U}`
13
+ ? {
14
+ full: T;
15
+ core: Core;
16
+ type: Type<U>;
17
+ pre: U extends `${Type<U>}${Sep | '.'}${infer Pre}` ? Pre : '';
18
+ display: `${StripCore extends true
19
+ ? Core extends '1.0.0'
20
+ ? ''
21
+ : `${Core} `
22
+ : `${Core} `}${Capitalize<Type<U>>}${U extends `${Type<U>}${Sep | '.'}${infer Pre}` ? ` ${Pre}` : ''}`;
23
+ }
24
+ : never
25
+ : T extends Part
26
+ ? {
27
+ full: T;
28
+ core: T;
29
+ display: T;
30
+ }
31
+ : never;
32
+
33
+ export const regex = /^(?<core>\d+\.\d+\.\d+)(?:[-_](?<type>[^-_.]+)[-_.](?<pre>\d*(?:\.\d+)*))?/;
34
+
35
+ /**
36
+ * Parses a semver version, including compile-time results
37
+ * @param full the full version to parse
38
+ * @param stripCore Whether to strip the leading core version in the display version when the core version is 1.0.0 (default false)
39
+ */
40
+ export function parse<const T extends Full>(full: T): Parse<T, false>;
41
+ export function parse<const T extends Full, const S extends boolean>(full: T, stripCore: S): Parse<T, S>;
42
+ export function parse<const T extends Full, const S extends boolean>(full: T, stripCore?: S): Parse<T, S> {
43
+ const { type, pre, core } = regex.exec(full)!.groups!;
44
+ const display = type ? `${stripCore && core == '1.0.0' ? '' : core + ' '}${capitalize(type)}${pre ? ` ${pre}` : ''}` : core;
45
+ return { full, core, pre, type, display } as Parse<T, S>;
46
+ }
package/tsconfig.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "lib": ["ESNext"],
4
4
  "module": "NodeNext",
5
- "target": "ES2023",
5
+ "target": "ES2022",
6
6
  "moduleResolution": "NodeNext",
7
7
  "outDir": "dist",
8
8
  "typeRoots": ["node_modules/@types"],