@contember/utilities 1.2.0-rc.9 → 1.2.1

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.
Files changed (86) hide show
  1. package/dist/development/assert-types/Predicates.js +8 -0
  2. package/dist/development/assert-types/Predicates.js.map +1 -1
  3. package/dist/development/class-name/listClassName.js.map +1 -1
  4. package/dist/development/class-name/themeClassName.js.map +1 -1
  5. package/dist/development/css-utilities/px.js +1 -1
  6. package/dist/development/css-utilities/px.js.map +1 -1
  7. package/dist/development/deprecate/deprecate.js +1 -1
  8. package/dist/development/deprecate/deprecate.js.map +1 -1
  9. package/dist/development/deprecate/fallback.js +11 -0
  10. package/dist/development/deprecate/fallback.js.map +1 -0
  11. package/dist/development/functional/extend.js +33 -0
  12. package/dist/development/functional/extend.js.map +1 -0
  13. package/dist/development/functional/range.js +7 -0
  14. package/dist/development/functional/range.js.map +1 -0
  15. package/dist/development/index.js +9 -3
  16. package/dist/development/index.js.map +1 -1
  17. package/dist/production/assert-types/Predicates.js +8 -0
  18. package/dist/production/assert-types/Predicates.js.map +1 -1
  19. package/dist/production/class-name/listClassName.js.map +1 -1
  20. package/dist/production/class-name/themeClassName.js.map +1 -1
  21. package/dist/production/css-utilities/px.js +1 -1
  22. package/dist/production/css-utilities/px.js.map +1 -1
  23. package/dist/production/deprecate/deprecate.js +1 -1
  24. package/dist/production/deprecate/deprecate.js.map +1 -1
  25. package/dist/production/deprecate/fallback.js +11 -0
  26. package/dist/production/deprecate/fallback.js.map +1 -0
  27. package/dist/production/functional/extend.js +33 -0
  28. package/dist/production/functional/extend.js.map +1 -0
  29. package/dist/production/functional/range.js +7 -0
  30. package/dist/production/functional/range.js.map +1 -0
  31. package/dist/production/index.js +9 -3
  32. package/dist/production/index.js.map +1 -1
  33. package/dist/types/assert-types/Predicates.d.ts +2 -0
  34. package/dist/types/assert-types/Predicates.d.ts.map +1 -1
  35. package/dist/types/class-name/listClassName.d.ts +2 -1
  36. package/dist/types/class-name/listClassName.d.ts.map +1 -1
  37. package/dist/types/class-name/themeClassName.d.ts.map +1 -1
  38. package/dist/types/class-name/types.d.ts +2 -3
  39. package/dist/types/class-name/types.d.ts.map +1 -1
  40. package/dist/types/deprecate/deprecate.d.ts +2 -2
  41. package/dist/types/deprecate/deprecate.d.ts.map +1 -1
  42. package/dist/types/deprecate/fallback.d.ts +2 -0
  43. package/dist/types/deprecate/fallback.d.ts.map +1 -0
  44. package/dist/types/deprecate/index.d.ts +1 -1
  45. package/dist/types/deprecate/index.d.ts.map +1 -1
  46. package/dist/types/deprecate/types.d.ts +1 -1
  47. package/dist/types/deprecate/types.d.ts.map +1 -1
  48. package/dist/types/functional/extend.d.ts +5 -0
  49. package/dist/types/functional/extend.d.ts.map +1 -0
  50. package/dist/types/functional/index.d.ts +2 -0
  51. package/dist/types/functional/index.d.ts.map +1 -1
  52. package/dist/types/functional/range.d.ts +9 -0
  53. package/dist/types/functional/range.d.ts.map +1 -0
  54. package/dist/types/tsconfig.tsbuildinfo +1 -1
  55. package/dist/types/types/Any.d.ts +4 -0
  56. package/dist/types/types/Any.d.ts.map +1 -0
  57. package/dist/types/types/Narrow.d.ts +11 -0
  58. package/dist/types/types/Narrow.d.ts.map +1 -0
  59. package/dist/types/types/PolymorphicRefs.d.ts +9 -0
  60. package/dist/types/types/PolymorphicRefs.d.ts.map +1 -1
  61. package/dist/types/types/index.d.ts +3 -1
  62. package/dist/types/types/index.d.ts.map +1 -1
  63. package/package.json +3 -3
  64. package/src/assert-types/Predicates.ts +25 -19
  65. package/src/class-name/listClassName.ts +2 -1
  66. package/src/class-name/themeClassName.ts +0 -1
  67. package/src/class-name/types.ts +2 -3
  68. package/src/css-utilities/px.ts +1 -1
  69. package/src/deprecate/deprecate.ts +5 -5
  70. package/src/deprecate/fallback.ts +7 -0
  71. package/src/deprecate/index.ts +1 -1
  72. package/src/deprecate/types.ts +1 -1
  73. package/src/functional/extend.ts +37 -0
  74. package/src/functional/index.ts +2 -0
  75. package/src/functional/range.ts +11 -0
  76. package/src/types/Any.ts +3 -0
  77. package/src/types/Narrow.ts +21 -0
  78. package/src/types/PolymorphicRefs.ts +10 -0
  79. package/src/types/index.ts +4 -0
  80. package/dist/development/deprecate/currentOrDeprecated.js +0 -20
  81. package/dist/development/deprecate/currentOrDeprecated.js.map +0 -1
  82. package/dist/production/deprecate/currentOrDeprecated.js +0 -20
  83. package/dist/production/deprecate/currentOrDeprecated.js.map +0 -1
  84. package/dist/types/deprecate/currentOrDeprecated.d.ts +0 -35
  85. package/dist/types/deprecate/currentOrDeprecated.d.ts.map +0 -1
  86. package/src/deprecate/currentOrDeprecated.ts +0 -51
