xenopomp-essentials 0.3.0 → 0.3.2
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/.config/.lintstagedrc.json +3 -0
- package/.config/build.config.ts +41 -0
- package/.config/testing-exclusions/index.ts +2 -0
- package/.config/testing-exclusions/istanbul-exclusions.ts +1 -0
- package/.config/testing-exclusions/vitest-exclusions.ts +8 -0
- package/.config/ts/tsconfig.lint.json +10 -0
- package/.config/vitest.config.ts +18 -0
- package/.gitattributes +25 -0
- package/.github/workflows/ci.yml +54 -0
- package/.github/workflows/npm-publish.yml +27 -0
- package/.husky/pre-commit +1 -0
- package/.idea/codeStyles/Project.xml +59 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +7 -0
- package/.idea/runConfigurations/_template__of_Vitest.xml +9 -0
- package/.idea/runConfigurations/build.xml +13 -0
- package/.idea/runConfigurations/coverage.xml +12 -0
- package/.idea/runConfigurations/lint.xml +13 -0
- package/.idea/runConfigurations/lint_code.xml +13 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/xenopomp-essentials-js.iml +14 -0
- package/.prettierrc +20 -0
- package/README.md +0 -0
- package/__tests__/assets/assertions/expect-deep-equal.ts +14 -0
- package/__tests__/assets/assertions/expect-to-render.ts +26 -0
- package/__tests__/assets/assertions/index.ts +3 -0
- package/__tests__/assets/assertions/not-throwing.ts +6 -0
- package/__tests__/assets/index.ts +1 -0
- package/__tests__/data/index.ts +1 -0
- package/__tests__/data/parseVersion.data.ts +52 -0
- package/__tests__/unit/cli/path-builder.test.ts +39 -0
- package/__tests__/unit/components/hoc/jsx-dot-notation/component.test-source.tsx +24 -0
- package/__tests__/unit/components/hoc/jsx-dot-notation/hoc.test.tsx +11 -0
- package/__tests__/unit/components/metrika.test.tsx +14 -0
- package/__tests__/unit/components/react-scan.test.tsx +10 -0
- package/__tests__/unit/eslint/config.test.tsx +41 -0
- package/__tests__/unit/utils/capitalize.test.ts +17 -0
- package/__tests__/unit/utils/minmax.test.ts +21 -0
- package/__tests__/unit/utils/parseVersion.test.ts +22 -0
- package/__tests__/unit/utils/pipe.test.ts +23 -0
- package/__tests__/unit/utils/transliterate.test.ts +17 -0
- package/_templates/generator/help/index.ejs.t +5 -0
- package/_templates/generator/new/hello.ejs.t +18 -0
- package/_templates/generator/with-prompt/hello.ejs.t +18 -0
- package/_templates/generator/with-prompt/prompt.ejs.t +14 -0
- package/_templates/init/repo/new-repo.ejs.t +4 -0
- package/_templates/type/new/module.ejs.t +7 -0
- package/_templates/type/new/type.ejs.t +7 -0
- package/_templates/util/new/func.ejs.t +7 -0
- package/_templates/util/new/module.ejs.t +7 -0
- package/_templates/util/new/test.ejs.t +13 -0
- package/eslint.config.ts +17 -0
- package/package.json +7 -6
- package/src/cli-tools/changeFile.ts +1 -0
- package/src/cli-tools/index.ts +2 -0
- package/src/cli-tools/pathBuilder.ts +89 -0
- package/src/eslint/config.ts +145 -0
- package/src/eslint/configs/all.ts +74 -0
- package/src/eslint/configs/deprecation.ts +33 -0
- package/src/eslint/configs/index.ts +7 -0
- package/src/eslint/configs/markdown.ts +30 -0
- package/src/eslint/configs/next.ts +40 -0
- package/src/eslint/configs/old.ts +67 -0
- package/src/eslint/configs/prettier.ts +6 -0
- package/src/eslint/configs/react.ts +18 -0
- package/src/eslint/index.ts +7 -0
- package/src/eslint/prefixes/author.ts +2 -0
- package/src/eslint/prefixes/index.ts +1 -0
- package/src/eslint/types/configs.ts +4 -0
- package/src/eslint/types/custom-config.ts +4 -0
- package/src/eslint/types/index.ts +2 -0
- package/src/index.ts +3 -0
- package/src/next/Metrika/Metrika.props.ts +11 -0
- package/src/next/Metrika/Metrika.tsx +56 -0
- package/src/next/ReactScan/ReactScan.tsx +33 -0
- package/src/next/index.ts +2 -0
- package/src/react/hoc/index.ts +1 -0
- package/src/react/hoc/jsxDotNotation.tsx +38 -0
- package/src/react/index.ts +1 -0
- package/src/repo-eslint-rules/deep-type-naming.rule.ts +49 -0
- package/src/repo-eslint-rules/index.ts +9 -0
- package/src/schemas/import-meta.schema.ts +12 -0
- package/src/schemas/index.ts +1 -0
- package/src/types/aliases/AnyObject.ts +5 -0
- package/src/types/aliases/EmptyObject.ts +8 -0
- package/src/types/aliases/Fn.ts +12 -0
- package/src/types/aliases/index.ts +3 -0
- package/src/types/index.ts +4 -0
- package/src/types/next/NextParams.ts +26 -0
- package/src/types/next/index.ts +1 -0
- package/src/types/react/AnyFc.ts +6 -0
- package/src/types/react/AsyncFC.ts +16 -0
- package/src/types/react/DataAttributes.ts +21 -0
- package/src/types/react/FCProps.ts +19 -0
- package/src/types/react/FunctionalChildren.ts +13 -0
- package/src/types/react/SetState.ts +11 -0
- package/src/types/react/VariableFC.ts +48 -0
- package/src/types/react/VariableProps.ts +9 -0
- package/src/types/react/index.ts +8 -0
- package/src/types/utilities/ArrayType.ts +12 -0
- package/src/types/utilities/AsyncReturnType.ts +14 -0
- package/src/types/utilities/DeepInject.ts +22 -0
- package/src/types/utilities/Defined.ts +5 -0
- package/src/types/utilities/Jsonish.ts +11 -0
- package/src/types/utilities/LenientAutocomplete.ts +24 -0
- package/src/types/utilities/MatchType.ts +26 -0
- package/src/types/utilities/MergeTypes.ts +12 -0
- package/src/types/utilities/Modify.ts +10 -0
- package/src/types/utilities/Nullable.ts +5 -0
- package/src/types/utilities/OneOf.ts +42 -0
- package/src/types/utilities/Prettify.ts +15 -0
- package/src/types/utilities/RecordKey.ts +9 -0
- package/src/types/utilities/RecordValue.ts +9 -0
- package/src/types/utilities/ReplaceReturnType.ts +10 -0
- package/src/types/utilities/SelectivePartial.ts +17 -0
- package/src/types/utilities/StrictOmit.ts +19 -0
- package/src/types/utilities/Synchronous.ts +18 -0
- package/src/types/utilities/Undefinable.ts +5 -0
- package/src/types/utilities/WeakOmit.ts +17 -0
- package/src/types/utilities/Writeable.ts +18 -0
- package/src/types/utilities/index.ts +24 -0
- package/src/utils/capitalize.ts +15 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/minmax.ts +35 -0
- package/src/utils/parseVersion.ts +42 -0
- package/src/utils/pipe.ts +29 -0
- package/src/utils/transliterate.ts +8 -0
- package/tsconfig.json +43 -0
- package/cli-tools/index.d.mts +0 -60
- package/cli-tools/index.d.ts +0 -60
- package/cli-tools/index.mjs +0 -1
- package/eslint/index.d.mts +0 -39
- package/eslint/index.d.ts +0 -39
- package/eslint/index.mjs +0 -3
- package/index.d.mts +0 -611
- package/index.d.ts +0 -611
- package/index.mjs +0 -1
- package/next/index.d.mts +0 -67
- package/next/index.d.ts +0 -67
- package/next/index.mjs +0 -11
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ComponentProps, ElementType } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { FCProps, VariableFC } from '@/types';
|
|
4
|
+
|
|
5
|
+
export type VariableProps<
|
|
6
|
+
A extends ElementType,
|
|
7
|
+
P = unknown,
|
|
8
|
+
Ex extends keyof ComponentProps<A> | undefined = undefined,
|
|
9
|
+
> = FCProps<VariableFC<A, P, Ex>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This type gets type of array`s item.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
* @example
|
|
6
|
+
* type Super = ArrayType<string[]>; // string
|
|
7
|
+
*
|
|
8
|
+
* type Good = ArrayType<(string|number)[]>; // string | number
|
|
9
|
+
*/
|
|
10
|
+
export type ArrayType<T> = T extends Array<infer A> ? A : never;
|
|
11
|
+
|
|
12
|
+
export type ArrayItemType<T> = ArrayType<T>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get return type of function that returns Promise ((...args: any) => Promise<any>).
|
|
3
|
+
*
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
* @example
|
|
6
|
+
* const doSomething = async (): Promise<string|number> => {
|
|
7
|
+
* return 'result';
|
|
8
|
+
* }
|
|
9
|
+
*
|
|
10
|
+
* type Something = PromiseReturnType<typeof doSomething>;
|
|
11
|
+
* // string|number
|
|
12
|
+
*/
|
|
13
|
+
export type AsyncReturnType<F extends (...args: any[]) => Promise<any>> =
|
|
14
|
+
Awaited<ReturnType<F>>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AnyObject } from '@/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use {@link InjectDeep} instead.
|
|
5
|
+
*/
|
|
6
|
+
type DeepInject<T, I extends AnyObject> = InjectDeep<T, I>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Recursively add some type inside all keys of target type.
|
|
10
|
+
*
|
|
11
|
+
* @since 0.0.1
|
|
12
|
+
* @example
|
|
13
|
+
* type Sups = DeepInject<{ supa: { sups: number } }, { _ignore: boolean }>;
|
|
14
|
+
* const asp: Sups = { supa: { sups: 1, _ignore: false }, _ignore: false };
|
|
15
|
+
*/
|
|
16
|
+
export type InjectDeep<T, I extends AnyObject> = T extends object
|
|
17
|
+
? {
|
|
18
|
+
[K in keyof T]: T[K] extends object
|
|
19
|
+
? T[K] & I & DeepInject<T[K], I>
|
|
20
|
+
: T[K];
|
|
21
|
+
} & I
|
|
22
|
+
: T;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Jsonifiable } from 'type-fest';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Return never if type does not match JSON schema.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @example
|
|
8
|
+
* type Schema = Jsonish<{ sus: string; am: string; }>; // OK
|
|
9
|
+
* type AlterSchema = Jsonish<{ sus: string; am: () => {}; }>; // Causes error
|
|
10
|
+
*/
|
|
11
|
+
export type Jsonish<T extends Jsonifiable> = T extends Jsonifiable ? T : never;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes types don`t merging in unions.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
* @example
|
|
6
|
+
* type Languages = 'TypeScript' | 'JavaScript' | Lenient<string>;
|
|
7
|
+
* // ^? "TypeScript" | "JavaScript" | string
|
|
8
|
+
*/
|
|
9
|
+
export type Lenient<T> = T & {};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* This type allows any string, but also saves compiler`s autocomplete
|
|
13
|
+
* feature.
|
|
14
|
+
*
|
|
15
|
+
* @since 0.0.1
|
|
16
|
+
* @example
|
|
17
|
+
* type Languages = 'TypeScript' | 'JavaScript';
|
|
18
|
+
*
|
|
19
|
+
* function handleLanguage(lang: LenientAutocomplete<Languages>) {
|
|
20
|
+
* // ^? string (but autocomplete feature is still here)
|
|
21
|
+
* console.log(lang);
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
export type LenientAutocomplete<T extends string> = T | Lenient<string>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if type **T** matches type **M**.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
*
|
|
6
|
+
* @example Not matching
|
|
7
|
+
* type ViewStyles = {
|
|
8
|
+
* paddingHorizontal: number
|
|
9
|
+
* }
|
|
10
|
+
*
|
|
11
|
+
* type Styles = MatchType<{}, ViewStyles>; // TSERROR
|
|
12
|
+
*
|
|
13
|
+
* @example Matching
|
|
14
|
+
* type ViewStyles = {
|
|
15
|
+
* paddingHorizontal: number;
|
|
16
|
+
* };
|
|
17
|
+
*
|
|
18
|
+
* // No error
|
|
19
|
+
* type Styles = MatchType<
|
|
20
|
+
* {
|
|
21
|
+
* paddingHorizontal: number;
|
|
22
|
+
* },
|
|
23
|
+
* ViewStyles
|
|
24
|
+
* >;
|
|
25
|
+
*/
|
|
26
|
+
export type MatchType<T extends M, M> = T extends M ? T : never;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EmptyObject } from '@/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merge array of types to one type.
|
|
5
|
+
* @since 0.0.1
|
|
6
|
+
*/
|
|
7
|
+
export type MergeTypes<
|
|
8
|
+
TypesArray extends any[],
|
|
9
|
+
Res = EmptyObject,
|
|
10
|
+
> = TypesArray extends [infer Head, ...infer Rem]
|
|
11
|
+
? MergeTypes<Rem, Res & Head>
|
|
12
|
+
: Res;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifies K (Key) in T (Type), replace it with R (Replacement).
|
|
3
|
+
*
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
* @example
|
|
6
|
+
* type ExcludedStore = Modify<IStore, 'appSettings', { appName: 'Simple name' }>; // Key in IStore has been replaced with new type.
|
|
7
|
+
*/
|
|
8
|
+
export type Modify<T, K extends keyof T, R> = Omit<T, K> & {
|
|
9
|
+
[Key in K]: R;
|
|
10
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { MergeTypes } from '@/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Extracts first type from two generics. Is helper type for {@link OneOf} type.
|
|
5
|
+
* @since 0.0.1
|
|
6
|
+
*/
|
|
7
|
+
export type OnlyFirst<F, S> = F & { [Key in keyof Omit<S, keyof F>]?: never };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Chooses only one of types array.
|
|
11
|
+
*
|
|
12
|
+
* @since 0.0.1
|
|
13
|
+
* @example
|
|
14
|
+
* type Email = {
|
|
15
|
+
* person: string;
|
|
16
|
+
* content: string;
|
|
17
|
+
* address: string;
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* type Mail = {
|
|
21
|
+
* person: string;
|
|
22
|
+
* content: string;
|
|
23
|
+
* postCode: number;
|
|
24
|
+
* };
|
|
25
|
+
*
|
|
26
|
+
* type Letter = OneOf<[Email, Mail]>;
|
|
27
|
+
*
|
|
28
|
+
* // Will error, cause address is not assignable to type never.
|
|
29
|
+
* const email: Letter = {
|
|
30
|
+
* person: 'person',
|
|
31
|
+
* content: 'content',
|
|
32
|
+
* address: '',
|
|
33
|
+
* postCode: 12,
|
|
34
|
+
* };
|
|
35
|
+
*/
|
|
36
|
+
export type OneOf<
|
|
37
|
+
TypesArray extends any[],
|
|
38
|
+
Res = never,
|
|
39
|
+
AllProperties = MergeTypes<TypesArray>,
|
|
40
|
+
> = TypesArray extends [infer Head, ...infer Rem]
|
|
41
|
+
? OneOf<Rem, Res | OnlyFirst<Head, AllProperties>, AllProperties>
|
|
42
|
+
: Res;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AnyObject } from '@/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Presents plain object in pretty form.
|
|
5
|
+
*/
|
|
6
|
+
export type Prettify<T> = {
|
|
7
|
+
[K in keyof T]: T[K];
|
|
8
|
+
} & {};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Presents object in pretty form recursively.
|
|
12
|
+
*/
|
|
13
|
+
export type PrettifyDeep<T> = {
|
|
14
|
+
[K in keyof T]: T[K] extends AnyObject ? Prettify<PrettifyDeep<T[K]>> : T[K];
|
|
15
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This type replace return type of function with other type.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
* @example
|
|
6
|
+
* type StringFC<T = {}> = ReplaceReturnType<FC<T>, string>;
|
|
7
|
+
*/
|
|
8
|
+
export type ReplaceReturnType<TFn, TR> = TFn extends (...a: infer A) => any
|
|
9
|
+
? (...a: A) => TR
|
|
10
|
+
: never;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Works as Partial, but makes only specified keys partial.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.0.1
|
|
5
|
+
* @example
|
|
6
|
+
* type Super = SelectivePartial<{
|
|
7
|
+
* name: string;
|
|
8
|
+
* address: {
|
|
9
|
+
* street: string;
|
|
10
|
+
* number: number
|
|
11
|
+
* }
|
|
12
|
+
* }, 'address'>;
|
|
13
|
+
*
|
|
14
|
+
* // Property 'address' will be partial.
|
|
15
|
+
*/
|
|
16
|
+
export type SelectivePartial<T, K extends keyof T> = Omit<T, K> &
|
|
17
|
+
Partial<Pick<T, K>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The strict version of Omit. Allows to remove only
|
|
3
|
+
* keys that are presented in T type.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.0.1
|
|
6
|
+
* @example
|
|
7
|
+
* type Tree = {
|
|
8
|
+
* height: number;
|
|
9
|
+
* age: number;
|
|
10
|
+
* name: string;
|
|
11
|
+
* };
|
|
12
|
+
*
|
|
13
|
+
* // TS2344: Type 'weight' does not satisfy the constraint keyof Tree
|
|
14
|
+
* type TreeInfo = StrictOmit<Tree, 'weight'>;
|
|
15
|
+
*
|
|
16
|
+
* // Works just like usual Omit
|
|
17
|
+
* type CorrectTreeInfo = StrictOmit<Tree, 'name'>;
|
|
18
|
+
*/
|
|
19
|
+
export type StrictOmit<T, K extends keyof T> = Omit<T, K>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Fn, ReplaceReturnType } from '@/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Make any async func synchronous.
|
|
5
|
+
*
|
|
6
|
+
* Return never, if __Func__ is not a function, actually.
|
|
7
|
+
*
|
|
8
|
+
* @since 0.0.1
|
|
9
|
+
* @example
|
|
10
|
+
* type NormalFunc = Synchronous<(one: string, two: number) => void>; // (one: string, two: number) => void
|
|
11
|
+
* type AsyncFunc = Synchronous<(one: string, two: number) => Promise<void>>; // (one: string, two: number) => void
|
|
12
|
+
* type NotAFunc = Synchronous<'sus'>; // never
|
|
13
|
+
*/
|
|
14
|
+
export type Synchronous<Func> = Func extends Fn
|
|
15
|
+
? Func extends (...args: any[]) => Promise<infer Result>
|
|
16
|
+
? ReplaceReturnType<Func, Result>
|
|
17
|
+
: Func
|
|
18
|
+
: never;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AnyObject } from '@/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Allows to pass undefined as Omit`s generic. Weakly omits type.
|
|
5
|
+
*
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @example
|
|
8
|
+
* // Will not omit any keys
|
|
9
|
+
* type Lib = WeakOmit<{ bookCount: number; date: string }, undefined>;
|
|
10
|
+
*
|
|
11
|
+
* // Will omit
|
|
12
|
+
* type LibStrong = WeakOmit<{ bookCount: number; date: string }, 'date'>;
|
|
13
|
+
*/
|
|
14
|
+
export type WeakOmit<
|
|
15
|
+
Obj extends AnyObject,
|
|
16
|
+
Keys extends keyof Obj | undefined = undefined,
|
|
17
|
+
> = Keys extends keyof Obj ? Omit<Obj, Keys> : Obj;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes readonly from type.
|
|
3
|
+
* @since 0.0.1
|
|
4
|
+
*/
|
|
5
|
+
export type Writeable<T> = { -readonly [P in keyof T]: T[P] };
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use {@link WriteableDeep} instead.
|
|
9
|
+
*/
|
|
10
|
+
type DeepWriteable<T> = WriteableDeep<T>;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Removes readonly from type deeply.
|
|
14
|
+
* @since 0.0.1
|
|
15
|
+
*/
|
|
16
|
+
export type WriteableDeep<T> = {
|
|
17
|
+
-readonly [P in keyof T]: DeepWriteable<T[P]>;
|
|
18
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from './Synchronous';
|
|
2
|
+
export * from './Writeable';
|
|
3
|
+
export * from './MatchType';
|
|
4
|
+
export * from './ArrayType';
|
|
5
|
+
export * from './AsyncReturnType';
|
|
6
|
+
export * from './DeepInject';
|
|
7
|
+
export * from './Defined';
|
|
8
|
+
export * from './Jsonish';
|
|
9
|
+
export * from './Modify';
|
|
10
|
+
export * from './Nullable';
|
|
11
|
+
export * from './RecordKey';
|
|
12
|
+
export * from './RecordValue';
|
|
13
|
+
export * from './ReplaceReturnType';
|
|
14
|
+
export * from './SelectivePartial';
|
|
15
|
+
export * from './Undefinable';
|
|
16
|
+
export * from './StrictOmit';
|
|
17
|
+
|
|
18
|
+
export * from './OneOf';
|
|
19
|
+
|
|
20
|
+
export * from './MergeTypes';
|
|
21
|
+
|
|
22
|
+
export * from './WeakOmit';
|
|
23
|
+
export * from './LenientAutocomplete';
|
|
24
|
+
export * from './Prettify';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capitalizes string (makes first letter uppercase).
|
|
3
|
+
* @since 0.0.1
|
|
4
|
+
*/
|
|
5
|
+
export function capitalize<T extends string>(str: T): Capitalize<T> {
|
|
6
|
+
return (str.charAt(0).toUpperCase() + str.slice(1)) as Capitalize<T>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Un-capitalizes string (makes first letter lowercase).
|
|
11
|
+
* @since 0.0.1
|
|
12
|
+
*/
|
|
13
|
+
export function uncapitalize<T extends string>(str: T): Uncapitalize<T> {
|
|
14
|
+
return (str.charAt(0).toLowerCase() + str.slice(1)) as Uncapitalize<T>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constraints number with min and max values.
|
|
3
|
+
*
|
|
4
|
+
* @example Min value
|
|
5
|
+
* console.log({
|
|
6
|
+
* ogNum: 1, // 1
|
|
7
|
+
* minmax: minmax(1, [2, undefined]), // 2
|
|
8
|
+
* });
|
|
9
|
+
*
|
|
10
|
+
* @example Max value
|
|
11
|
+
* console.log({
|
|
12
|
+
* ogNum: 1001, // 1001
|
|
13
|
+
* minmax: minmax(1001, [undefined, 900]), // 900
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* @example Min and max value
|
|
17
|
+
* console.log({
|
|
18
|
+
* ogNum: 600, // 600
|
|
19
|
+
* minmax: minmax(1001, [2, 900]), // 600
|
|
20
|
+
* });
|
|
21
|
+
*/
|
|
22
|
+
export const minmax = (
|
|
23
|
+
num: number,
|
|
24
|
+
[min, max]: [min: number | undefined, max: number | undefined],
|
|
25
|
+
) => {
|
|
26
|
+
if (!!min && num <= min) {
|
|
27
|
+
return min;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!!max && num >= max) {
|
|
31
|
+
return max;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return num;
|
|
35
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { LenientAutocomplete, Nullable } from '@/types';
|
|
2
|
+
|
|
3
|
+
export type Preid = 'alpha' | 'beta' | 'rc';
|
|
4
|
+
|
|
5
|
+
export interface VersionData {
|
|
6
|
+
/** Version in format: (__``x.x.x``__-beta.x) */
|
|
7
|
+
version: Nullable<string>;
|
|
8
|
+
|
|
9
|
+
/** Version preid. (x.x.x-__``beta``__.x) */
|
|
10
|
+
preid?: LenientAutocomplete<Preid>;
|
|
11
|
+
|
|
12
|
+
/** Number of pre-release. (x.x.x-beta.__``12``__) */
|
|
13
|
+
prerelease?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Parses version with preid.
|
|
18
|
+
*
|
|
19
|
+
* @since 0.0.1
|
|
20
|
+
*
|
|
21
|
+
* @param raw
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const { version, preid } = parseVersion('0.0.0-beta.0');
|
|
25
|
+
* // version = '0.0.0'
|
|
26
|
+
* // preid = 'beta'
|
|
27
|
+
*/
|
|
28
|
+
export const parseVersion = (raw: string): VersionData => {
|
|
29
|
+
/** Parsed version. */
|
|
30
|
+
// eslint-disable-next-line regexp/no-useless-flag,regexp/no-unused-capturing-group
|
|
31
|
+
const version = raw.match(/(\d\.){2}\d/gi)?.at(0) || null;
|
|
32
|
+
// eslint-disable-next-line regexp/no-useless-flag
|
|
33
|
+
const preid = raw.match(/(?<=-)\w+(?=\.\d)/gi)?.at(0);
|
|
34
|
+
// eslint-disable-next-line regexp/no-useless-flag,regexp/no-unused-capturing-group
|
|
35
|
+
const prerelease = raw.match(/(?<=((\d\.){2}\d-\w+\.))\d+/gi)?.at(0);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
version,
|
|
39
|
+
preid,
|
|
40
|
+
prerelease,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates pipelines of functions that will be executed only
|
|
3
|
+
* when you will call whole pipeline.
|
|
4
|
+
*
|
|
5
|
+
* @since 0.0.1
|
|
6
|
+
*
|
|
7
|
+
* @param fn
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const stringToDateAndTime = pipe(Date.parse)
|
|
11
|
+
* .pipe(n => new Date(n))
|
|
12
|
+
* .pipe(d => d.toDateString())
|
|
13
|
+
* .pipe(s => s.split('T'))
|
|
14
|
+
* .pipe(([date, time]) => ({ date, time }));
|
|
15
|
+
*
|
|
16
|
+
* const res = stringToDateAndTime('Jan 1, 2024');
|
|
17
|
+
* // ^? { date: string | undefined; time: string | undefined }
|
|
18
|
+
*
|
|
19
|
+
* @see https://youtu.be/bH61wRMqp-o?si=D-2Az-_dUFBxG9HG&t=429
|
|
20
|
+
*/
|
|
21
|
+
export function pipe<A, B>(fn: (a: A) => B) {
|
|
22
|
+
function run(a: A) {
|
|
23
|
+
return fn(a);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
run.pipe = <C>(fn2: (b: B) => C) => pipe((a: A) => fn2(fn(a)));
|
|
27
|
+
|
|
28
|
+
return run;
|
|
29
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Next default options. */
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"allowImportingTsExtensions": false,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
// "noEmit": true,
|
|
12
|
+
"esModuleInterop": true,
|
|
13
|
+
"module": "esnext",
|
|
14
|
+
"moduleResolution": "bundler",
|
|
15
|
+
"resolveJsonModule": true,
|
|
16
|
+
"isolatedModules": true,
|
|
17
|
+
"jsx": "preserve",
|
|
18
|
+
// "incremental": true,
|
|
19
|
+
// "plugins": [
|
|
20
|
+
// {
|
|
21
|
+
// "name": "next"
|
|
22
|
+
// }
|
|
23
|
+
// ],
|
|
24
|
+
"paths": {
|
|
25
|
+
"@/*": ["./src/*"],
|
|
26
|
+
"@test/*": ["./__tests__/*"]
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
/* Make compiler more strict. */
|
|
30
|
+
"noImplicitAny": true,
|
|
31
|
+
"noUncheckedIndexedAccess": true,
|
|
32
|
+
"noImplicitReturns": true,
|
|
33
|
+
"strictNullChecks": true
|
|
34
|
+
},
|
|
35
|
+
"include": [
|
|
36
|
+
"next-env.d.ts",
|
|
37
|
+
".config/declarations/vitest.d.ts", ".config/declarations/*.d.ts",
|
|
38
|
+
"**/*.ts", "**/*.tsx",
|
|
39
|
+
".next/types/**/*.ts",
|
|
40
|
+
"./src"
|
|
41
|
+
],
|
|
42
|
+
"exclude": ["node_modules"]
|
|
43
|
+
}
|
package/cli-tools/index.d.mts
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Fluent interface for creating paths of application.
|
|
3
|
-
*
|
|
4
|
-
* @since 0.0.1
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* import { PathBuilder } from 'xenopomp-essentials/cli-tools';
|
|
8
|
-
*
|
|
9
|
-
* const builder = new PathBuilder();
|
|
10
|
-
*
|
|
11
|
-
* const res = builder
|
|
12
|
-
* .appSource()
|
|
13
|
-
* .cd('./dist/src')
|
|
14
|
-
* .file('.prettierrc')
|
|
15
|
-
* .build();
|
|
16
|
-
*
|
|
17
|
-
* console.log(res); //? C:/Projects/example/node_modules/xenopomp-essentials/dist/src/.prettierrc
|
|
18
|
-
*/
|
|
19
|
-
declare class PathBuilder {
|
|
20
|
-
private paths;
|
|
21
|
-
private pushPaths;
|
|
22
|
-
/**
|
|
23
|
-
* Pushes any custom paths to builder.
|
|
24
|
-
* @since 0.0.1
|
|
25
|
-
* @param paths
|
|
26
|
-
*/
|
|
27
|
-
cd(...paths: string[]): PathBuilder;
|
|
28
|
-
/**
|
|
29
|
-
* Pushes filename to paths.
|
|
30
|
-
* @since 0.0.1
|
|
31
|
-
* @param fileName
|
|
32
|
-
*/
|
|
33
|
-
file<T extends `${string}.${string}`>(fileName: T): PathBuilder;
|
|
34
|
-
/**
|
|
35
|
-
* Pushes path to compiled app directory.
|
|
36
|
-
* Is useful for cli tools that have to access files inside their bundles.
|
|
37
|
-
*
|
|
38
|
-
* It probably may take no effect (if import.meta is not available in a scope).
|
|
39
|
-
* If it is, will push cwd.
|
|
40
|
-
*
|
|
41
|
-
* @since 0.0.1
|
|
42
|
-
*/
|
|
43
|
-
appSource(): PathBuilder;
|
|
44
|
-
/**
|
|
45
|
-
* Gets path of directory where script is running. In cli tools it access
|
|
46
|
-
* path, where cli tool was started.
|
|
47
|
-
* @since 0.0.1
|
|
48
|
-
*/
|
|
49
|
-
cwd(): PathBuilder;
|
|
50
|
-
/**
|
|
51
|
-
* @since 0.0.1
|
|
52
|
-
*/
|
|
53
|
-
clear(): PathBuilder;
|
|
54
|
-
/**
|
|
55
|
-
* @since 0.0.1
|
|
56
|
-
*/
|
|
57
|
-
build(): string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export { PathBuilder };
|