xenopomp-essentials 0.3.1 → 0.3.3
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/.yarnrc +2 -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 +4 -3
- 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
package/index.d.mts
DELETED
|
@@ -1,611 +0,0 @@
|
|
|
1
|
-
import { ElementType, ComponentProps, FC, ReactNode, Dispatch, SetStateAction } from 'react';
|
|
2
|
-
import { Jsonifiable } from 'type-fest';
|
|
3
|
-
import * as transliteration from 'transliteration';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Matches any object but not arrays, class instances etc.
|
|
7
|
-
* @since 0.0.1
|
|
8
|
-
*/
|
|
9
|
-
type AnyObject = Record<PropertyKey, unknown>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* This type stands for empty object type.
|
|
13
|
-
*
|
|
14
|
-
* @since 0.0.1
|
|
15
|
-
* @example
|
|
16
|
-
* const message: EmptyObject = { type: string; }; // Will cause error.
|
|
17
|
-
*/
|
|
18
|
-
type EmptyObject = Record<PropertyKey, never>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Simple alias for creating function types. You can use it for type guards
|
|
22
|
-
* as representation of any function, also you can create cleaner type declarations
|
|
23
|
-
* for functions.
|
|
24
|
-
*
|
|
25
|
-
* @since 0.0.1
|
|
26
|
-
* @example
|
|
27
|
-
* type MyFn = Fn<[a: string, b: string], string>;
|
|
28
|
-
*/
|
|
29
|
-
type Fn<Args extends any[] = any[], Res = unknown> = (...args: Args) => Res;
|
|
30
|
-
|
|
31
|
-
type ParamObj<P extends string> = Record<P, string>;
|
|
32
|
-
/**
|
|
33
|
-
* Represents Next.js routing params.
|
|
34
|
-
* @since 0.0.1
|
|
35
|
-
*/
|
|
36
|
-
interface NextParams<P extends string> {
|
|
37
|
-
params: ParamObj<P>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Represents Next.js routing search params.
|
|
41
|
-
* @since 0.0.1
|
|
42
|
-
*/
|
|
43
|
-
interface NextSearchParams<P extends string> {
|
|
44
|
-
searchParams: ParamObj<P>;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* This type describes Next error page params.
|
|
48
|
-
* @since 0.0.1
|
|
49
|
-
*/
|
|
50
|
-
interface NextErrorParams<E extends Error = any> {
|
|
51
|
-
error: E;
|
|
52
|
-
reset: () => void;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* This type wraps ComponentProps<A> to your FC.
|
|
57
|
-
*
|
|
58
|
-
* - __A__ - element type
|
|
59
|
-
* - __P__ - wrapping props
|
|
60
|
-
* - __Ex__ - excluded component props (for example, if you do not want to include 'children' prop in component)
|
|
61
|
-
*
|
|
62
|
-
* @since 0.0.1
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* type VariableComponentPropsWithChildren = ComponentProps<VariableFC<'div'>>;
|
|
66
|
-
* type VariableComponentPropsWithoutChildren = ComponentProps<VariableFC<'div', {}, 'children'>>;
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* // With children
|
|
70
|
-
* const VariableComponent: VariableFC<'section', { variant?: 'default' }> = ({ variant, ...props }) => {
|
|
71
|
-
* return <section {...props}></section>
|
|
72
|
-
* }
|
|
73
|
-
*
|
|
74
|
-
* @example
|
|
75
|
-
* // Without children
|
|
76
|
-
* const VariableComponent: VariableFC<'section', { variant?: 'default' }, 'children'> = ({ variant, ...props }) => {
|
|
77
|
-
* return (
|
|
78
|
-
* <section {...props}>
|
|
79
|
-
* <div>Insert your own children</div>
|
|
80
|
-
* </section>
|
|
81
|
-
* );
|
|
82
|
-
* }
|
|
83
|
-
*/
|
|
84
|
-
type VariableFC<A extends ElementType, P = unknown, Ex extends keyof ComponentProps<A> | undefined = undefined> = FC<P & WeakOmit<ComponentProps<A>, Ex>>;
|
|
85
|
-
/**
|
|
86
|
-
* Works similar to {@link VariableFC}, but return type is Promise<ReactNode>;
|
|
87
|
-
* @since 0.0.1
|
|
88
|
-
*/
|
|
89
|
-
type AsyncVariableFC<A extends ElementType, P = unknown, Ex extends keyof ComponentProps<A> | undefined = undefined> = AsyncFC<P & WeakOmit<ComponentProps<A>, Ex>>;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Same as **FC** (or FunctionalComponent), but it returns Promise.
|
|
93
|
-
*
|
|
94
|
-
* @since 0.0.1
|
|
95
|
-
* @example
|
|
96
|
-
* const Header: AsyncFC<HeaderProps> = async ({}) => {
|
|
97
|
-
* // Do async stuff here...
|
|
98
|
-
*
|
|
99
|
-
* return <div></div>;
|
|
100
|
-
* };
|
|
101
|
-
*/
|
|
102
|
-
type AsyncFC<T = unknown> = ReplaceReturnType<FC<T>, Promise<ReactNode>>;
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Type of set state function from useState.
|
|
106
|
-
*
|
|
107
|
-
* @since 0.0.1
|
|
108
|
-
* @example
|
|
109
|
-
* // typeof setState => SetState<string>
|
|
110
|
-
* const [state, setState] = useState<string>('example');
|
|
111
|
-
*/
|
|
112
|
-
type SetState<TType> = Dispatch<SetStateAction<TType>>;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* This type allows you to make children that can be function.
|
|
116
|
-
*
|
|
117
|
-
* @since 0.0.1
|
|
118
|
-
* @example
|
|
119
|
-
* type Child = FunctionalChildren<[options: string]>;
|
|
120
|
-
* // ReactNode | ((options: string) => ReactNode)
|
|
121
|
-
*/
|
|
122
|
-
type FunctionalChildren<Args extends any[]> = ReactNode | ((...args: Args) => ReactNode);
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @deprecated use {@link FCProps} instead.
|
|
126
|
-
*/
|
|
127
|
-
type FcProps<Comp> = FCProps<Comp>;
|
|
128
|
-
/**
|
|
129
|
-
* Extracts type of props from FC type.
|
|
130
|
-
*
|
|
131
|
-
* @since 0.0.1
|
|
132
|
-
* @example
|
|
133
|
-
* type Props = FcProps<FC<{ align?: boolean }>>;
|
|
134
|
-
* // ^? { align?: boolean }
|
|
135
|
-
*
|
|
136
|
-
* type VariableProps = FcProps<VariableFC<'button', { notAlign?: boolean }>>;
|
|
137
|
-
* // ^? {notAlign?: boolean} & Omit<ClassAttributes<HTMLButtonElement> & React.ButtonHTMLAttributes<HTMLButtonElement>, undefined>
|
|
138
|
-
*/
|
|
139
|
-
type FCProps<Comp> = Comp extends FC<infer Props> ? Props : never;
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Matches any proper React component.
|
|
143
|
-
*/
|
|
144
|
-
type AnyFC = FC<unknown>;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Type that represents data-{attr} keys.
|
|
148
|
-
*/
|
|
149
|
-
type Attribute = `data-${string}`;
|
|
150
|
-
/**
|
|
151
|
-
* Matches any proper data-{attr} keys.
|
|
152
|
-
*/
|
|
153
|
-
type DataAttributeShape = Record<Attribute, any>;
|
|
154
|
-
/**
|
|
155
|
-
* Represents React`s data-{attr} properties for components.
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* type AdditionalAttributes = DataAttributes<{ 'data-disabled': boolean }>;
|
|
159
|
-
*
|
|
160
|
-
* const attrs: AdditionalAttributes = {
|
|
161
|
-
* 'data-disabled': false, // this attr is required
|
|
162
|
-
* };
|
|
163
|
-
*/
|
|
164
|
-
type DataAttributes<Shape extends DataAttributeShape> = Shape;
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Make any async func synchronous.
|
|
168
|
-
*
|
|
169
|
-
* Return never, if __Func__ is not a function, actually.
|
|
170
|
-
*
|
|
171
|
-
* @since 0.0.1
|
|
172
|
-
* @example
|
|
173
|
-
* type NormalFunc = Synchronous<(one: string, two: number) => void>; // (one: string, two: number) => void
|
|
174
|
-
* type AsyncFunc = Synchronous<(one: string, two: number) => Promise<void>>; // (one: string, two: number) => void
|
|
175
|
-
* type NotAFunc = Synchronous<'sus'>; // never
|
|
176
|
-
*/
|
|
177
|
-
type Synchronous<Func> = Func extends Fn ? Func extends (...args: any[]) => Promise<infer Result> ? ReplaceReturnType<Func, Result> : Func : never;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Removes readonly from type.
|
|
181
|
-
* @since 0.0.1
|
|
182
|
-
*/
|
|
183
|
-
type Writeable<T> = {
|
|
184
|
-
-readonly [P in keyof T]: T[P];
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* @deprecated Use {@link WriteableDeep} instead.
|
|
188
|
-
*/
|
|
189
|
-
type DeepWriteable<T> = WriteableDeep<T>;
|
|
190
|
-
/**
|
|
191
|
-
* Removes readonly from type deeply.
|
|
192
|
-
* @since 0.0.1
|
|
193
|
-
*/
|
|
194
|
-
type WriteableDeep<T> = {
|
|
195
|
-
-readonly [P in keyof T]: DeepWriteable<T[P]>;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Checks if type **T** matches type **M**.
|
|
200
|
-
*
|
|
201
|
-
* @since 0.0.1
|
|
202
|
-
*
|
|
203
|
-
* @example Not matching
|
|
204
|
-
* type ViewStyles = {
|
|
205
|
-
* paddingHorizontal: number
|
|
206
|
-
* }
|
|
207
|
-
*
|
|
208
|
-
* type Styles = MatchType<{}, ViewStyles>; // TSERROR
|
|
209
|
-
*
|
|
210
|
-
* @example Matching
|
|
211
|
-
* type ViewStyles = {
|
|
212
|
-
* paddingHorizontal: number;
|
|
213
|
-
* };
|
|
214
|
-
*
|
|
215
|
-
* // No error
|
|
216
|
-
* type Styles = MatchType<
|
|
217
|
-
* {
|
|
218
|
-
* paddingHorizontal: number;
|
|
219
|
-
* },
|
|
220
|
-
* ViewStyles
|
|
221
|
-
* >;
|
|
222
|
-
*/
|
|
223
|
-
type MatchType<T extends M, M> = T extends M ? T : never;
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* This type gets type of array`s item.
|
|
227
|
-
*
|
|
228
|
-
* @since 0.0.1
|
|
229
|
-
* @example
|
|
230
|
-
* type Super = ArrayType<string[]>; // string
|
|
231
|
-
*
|
|
232
|
-
* type Good = ArrayType<(string|number)[]>; // string | number
|
|
233
|
-
*/
|
|
234
|
-
type ArrayType<T> = T extends Array<infer A> ? A : never;
|
|
235
|
-
type ArrayItemType<T> = ArrayType<T>;
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Get return type of function that returns Promise ((...args: any) => Promise<any>).
|
|
239
|
-
*
|
|
240
|
-
* @since 0.0.1
|
|
241
|
-
* @example
|
|
242
|
-
* const doSomething = async (): Promise<string|number> => {
|
|
243
|
-
* return 'result';
|
|
244
|
-
* }
|
|
245
|
-
*
|
|
246
|
-
* type Something = PromiseReturnType<typeof doSomething>;
|
|
247
|
-
* // string|number
|
|
248
|
-
*/
|
|
249
|
-
type AsyncReturnType<F extends (...args: any[]) => Promise<any>> = Awaited<ReturnType<F>>;
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* @deprecated Use {@link InjectDeep} instead.
|
|
253
|
-
*/
|
|
254
|
-
type DeepInject<T, I extends AnyObject> = InjectDeep<T, I>;
|
|
255
|
-
/**
|
|
256
|
-
* Recursively add some type inside all keys of target type.
|
|
257
|
-
*
|
|
258
|
-
* @since 0.0.1
|
|
259
|
-
* @example
|
|
260
|
-
* type Sups = DeepInject<{ supa: { sups: number } }, { _ignore: boolean }>;
|
|
261
|
-
* const asp: Sups = { supa: { sups: 1, _ignore: false }, _ignore: false };
|
|
262
|
-
*/
|
|
263
|
-
type InjectDeep<T, I extends AnyObject> = T extends object ? {
|
|
264
|
-
[K in keyof T]: T[K] extends object ? T[K] & I & DeepInject<T[K], I> : T[K];
|
|
265
|
-
} & I : T;
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Removes undefined from union type.
|
|
269
|
-
* @since 0.0.1
|
|
270
|
-
*/
|
|
271
|
-
type Defined<T> = Exclude<T, undefined>;
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Return never if type does not match JSON schema.
|
|
275
|
-
*
|
|
276
|
-
* @since 0.0.1
|
|
277
|
-
* @example
|
|
278
|
-
* type Schema = Jsonish<{ sus: string; am: string; }>; // OK
|
|
279
|
-
* type AlterSchema = Jsonish<{ sus: string; am: () => {}; }>; // Causes error
|
|
280
|
-
*/
|
|
281
|
-
type Jsonish<T extends Jsonifiable> = T extends Jsonifiable ? T : never;
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Modifies K (Key) in T (Type), replace it with R (Replacement).
|
|
285
|
-
*
|
|
286
|
-
* @since 0.0.1
|
|
287
|
-
* @example
|
|
288
|
-
* type ExcludedStore = Modify<IStore, 'appSettings', { appName: 'Simple name' }>; // Key in IStore has been replaced with new type.
|
|
289
|
-
*/
|
|
290
|
-
type Modify<T, K extends keyof T, R> = Omit<T, K> & {
|
|
291
|
-
[Key in K]: R;
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Make union type of T and null.
|
|
296
|
-
* @since 0.0.1
|
|
297
|
-
*/
|
|
298
|
-
type Nullable<T> = T | null;
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Get typeof key of Record.
|
|
302
|
-
*
|
|
303
|
-
* @since 0.0.1
|
|
304
|
-
* @example
|
|
305
|
-
* type Key = RecordKey<Record<string, number>>; // string
|
|
306
|
-
*/
|
|
307
|
-
type RecordKey<R extends Record<any, any>> = R extends Record<infer K, any> ? K : never;
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* Get typeof value of Record.
|
|
311
|
-
*
|
|
312
|
-
* @since 0.0.1
|
|
313
|
-
* @example
|
|
314
|
-
* type Value = RecordValue<Record<string, number>>; // number
|
|
315
|
-
*/
|
|
316
|
-
type RecordValue<R extends Record<any, any>> = R extends Record<any, infer V> ? V : never;
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* This type replace return type of function with other type.
|
|
320
|
-
*
|
|
321
|
-
* @since 0.0.1
|
|
322
|
-
* @example
|
|
323
|
-
* type StringFC<T = {}> = ReplaceReturnType<FC<T>, string>;
|
|
324
|
-
*/
|
|
325
|
-
type ReplaceReturnType<TFn, TR> = TFn extends (...a: infer A) => any ? (...a: A) => TR : never;
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* Works as Partial, but makes only specified keys partial.
|
|
329
|
-
*
|
|
330
|
-
* @since 0.0.1
|
|
331
|
-
* @example
|
|
332
|
-
* type Super = SelectivePartial<{
|
|
333
|
-
* name: string;
|
|
334
|
-
* address: {
|
|
335
|
-
* street: string;
|
|
336
|
-
* number: number
|
|
337
|
-
* }
|
|
338
|
-
* }, 'address'>;
|
|
339
|
-
*
|
|
340
|
-
* // Property 'address' will be partial.
|
|
341
|
-
*/
|
|
342
|
-
type SelectivePartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Makes type union of type T and undefined
|
|
346
|
-
* @since 0.0.1
|
|
347
|
-
*/
|
|
348
|
-
type Undefinable<T> = T | undefined;
|
|
349
|
-
|
|
350
|
-
/**
|
|
351
|
-
* The strict version of Omit. Allows to remove only
|
|
352
|
-
* keys that are presented in T type.
|
|
353
|
-
*
|
|
354
|
-
* @since 0.0.1
|
|
355
|
-
* @example
|
|
356
|
-
* type Tree = {
|
|
357
|
-
* height: number;
|
|
358
|
-
* age: number;
|
|
359
|
-
* name: string;
|
|
360
|
-
* };
|
|
361
|
-
*
|
|
362
|
-
* // TS2344: Type 'weight' does not satisfy the constraint keyof Tree
|
|
363
|
-
* type TreeInfo = StrictOmit<Tree, 'weight'>;
|
|
364
|
-
*
|
|
365
|
-
* // Works just like usual Omit
|
|
366
|
-
* type CorrectTreeInfo = StrictOmit<Tree, 'name'>;
|
|
367
|
-
*/
|
|
368
|
-
type StrictOmit<T, K extends keyof T> = Omit<T, K>;
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Extracts first type from two generics. Is helper type for {@link OneOf} type.
|
|
372
|
-
* @since 0.0.1
|
|
373
|
-
*/
|
|
374
|
-
type OnlyFirst<F, S> = F & {
|
|
375
|
-
[Key in keyof Omit<S, keyof F>]?: never;
|
|
376
|
-
};
|
|
377
|
-
/**
|
|
378
|
-
* Chooses only one of types array.
|
|
379
|
-
*
|
|
380
|
-
* @since 0.0.1
|
|
381
|
-
* @example
|
|
382
|
-
* type Email = {
|
|
383
|
-
* person: string;
|
|
384
|
-
* content: string;
|
|
385
|
-
* address: string;
|
|
386
|
-
* };
|
|
387
|
-
*
|
|
388
|
-
* type Mail = {
|
|
389
|
-
* person: string;
|
|
390
|
-
* content: string;
|
|
391
|
-
* postCode: number;
|
|
392
|
-
* };
|
|
393
|
-
*
|
|
394
|
-
* type Letter = OneOf<[Email, Mail]>;
|
|
395
|
-
*
|
|
396
|
-
* // Will error, cause address is not assignable to type never.
|
|
397
|
-
* const email: Letter = {
|
|
398
|
-
* person: 'person',
|
|
399
|
-
* content: 'content',
|
|
400
|
-
* address: '',
|
|
401
|
-
* postCode: 12,
|
|
402
|
-
* };
|
|
403
|
-
*/
|
|
404
|
-
type OneOf<TypesArray extends any[], Res = never, AllProperties = MergeTypes<TypesArray>> = TypesArray extends [infer Head, ...infer Rem] ? OneOf<Rem, Res | OnlyFirst<Head, AllProperties>, AllProperties> : Res;
|
|
405
|
-
|
|
406
|
-
/**
|
|
407
|
-
* Merge array of types to one type.
|
|
408
|
-
* @since 0.0.1
|
|
409
|
-
*/
|
|
410
|
-
type MergeTypes<TypesArray extends any[], Res = EmptyObject> = TypesArray extends [infer Head, ...infer Rem] ? MergeTypes<Rem, Res & Head> : Res;
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* Allows to pass undefined as Omit`s generic. Weakly omits type.
|
|
414
|
-
*
|
|
415
|
-
* @since 0.0.1
|
|
416
|
-
* @example
|
|
417
|
-
* // Will not omit any keys
|
|
418
|
-
* type Lib = WeakOmit<{ bookCount: number; date: string }, undefined>;
|
|
419
|
-
*
|
|
420
|
-
* // Will omit
|
|
421
|
-
* type LibStrong = WeakOmit<{ bookCount: number; date: string }, 'date'>;
|
|
422
|
-
*/
|
|
423
|
-
type WeakOmit<Obj extends AnyObject, Keys extends keyof Obj | undefined = undefined> = Keys extends keyof Obj ? Omit<Obj, Keys> : Obj;
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Makes types don`t merging in unions.
|
|
427
|
-
*
|
|
428
|
-
* @since 0.0.1
|
|
429
|
-
* @example
|
|
430
|
-
* type Languages = 'TypeScript' | 'JavaScript' | Lenient<string>;
|
|
431
|
-
* // ^? "TypeScript" | "JavaScript" | string
|
|
432
|
-
*/
|
|
433
|
-
type Lenient<T> = T & {};
|
|
434
|
-
/**
|
|
435
|
-
* This type allows any string, but also saves compiler`s autocomplete
|
|
436
|
-
* feature.
|
|
437
|
-
*
|
|
438
|
-
* @since 0.0.1
|
|
439
|
-
* @example
|
|
440
|
-
* type Languages = 'TypeScript' | 'JavaScript';
|
|
441
|
-
*
|
|
442
|
-
* function handleLanguage(lang: LenientAutocomplete<Languages>) {
|
|
443
|
-
* // ^? string (but autocomplete feature is still here)
|
|
444
|
-
* console.log(lang);
|
|
445
|
-
* }
|
|
446
|
-
*/
|
|
447
|
-
type LenientAutocomplete<T extends string> = T | Lenient<string>;
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Presents plain object in pretty form.
|
|
451
|
-
*/
|
|
452
|
-
type Prettify<T> = {
|
|
453
|
-
[K in keyof T]: T[K];
|
|
454
|
-
} & {};
|
|
455
|
-
/**
|
|
456
|
-
* Presents object in pretty form recursively.
|
|
457
|
-
*/
|
|
458
|
-
type PrettifyDeep<T> = {
|
|
459
|
-
[K in keyof T]: T[K] extends AnyObject ? Prettify<PrettifyDeep<T[K]>> : T[K];
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* Creates pipelines of functions that will be executed only
|
|
464
|
-
* when you will call whole pipeline.
|
|
465
|
-
*
|
|
466
|
-
* @since 0.0.1
|
|
467
|
-
*
|
|
468
|
-
* @param fn
|
|
469
|
-
*
|
|
470
|
-
* @example
|
|
471
|
-
* const stringToDateAndTime = pipe(Date.parse)
|
|
472
|
-
* .pipe(n => new Date(n))
|
|
473
|
-
* .pipe(d => d.toDateString())
|
|
474
|
-
* .pipe(s => s.split('T'))
|
|
475
|
-
* .pipe(([date, time]) => ({ date, time }));
|
|
476
|
-
*
|
|
477
|
-
* const res = stringToDateAndTime('Jan 1, 2024');
|
|
478
|
-
* // ^? { date: string | undefined; time: string | undefined }
|
|
479
|
-
*
|
|
480
|
-
* @see https://youtu.be/bH61wRMqp-o?si=D-2Az-_dUFBxG9HG&t=429
|
|
481
|
-
*/
|
|
482
|
-
declare function pipe<A, B>(fn: (a: A) => B): {
|
|
483
|
-
(a: A): B;
|
|
484
|
-
pipe<C>(fn2: (b: B) => C): {
|
|
485
|
-
(a: A): C;
|
|
486
|
-
pipe<C_1>(fn2: (b: C) => C_1): {
|
|
487
|
-
(a: A): C_1;
|
|
488
|
-
pipe<C_2>(fn2: (b: C_1) => C_2): {
|
|
489
|
-
(a: A): C_2;
|
|
490
|
-
pipe<C_3>(fn2: (b: C_2) => C_3): {
|
|
491
|
-
(a: A): C_3;
|
|
492
|
-
pipe<C_4>(fn2: (b: C_3) => C_4): {
|
|
493
|
-
(a: A): C_4;
|
|
494
|
-
pipe<C_5>(fn2: (b: C_4) => C_5): {
|
|
495
|
-
(a: A): C_5;
|
|
496
|
-
pipe<C_6>(fn2: (b: C_5) => C_6): {
|
|
497
|
-
(a: A): C_6;
|
|
498
|
-
pipe<C_7>(fn2: (b: C_6) => C_7): {
|
|
499
|
-
(a: A): C_7;
|
|
500
|
-
pipe<C_8>(fn2: (b: C_7) => C_8): {
|
|
501
|
-
(a: A): C_8;
|
|
502
|
-
pipe<C_9>(fn2: (b: C_8) => C_9): {
|
|
503
|
-
(a: A): C_9;
|
|
504
|
-
pipe<C_10>(fn2: (b: C_9) => C_10): /*elided*/ any;
|
|
505
|
-
};
|
|
506
|
-
};
|
|
507
|
-
};
|
|
508
|
-
};
|
|
509
|
-
};
|
|
510
|
-
};
|
|
511
|
-
};
|
|
512
|
-
};
|
|
513
|
-
};
|
|
514
|
-
};
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Capitalizes string (makes first letter uppercase).
|
|
519
|
-
* @since 0.0.1
|
|
520
|
-
*/
|
|
521
|
-
declare function capitalize<T extends string>(str: T): Capitalize<T>;
|
|
522
|
-
/**
|
|
523
|
-
* Un-capitalizes string (makes first letter lowercase).
|
|
524
|
-
* @since 0.0.1
|
|
525
|
-
*/
|
|
526
|
-
declare function uncapitalize<T extends string>(str: T): Uncapitalize<T>;
|
|
527
|
-
|
|
528
|
-
type Preid = 'alpha' | 'beta' | 'rc';
|
|
529
|
-
interface VersionData {
|
|
530
|
-
/** Version in format: (__``x.x.x``__-beta.x) */
|
|
531
|
-
version: Nullable<string>;
|
|
532
|
-
/** Version preid. (x.x.x-__``beta``__.x) */
|
|
533
|
-
preid?: LenientAutocomplete<Preid>;
|
|
534
|
-
/** Number of pre-release. (x.x.x-beta.__``12``__) */
|
|
535
|
-
prerelease?: string;
|
|
536
|
-
}
|
|
537
|
-
/**
|
|
538
|
-
* Parses version with preid.
|
|
539
|
-
*
|
|
540
|
-
* @since 0.0.1
|
|
541
|
-
*
|
|
542
|
-
* @param raw
|
|
543
|
-
*
|
|
544
|
-
* @example
|
|
545
|
-
* const { version, preid } = parseVersion('0.0.0-beta.0');
|
|
546
|
-
* // version = '0.0.0'
|
|
547
|
-
* // preid = 'beta'
|
|
548
|
-
*/
|
|
549
|
-
declare const parseVersion: (raw: string) => VersionData;
|
|
550
|
-
|
|
551
|
-
/**
|
|
552
|
-
* Transforms any given string to transliterated variant.
|
|
553
|
-
*
|
|
554
|
-
* @since 0.0.1
|
|
555
|
-
*/
|
|
556
|
-
declare const transliterate: transliteration.TransliterateFunction;
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* Constraints number with min and max values.
|
|
560
|
-
*
|
|
561
|
-
* @example Min value
|
|
562
|
-
* console.log({
|
|
563
|
-
* ogNum: 1, // 1
|
|
564
|
-
* minmax: minmax(1, [2, undefined]), // 2
|
|
565
|
-
* });
|
|
566
|
-
*
|
|
567
|
-
* @example Max value
|
|
568
|
-
* console.log({
|
|
569
|
-
* ogNum: 1001, // 1001
|
|
570
|
-
* minmax: minmax(1001, [undefined, 900]), // 900
|
|
571
|
-
* });
|
|
572
|
-
*
|
|
573
|
-
* @example Min and max value
|
|
574
|
-
* console.log({
|
|
575
|
-
* ogNum: 600, // 600
|
|
576
|
-
* minmax: minmax(1001, [2, 900]), // 600
|
|
577
|
-
* });
|
|
578
|
-
*/
|
|
579
|
-
declare const minmax: (num: number, [min, max]: [min: number | undefined, max: number | undefined]) => number;
|
|
580
|
-
|
|
581
|
-
/**
|
|
582
|
-
* Creates properly type object with jsxDotNotation.
|
|
583
|
-
*
|
|
584
|
-
* @param comp
|
|
585
|
-
* @param rest
|
|
586
|
-
*
|
|
587
|
-
* @example
|
|
588
|
-
* const FlexComp: FC<PropsWithChildren> = ({ children }) => <div>{children}</div>;
|
|
589
|
-
* const FlexRow: FC<PropsWithChildren & { short?: boolean }> = ({ children }) => (
|
|
590
|
-
* <div>{children}</div>
|
|
591
|
-
* );
|
|
592
|
-
* const FlexCol: FC<PropsWithChildren> = ({ children }) => <div>{children}</div>;
|
|
593
|
-
*
|
|
594
|
-
* const Flex = jsxDotNotation(FlexComp, {
|
|
595
|
-
* Row: FlexRow,
|
|
596
|
-
* Col: FlexCol,
|
|
597
|
-
* });
|
|
598
|
-
*
|
|
599
|
-
* const Am = () => {
|
|
600
|
-
* return (
|
|
601
|
-
* <Flex>
|
|
602
|
-
* <Flex.Row short>
|
|
603
|
-
* <Flex.Col></Flex.Col>
|
|
604
|
-
* </Flex.Row>
|
|
605
|
-
* </Flex>
|
|
606
|
-
* );
|
|
607
|
-
* };
|
|
608
|
-
*/
|
|
609
|
-
declare function jsxDotNotation<Props = EmptyObject, Rest extends Record<string, FC<any>> = EmptyObject>(comp: FC<Props>, rest: Rest): FC<Props> & Rest;
|
|
610
|
-
|
|
611
|
-
export { type AnyFC, type AnyObject, type ArrayItemType, type ArrayType, type AsyncFC, type AsyncReturnType, type AsyncVariableFC, type DataAttributes, type Defined, type EmptyObject, type FCProps, type FcProps, type Fn, type FunctionalChildren, type InjectDeep, type Jsonish, type Lenient, type LenientAutocomplete, type MatchType, type MergeTypes, type Modify, type NextErrorParams, type NextParams, type NextSearchParams, type Nullable, type OneOf, type OnlyFirst, type Preid, type Prettify, type PrettifyDeep, type RecordKey, type RecordValue, type ReplaceReturnType, type SelectivePartial, type SetState, type StrictOmit, type Synchronous, type Undefinable, type VariableFC, type VersionData, type WeakOmit, type Writeable, type WriteableDeep, capitalize, jsxDotNotation, minmax, parseVersion, pipe, transliterate, uncapitalize };
|