@@ -12,5 +12,5 @@ export function px<V extends number | false | null | undefined>(value?: V): stri
12
12
  * @returns Returns a string in the format '10px' or '' when value is falsy.
13
13
  */
14
14
  export function px<V extends number | false | null | undefined>(value?: V): string {
15
- return typeof value === 'number' && !isNaN(value) ? value + 'px' : ''
15
+ return typeof value === 'number' && !(isNaN(value) || value === Infinity || value === -Infinity) ? value + 'px' : ''
16
16
  }
@@ -5,7 +5,7 @@ import { SemverString } from './types'
5
5
  * @internal
6
6
  *
7
7
  * @param removal - Version when the deprecated feature will be removed
8
- * @param assertion - Condition that must be true to avoid the deprecation warning
8
+ * @param condition - Condition under which the deprecation warning will be logged
9
9
  * @param deprecated - Name of the deprecated feature
10
10
  * @param replacement - Name of the feature that replaces the deprecated feature
11
11
  *
@@ -16,15 +16,15 @@ import { SemverString } from './types'
16
16
  * // Logs: Use of "default" is deprecated and might be removed in the next release. Use "hidden" instead.
17
17
  * ```
18
18
  */
19
- export function deprecate(removal: SemverString, assertion: boolean, deprecated: string, replacement: string): void {
20
- if (assertion === false) {
19
+ export function deprecate(removal: SemverString, condition: boolean, deprecated: string, replacement: string | null): void {
20
+ if (condition === true) {
21
21
  if (import.meta.env.DEV) {
22
22
  const shouldThrow = Boolean(import.meta.env.VITE_CONTEMBER_ADMIN_STRICT_DEPRECATIONS)
23
23
 
24
24
  if (shouldThrow) {
25
- throw new Error(`Support for ${deprecated} was planned to be removed in the ${removal} release. Replace it with ${replacement} instead.`)
25
+ throw new Error(`Support for ${deprecated} was planned to be removed in the ${removal} release.${replacement ? ` Replace it with ${replacement} instead.` : 'Remove it.'}`)
26
26
  } else {
27
- console.warn(`Use of ${deprecated} is deprecated and might be removed in the next release. Use ${replacement} instead.`)
27
+ console.warn(`Use of ${deprecated} is deprecated and might be removed in the next release.${replacement ? ` Use ${replacement} instead.` : 'There is no replacement.'}`)
28
28
  }
29
29
  }
30
30
  }
@@ -0,0 +1,7 @@
1
+ export function fallback<R>(current: R, condition: boolean, mapped: R): R {
2
+ if (condition === true) {
3
+ return mapped
4
+ } else {
5
+ return current
6
+ }
7
+ }
@@ -1,3 +1,3 @@
1
- export * from './currentOrDeprecated'
2
1
  export * from './deprecate'
2
+ export * from './fallback'
3
3
  export * from './types'
@@ -1,2 +1,2 @@
1
1
 
2
- export type SemverString = `${number}.${number}.${number}` | `v${number}.${number}.${number}`
2
+ export type SemverString = `${number}.${number}.${number}`
@@ -0,0 +1,37 @@
1
+ /** @internal */
2
+ export function extend<B, E>(
3
+ base: B,
4
+ extension: E,
5
+ ) {
6
+ base = Object.freeze(base)
7
+ extension = Object.freeze(extension)
8
+
9
+ if (typeof base !== typeof extension) {
10
+ return extension === undefined ? base : extension
11
+ } else {
12
+ if (typeof base === 'object' && typeof extension === 'object') {
13
+ if (Array.isArray(base) && Array.isArray(extension)) {
14
+ return Object.freeze([...base, ...extension])
15
+ } else if (base && extension) {
16
+ if ('$$typeof' in extension) {
17
+ return extension
18
+ }
19
+
20
+ const keys = [...new Set([
21
+ ...Object.keys(base),
22
+ ...Object.keys(extension),
23
+ ])]
24
+
25
+ const entries: [string, unknown][] = keys.map(
26
+ key => [key, extend((base as Record<string, unknown>)[key], (extension as Record<string, unknown>)[key])],
27
+ )
28
+
29
+ return Object.freeze(Object.fromEntries(entries))
30
+ } else {
31
+ return extension
32
+ }
33
+ } else {
34
+ return extension
35
+ }
36
+ }
37
+ }
@@ -1,3 +1,5 @@
1
+ export * from './extend'
1
2
  export * from './omit'
2
3
  export * from './pick'
4
+ export * from './range'
3
5
  export * from './setHasOneOf'
@@ -0,0 +1,11 @@
1
+
2
+ /**
3
+ * Get a list of numbers between start and end, inclusive, with the given step size (defaulting to 1)
4
+ * @param start - The starting number.
5
+ * @param end - The ending number.
6
+ * @param step - The step size, optional, defaults to 1.
7
+ * @returns A list of numbers between start and end, inclusive, with the given step size (defaulting to 1)
8
+ */
9
+ export function range(start: number, end: number, step = 1): number[] {
10
+ return Array.from({ length: Math.floor(Math.abs(end - start) / step) + 1 }, (_, i) => start + i * (end > start ? 1 : -1) * Math.abs(step))
11
+ }
@@ -0,0 +1,3 @@
1
+ export type KeyofBase = keyof any;
2
+ export type AnyArray<Type = any> = Array<Type> | ReadonlyArray<Type>;
3
+ export type AnyRecord<T = any> = Record<KeyofBase, T>;
@@ -0,0 +1,21 @@
1
+ import { Try } from './Try'
2
+
3
+ /**
4
+ * Describes types that can be narrowed
5
+ */
6
+ export type Narrowable =
7
+ | string
8
+ | number
9
+ | bigint
10
+ | boolean
11
+
12
+
13
+ type NarrowRaw<A> =
14
+ | (A extends [] ? [] : never)
15
+ | (A extends Narrowable ? A : never)
16
+ | ({ [K in keyof A]: A[K] extends Function
17
+ ? A[K]
18
+ : NarrowRaw<A[K]> })
19
+
20
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint
21
+ export type Narrow<A extends any> = Try<A, [], NarrowRaw<A>>
@@ -56,3 +56,13 @@ export type PolymorphicComponentPropsWithRef<
56
56
  C extends React.ElementType,
57
57
  Props = {}
58
58
  > = PolymorphicComponentProps<C, Props> & { ref?: PolymorphicRef<C> }
59
+
60
+ /**
61
+ * A polymorphic component is a component that can be rendered as different
62
+ * HTML elements or other React components by specifying the `as` prop.
63
+ * This type allows for specifying the component (`C`) and the props (`P`)
64
+ * that the component accepts.
65
+ */
66
+ export type PolymorphicComponent<T extends React.ElementType, P = {}> =
67
+ & (<C extends React.ElementType = T>(props: PolymorphicComponentPropsWithRef<C, P>) => React.ReactElement | null)
68
+ & { displayName?: string | undefined }
@@ -3,13 +3,17 @@ export type {
3
3
  DelimiterCase,
4
4
  KebabCase,
5
5
  LiteralToPrimitiveDeep,
6
+ MergeExclusive,
6
7
  Opaque,
7
8
  PascalCase,
8
9
  Replace,
10
+ Simplify,
9
11
  UnionToIntersection,
10
12
  UnwrapOpaque,
11
13
  } from 'type-fest'
14
+ export * from './Any'
12
15
  export * from './DeepPartial'
16
+ export * from './Narrow'
13
17
  export * from './NonNullableRequired'
14
18
  export * from './NonOptional'
15
19
  export * from './ObjectKeyValue'
@@ -1,20 +0,0 @@
1
- function currentOrDeprecated(current, deprecated, shouldThrow = false) {
2
- if (deprecated !== void 0) {
3
- if (current !== void 0 && false) {
4
- console.error("Current value:", current);
5
- console.error("Deprecated value:", deprecated);
6
- if (shouldThrow) {
7
- throw new Error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`);
8
- } else {
9
- console.error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`);
10
- }
11
- }
12
- return deprecated;
13
- } else {
14
- return current;
15
- }
16
- }
17
- export {
18
- currentOrDeprecated
19
- };
20
- //# sourceMappingURL=currentOrDeprecated.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentOrDeprecated.js","sources":["../../../src/deprecate/currentOrDeprecated.ts"],"sourcesContent":["/**\n * Resolves current or deprecated value. If both are defined, it will throw an error in development mode.\n *\n * @internal\n *\n * Errors are thrown only in development mode. In production mode, the deprecated value is returned.\n *\n * @param current - Current value that replaces deprecated value\n * @param deprecated - Deprecated value that will be removed in the next release\n * @param shouldThrow - Whether to throw an error if both current and deprecated are defined\n * @returns Deprecated value if it is defined, otherwise current value\n * @throws Error if both current and deprecated are defined\n *\n * @example\n * ```ts\n * const current = 'current'\n * const deprecated = 'deprecated'\n *\n * const value = currentOrDeprecated(current, deprecated)\n *\n * console.log(value) // 'deprecated'\n * ```\n *\n * @example\n * ```ts\n * const current = 'current'\n * const deprecated = undefined\n *\n * const value = currentOrDeprecated(current, deprecated)\n *\n * console.log(value) // 'current'\n * ```\n */\nexport function currentOrDeprecated<R, D>(current: R, deprecated: D, shouldThrow: boolean = false): R | D {\n\tif (deprecated !== undefined) {\n\t\tif (current !== undefined && import.meta.env.DEV) {\n\t\t\tconsole.error('Current value:', current)\n\t\t\tconsole.error('Deprecated value:', deprecated)\n\n\t\t\tif (shouldThrow) {\n\t\t\t\tthrow new Error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`)\n\t\t\t} else {\n\t\t\t\tconsole.error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`)\n\t\t\t}\n\t\t}\n\n\t\treturn deprecated\n\t} else {\n\t\treturn current\n\t}\n}\n"],"names":[],"mappings":"AAiCO,SAAS,oBAA0B,SAAY,YAAe,cAAuB,OAAc;AACzG,MAAI,eAAe,QAAW;AAC7B,QAAI,YAAY,UAAa,OAAqB;AACzC,cAAA,MAAM,kBAAkB,OAAO;AAC/B,cAAA,MAAM,qBAAqB,UAAU;AAE7C,UAAI,aAAa;AACV,cAAA,IAAI,MAAM,yGAAyG;AAAA,MAAA,OACnH;AACN,gBAAQ,MAAM,yGAAyG;AAAA,MACxH;AAAA,IACD;AAEO,WAAA;AAAA,EAAA,OACD;AACC,WAAA;AAAA,EACR;AACD;"}
@@ -1,20 +0,0 @@
1
- function currentOrDeprecated(current, deprecated, shouldThrow = false) {
2
- if (deprecated !== void 0) {
3
- if (current !== void 0 && false) {
4
- console.error("Current value:", current);
5
- console.error("Deprecated value:", deprecated);
6
- if (shouldThrow) {
7
- throw new Error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`);
8
- } else {
9
- console.error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`);
10
- }
11
- }
12
- return deprecated;
13
- } else {
14
- return current;
15
- }
16
- }
17
- export {
18
- currentOrDeprecated
19
- };
20
- //# sourceMappingURL=currentOrDeprecated.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentOrDeprecated.js","sources":["../../../src/deprecate/currentOrDeprecated.ts"],"sourcesContent":["/**\n * Resolves current or deprecated value. If both are defined, it will throw an error in development mode.\n *\n * @internal\n *\n * Errors are thrown only in development mode. In production mode, the deprecated value is returned.\n *\n * @param current - Current value that replaces deprecated value\n * @param deprecated - Deprecated value that will be removed in the next release\n * @param shouldThrow - Whether to throw an error if both current and deprecated are defined\n * @returns Deprecated value if it is defined, otherwise current value\n * @throws Error if both current and deprecated are defined\n *\n * @example\n * ```ts\n * const current = 'current'\n * const deprecated = 'deprecated'\n *\n * const value = currentOrDeprecated(current, deprecated)\n *\n * console.log(value) // 'deprecated'\n * ```\n *\n * @example\n * ```ts\n * const current = 'current'\n * const deprecated = undefined\n *\n * const value = currentOrDeprecated(current, deprecated)\n *\n * console.log(value) // 'current'\n * ```\n */\nexport function currentOrDeprecated<R, D>(current: R, deprecated: D, shouldThrow: boolean = false): R | D {\n\tif (deprecated !== undefined) {\n\t\tif (current !== undefined && import.meta.env.DEV) {\n\t\t\tconsole.error('Current value:', current)\n\t\t\tconsole.error('Deprecated value:', deprecated)\n\n\t\t\tif (shouldThrow) {\n\t\t\t\tthrow new Error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`)\n\t\t\t} else {\n\t\t\t\tconsole.error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`)\n\t\t\t}\n\t\t}\n\n\t\treturn deprecated\n\t} else {\n\t\treturn current\n\t}\n}\n"],"names":[],"mappings":"AAiCO,SAAS,oBAA0B,SAAY,YAAe,cAAuB,OAAc;AACzG,MAAI,eAAe,QAAW;AAC7B,QAAI,YAAY,UAAa,OAAqB;AACzC,cAAA,MAAM,kBAAkB,OAAO;AAC/B,cAAA,MAAM,qBAAqB,UAAU;AAE7C,UAAI,aAAa;AACV,cAAA,IAAI,MAAM,yGAAyG;AAAA,MAAA,OACnH;AACN,gBAAQ,MAAM,yGAAyG;AAAA,MACxH;AAAA,IACD;AAEO,WAAA;AAAA,EAAA,OACD;AACC,WAAA;AAAA,EACR;AACD;"}
@@ -1,35 +0,0 @@
1
- /**
2
- * Resolves current or deprecated value. If both are defined, it will throw an error in development mode.
3
- *
4
- * @internal
5
- *
6
- * Errors are thrown only in development mode. In production mode, the deprecated value is returned.
7
- *
8
- * @param current - Current value that replaces deprecated value
9
- * @param deprecated - Deprecated value that will be removed in the next release
10
- * @param shouldThrow - Whether to throw an error if both current and deprecated are defined
11
- * @returns Deprecated value if it is defined, otherwise current value
12
- * @throws Error if both current and deprecated are defined
13
- *
14
- * @example
15
- * ```ts
16
- * const current = 'current'
17
- * const deprecated = 'deprecated'
18
- *
19
- * const value = currentOrDeprecated(current, deprecated)
20
- *
21
- * console.log(value) // 'deprecated'
22
- * ```
23
- *
24
- * @example
25
- * ```ts
26
- * const current = 'current'
27
- * const deprecated = undefined
28
- *
29
- * const value = currentOrDeprecated(current, deprecated)
30
- *
31
- * console.log(value) // 'current'
32
- * ```
33
- */
34
- export declare function currentOrDeprecated<R, D>(current: R, deprecated: D, shouldThrow?: boolean): R | D;
35
- //# sourceMappingURL=currentOrDeprecated.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"currentOrDeprecated.d.ts","sourceRoot":"","sources":["../../../src/deprecate/currentOrDeprecated.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,WAAW,GAAE,OAAe,GAAG,CAAC,GAAG,CAAC,CAiBxG"}
@@ -1,51 +0,0 @@
1
- /**
2
- * Resolves current or deprecated value. If both are defined, it will throw an error in development mode.
3
- *
4
- * @internal
5
- *
6
- * Errors are thrown only in development mode. In production mode, the deprecated value is returned.
7
- *
8
- * @param current - Current value that replaces deprecated value
9
- * @param deprecated - Deprecated value that will be removed in the next release
10
- * @param shouldThrow - Whether to throw an error if both current and deprecated are defined
11
- * @returns Deprecated value if it is defined, otherwise current value
12
- * @throws Error if both current and deprecated are defined
13
- *
14
- * @example
15
- * ```ts
16
- * const current = 'current'
17
- * const deprecated = 'deprecated'
18
- *
19
- * const value = currentOrDeprecated(current, deprecated)
20
- *
21
- * console.log(value) // 'deprecated'
22
- * ```
23
- *
24
- * @example
25
- * ```ts
26
- * const current = 'current'
27
- * const deprecated = undefined
28
- *
29
- * const value = currentOrDeprecated(current, deprecated)
30
- *
31
- * console.log(value) // 'current'
32
- * ```
33
- */
34
- export function currentOrDeprecated<R, D>(current: R, deprecated: D, shouldThrow: boolean = false): R | D {
35
- if (deprecated !== undefined) {
36
- if (current !== undefined && import.meta.env.DEV) {
37
- console.error('Current value:', current)
38
- console.error('Deprecated value:', deprecated)
39
-
40
- if (shouldThrow) {
41
- throw new Error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`)
42
- } else {
43
- console.error(`You are using deprecated together with current value which is mutually exclusive. Use only one of them.`)
44
- }
45
- }
46
-
47
- return deprecated
48
- } else {
49
- return current
50
- }
51
- }