@transcend-io/type-utils 2.0.0 → 3.0.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.
Files changed (167) hide show
  1. package/LICENSE +201 -21
  2. package/dist/index.d.mts +591 -0
  3. package/dist/index.d.mts.map +1 -0
  4. package/dist/index.mjs +529 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/package.json +33 -41
  7. package/.yarn/sdks/eslint/package.json +0 -14
  8. package/.yarn/sdks/prettier/package.json +0 -7
  9. package/.yarn/sdks/typescript/package.json +0 -10
  10. package/README.md +0 -37
  11. package/build/aggregateObjects.d.ts +0 -27
  12. package/build/aggregateObjects.d.ts.map +0 -1
  13. package/build/aggregateObjects.js +0 -34
  14. package/build/aggregateObjects.js.map +0 -1
  15. package/build/apply.d.ts +0 -35
  16. package/build/apply.d.ts.map +0 -1
  17. package/build/apply.js +0 -47
  18. package/build/apply.js.map +0 -1
  19. package/build/codecTools/FixedLengthArray.d.ts +0 -20
  20. package/build/codecTools/FixedLengthArray.d.ts.map +0 -1
  21. package/build/codecTools/FixedLengthArray.js +0 -11
  22. package/build/codecTools/FixedLengthArray.js.map +0 -1
  23. package/build/codecTools/FixedLengthString.d.ts +0 -17
  24. package/build/codecTools/FixedLengthString.d.ts.map +0 -1
  25. package/build/codecTools/FixedLengthString.js +0 -10
  26. package/build/codecTools/FixedLengthString.js.map +0 -1
  27. package/build/codecTools/NonEmptyString.d.ts +0 -12
  28. package/build/codecTools/NonEmptyString.d.ts.map +0 -1
  29. package/build/codecTools/NonEmptyString.js +0 -6
  30. package/build/codecTools/NonEmptyString.js.map +0 -1
  31. package/build/codecTools/createDefaultCodec.d.ts +0 -39
  32. package/build/codecTools/createDefaultCodec.d.ts.map +0 -1
  33. package/build/codecTools/createDefaultCodec.js +0 -114
  34. package/build/codecTools/createDefaultCodec.js.map +0 -1
  35. package/build/codecTools/decodeCodec.d.ts +0 -12
  36. package/build/codecTools/decodeCodec.d.ts.map +0 -1
  37. package/build/codecTools/decodeCodec.js +0 -47
  38. package/build/codecTools/decodeCodec.js.map +0 -1
  39. package/build/codecTools/dictionary.d.ts +0 -18
  40. package/build/codecTools/dictionary.d.ts.map +0 -1
  41. package/build/codecTools/dictionary.js +0 -13
  42. package/build/codecTools/dictionary.js.map +0 -1
  43. package/build/codecTools/index.d.ts +0 -10
  44. package/build/codecTools/index.d.ts.map +0 -1
  45. package/build/codecTools/index.js +0 -10
  46. package/build/codecTools/index.js.map +0 -1
  47. package/build/codecTools/isCodecError.d.ts +0 -7
  48. package/build/codecTools/isCodecError.d.ts.map +0 -1
  49. package/build/codecTools/isCodecError.js +0 -9
  50. package/build/codecTools/isCodecError.js.map +0 -1
  51. package/build/codecTools/partialRecord.d.ts +0 -16
  52. package/build/codecTools/partialRecord.d.ts.map +0 -1
  53. package/build/codecTools/partialRecord.js +0 -11
  54. package/build/codecTools/partialRecord.js.map +0 -1
  55. package/build/codecTools/toJsonSchema.d.ts +0 -11
  56. package/build/codecTools/toJsonSchema.d.ts.map +0 -1
  57. package/build/codecTools/toJsonSchema.js +0 -115
  58. package/build/codecTools/toJsonSchema.js.map +0 -1
  59. package/build/enum.d.ts +0 -47
  60. package/build/enum.d.ts.map +0 -1
  61. package/build/enum.js +0 -44
  62. package/build/enum.js.map +0 -1
  63. package/build/enums.d.ts +0 -20
  64. package/build/enums.d.ts.map +0 -1
  65. package/build/enums.js +0 -18
  66. package/build/enums.js.map +0 -1
  67. package/build/findAllWithRegex.d.ts +0 -41
  68. package/build/findAllWithRegex.d.ts.map +0 -1
  69. package/build/findAllWithRegex.js +0 -41
  70. package/build/findAllWithRegex.js.map +0 -1
  71. package/build/flattenObject.d.ts +0 -33
  72. package/build/flattenObject.d.ts.map +0 -1
  73. package/build/flattenObject.js +0 -72
  74. package/build/flattenObject.js.map +0 -1
  75. package/build/fromEntries.d.ts +0 -9
  76. package/build/fromEntries.d.ts.map +0 -1
  77. package/build/fromEntries.js +0 -9
  78. package/build/fromEntries.js.map +0 -1
  79. package/build/getEntries.d.ts +0 -8
  80. package/build/getEntries.d.ts.map +0 -1
  81. package/build/getEntries.js +0 -10
  82. package/build/getEntries.js.map +0 -1
  83. package/build/getKeys.d.ts +0 -14
  84. package/build/getKeys.d.ts.map +0 -1
  85. package/build/getKeys.js +0 -19
  86. package/build/getKeys.js.map +0 -1
  87. package/build/getValues.d.ts +0 -9
  88. package/build/getValues.d.ts.map +0 -1
  89. package/build/getValues.js +0 -9
  90. package/build/getValues.js.map +0 -1
  91. package/build/gql.d.ts +0 -22
  92. package/build/gql.d.ts.map +0 -1
  93. package/build/gql.js +0 -32
  94. package/build/gql.js.map +0 -1
  95. package/build/groupBy.d.ts +0 -11
  96. package/build/groupBy.d.ts.map +0 -1
  97. package/build/groupBy.js +0 -20
  98. package/build/groupBy.js.map +0 -1
  99. package/build/index.d.ts +0 -19
  100. package/build/index.d.ts.map +0 -1
  101. package/build/index.js +0 -19
  102. package/build/index.js.map +0 -1
  103. package/build/invert.d.ts +0 -23
  104. package/build/invert.d.ts.map +0 -1
  105. package/build/invert.js +0 -79
  106. package/build/invert.js.map +0 -1
  107. package/build/noExcess.d.ts +0 -33
  108. package/build/noExcess.d.ts.map +0 -1
  109. package/build/noExcess.js +0 -153
  110. package/build/noExcess.js.map +0 -1
  111. package/build/tests/FixedLengthArray.test.d.ts +0 -2
  112. package/build/tests/FixedLengthArray.test.d.ts.map +0 -1
  113. package/build/tests/FixedLengthArray.test.js +0 -15
  114. package/build/tests/FixedLengthArray.test.js.map +0 -1
  115. package/build/tests/aggregateObjects.test.d.ts +0 -2
  116. package/build/tests/aggregateObjects.test.d.ts.map +0 -1
  117. package/build/tests/aggregateObjects.test.js +0 -98
  118. package/build/tests/aggregateObjects.test.js.map +0 -1
  119. package/build/tests/createDefaultCodec.test.d.ts +0 -2
  120. package/build/tests/createDefaultCodec.test.d.ts.map +0 -1
  121. package/build/tests/createDefaultCodec.test.js +0 -104
  122. package/build/tests/createDefaultCodec.test.js.map +0 -1
  123. package/build/tests/decodeCodec.test.d.ts +0 -2
  124. package/build/tests/decodeCodec.test.d.ts.map +0 -1
  125. package/build/tests/decodeCodec.test.js +0 -43
  126. package/build/tests/decodeCodec.test.js.map +0 -1
  127. package/build/tests/enum.test.d.ts +0 -2
  128. package/build/tests/enum.test.d.ts.map +0 -1
  129. package/build/tests/enum.test.js +0 -21
  130. package/build/tests/enum.test.js.map +0 -1
  131. package/build/tests/flattenObject.test.d.ts +0 -2
  132. package/build/tests/flattenObject.test.d.ts.map +0 -1
  133. package/build/tests/flattenObject.test.js +0 -115
  134. package/build/tests/flattenObject.test.js.map +0 -1
  135. package/build/tests/gql.test.d.ts +0 -2
  136. package/build/tests/gql.test.d.ts.map +0 -1
  137. package/build/tests/gql.test.js +0 -44
  138. package/build/tests/gql.test.js.map +0 -1
  139. package/build/tests/groupBy.test.d.ts +0 -2
  140. package/build/tests/groupBy.test.d.ts.map +0 -1
  141. package/build/tests/groupBy.test.js +0 -13
  142. package/build/tests/groupBy.test.js.map +0 -1
  143. package/build/tests/invert.test.d.ts +0 -2
  144. package/build/tests/invert.test.d.ts.map +0 -1
  145. package/build/tests/invert.test.js +0 -50
  146. package/build/tests/invert.test.js.map +0 -1
  147. package/build/tests/noExcess.test.d.ts +0 -2
  148. package/build/tests/noExcess.test.d.ts.map +0 -1
  149. package/build/tests/noExcess.test.js +0 -65
  150. package/build/tests/noExcess.test.js.map +0 -1
  151. package/build/tests/transposeObjectArray.test.d.ts +0 -2
  152. package/build/tests/transposeObjectArray.test.d.ts.map +0 -1
  153. package/build/tests/transposeObjectArray.test.js +0 -155
  154. package/build/tests/transposeObjectArray.test.js.map +0 -1
  155. package/build/transposeObjectArray.d.ts +0 -67
  156. package/build/transposeObjectArray.d.ts.map +0 -1
  157. package/build/transposeObjectArray.js +0 -39
  158. package/build/transposeObjectArray.js.map +0 -1
  159. package/build/tsbuildinfo +0 -1
  160. package/build/types.d.ts +0 -150
  161. package/build/types.d.ts.map +0 -1
  162. package/build/types.js +0 -2
  163. package/build/types.js.map +0 -1
  164. package/build/valuesOf.d.ts +0 -12
  165. package/build/valuesOf.d.ts.map +0 -1
  166. package/build/valuesOf.js +0 -14
  167. package/build/valuesOf.js.map +0 -1
@@ -1,47 +0,0 @@
1
- import { fold, isLeft } from 'fp-ts/Either';
2
- import { pipe } from 'fp-ts/pipeable';
3
- /**
4
- * Determine the codec paths that are invalid.
5
- * @param v - Validation errors.
6
- * @returns The error strings formatted for human consumption.
7
- */
8
- function getPaths(v) {
9
- return pipe(v, fold((errors) => errors.map((error) => {
10
- const lastCtx = error.context.at(-1);
11
- const fullPath = error.context.map(({ key }) => key).join('.');
12
- return `${fullPath} expected type '${lastCtx === null || lastCtx === void 0 ? void 0 : lastCtx.type.name}'`;
13
- }), () => ['no errors']));
14
- }
15
- /**
16
- * Get custom error messages for the errors.
17
- * @param v - Validation errors.
18
- * @param customErrorFromContext - Custom mapper function.
19
- * @returns The custom error strings formatted for human consumption.
20
- */
21
- function getCustomErrors(v, customErrorFromContext) {
22
- return pipe(v, fold((errors) => errors.map((error) => customErrorFromContext(error.context)), () => ['no errors']));
23
- }
24
- export const CODEC_ERROR_MESSAGE = 'Failed to decode codec:';
25
- /**
26
- * Decode a codec, returning the value if contents are validated, else throws an error
27
- * @param codec - The codec to decode with
28
- * @param txt - The text to JSON parse
29
- * @param parse - If a string is provided, assume it is JSON and call JSON.parse on it
30
- * @param customErrorFromContext - a function to custom process validation contexts to error messages
31
- * @returns The result of the function or the object if it was not a function
32
- */
33
- export function decodeCodec(codec, txt, parse = true, customErrorFromContext = undefined) {
34
- // uncomment the below to view the response pre-decode
35
- const decoded = codec.decode(parse && typeof txt === 'string' ? JSON.parse(txt) : txt);
36
- // Log errors on failure
37
- if (isLeft(decoded)) {
38
- const errorPaths = getPaths(decoded);
39
- const customError = customErrorFromContext !== undefined
40
- ? JSON.stringify(getCustomErrors(decoded, customErrorFromContext), null, 2)
41
- : undefined;
42
- throw new Error(`${CODEC_ERROR_MESSAGE} ${JSON.stringify(errorPaths, null, 2)}${customError !== null && customError !== void 0 ? customError : ''}`);
43
- }
44
- // Return the decoded codec
45
- return decoded.right;
46
- }
47
- //# sourceMappingURL=decodeCodec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decodeCodec.js","sourceRoot":"","sources":["../../src/codecTools/decodeCodec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAGtC;;;;GAIG;AACH,SAAS,QAAQ,CAAI,CAAkB;IACrC,OAAO,IAAI,CACT,CAAC,EACD,IAAI,CACF,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACnB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACrC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/D,OAAO,GAAG,QAAQ,mBAAmB,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,IAAI,GAAG,CAAC;IAC7D,CAAC,CAAC,EAEJ,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,CACpB,CACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CACtB,CAAkB,EAClB,sBAAgE;IAEhE,OAAO,IAAI,CACT,CAAC,EACD,IAAI,CACF,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,sBAAsB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,EACxE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,CACpB,CACF,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CACzB,KAAa,EACb,GAAgD,EAChD,KAAK,GAAG,IAAI,EACZ,yBAEgB,SAAS;IAEzB,sDAAsD;IACtD,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAC1B,KAAK,IAAI,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CACzD,CAAC;IACF,wBAAwB;IACxB,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACpB,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;QACrC,MAAM,WAAW,GACf,sBAAsB,KAAK,SAAS;YAClC,CAAC,CAAC,IAAI,CAAC,SAAS,CACZ,eAAe,CAAC,OAAO,EAAE,sBAAsB,CAAC,EAChD,IAAI,EACJ,CAAC,CACF;YACH,CAAC,CAAC,SAAS,CAAC;QAChB,MAAM,IAAI,KAAK,CACb,GAAG,mBAAmB,IAAI,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC,GAC3D,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,EACjB,EAAE,CACH,CAAC;IACJ,CAAC;IAED,2BAA2B;IAC3B,OAAO,OAAO,CAAC,KAAK,CAAC;AACvB,CAAC"}
@@ -1,18 +0,0 @@
1
- import * as t from 'io-ts';
2
- /** A record with optional keys */
3
- export interface DictionaryC<D extends t.Mixed, C extends t.Mixed> extends t.DictionaryType<D, C, {
4
- [K in t.TypeOf<D>]?: t.TypeOf<C>;
5
- }, {
6
- [K in t.OutputOf<D>]?: t.OutputOf<C>;
7
- }, unknown> {
8
- }
9
- /**
10
- * Helper to encode/decode a record with partial keys.
11
- * Copied from https://github.com/gcanti/io-ts/issues/429#issuecomment-655394345
12
- * @param keys - The possible dictionary keys
13
- * @param values - The possible dictionary values
14
- * @param name - (Optional) name of this dictionary
15
- * @returns The codec for a dictionary
16
- */
17
- export declare const dictionary: <D extends t.Mixed, C extends t.Mixed>(keys: D, values: C, name?: string) => DictionaryC<D, C>;
18
- //# sourceMappingURL=dictionary.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dictionary.d.ts","sourceRoot":"","sources":["../../src/codecTools/dictionary.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,kCAAkC;AAClC,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC,KAAK,CAC/D,SAAQ,CAAC,CAAC,cAAc,CACtB,CAAC,EACD,CAAC,EACD;KACG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;CACjC,EACD;KACG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;CACrC,EACD,OAAO,CACR;CAAG;AAEN;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,oEAGd,MAAM,sBAEqD,CAAC"}
@@ -1,13 +0,0 @@
1
- // external
2
- import { unsafeCoerce } from 'fp-ts/function';
3
- import * as t from 'io-ts';
4
- /**
5
- * Helper to encode/decode a record with partial keys.
6
- * Copied from https://github.com/gcanti/io-ts/issues/429#issuecomment-655394345
7
- * @param keys - The possible dictionary keys
8
- * @param values - The possible dictionary values
9
- * @param name - (Optional) name of this dictionary
10
- * @returns The codec for a dictionary
11
- */
12
- export const dictionary = (keys, values, name) => unsafeCoerce(t.record(t.union([keys, t.undefined]), values, name));
13
- //# sourceMappingURL=dictionary.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dictionary.js","sourceRoot":"","sources":["../../src/codecTools/dictionary.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAgB3B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAO,EACP,MAAS,EACT,IAAa,EACM,EAAE,CACrB,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC"}
@@ -1,10 +0,0 @@
1
- export * from './decodeCodec.js';
2
- export * from './dictionary.js';
3
- export * from './FixedLengthString.js';
4
- export * from './FixedLengthArray.js';
5
- export * from './partialRecord.js';
6
- export * from './isCodecError.js';
7
- export * from './NonEmptyString.js';
8
- export * from './toJsonSchema.js';
9
- export * from './createDefaultCodec.js';
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/codecTools/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
@@ -1,10 +0,0 @@
1
- export * from './decodeCodec.js';
2
- export * from './dictionary.js';
3
- export * from './FixedLengthString.js';
4
- export * from './FixedLengthArray.js';
5
- export * from './partialRecord.js';
6
- export * from './isCodecError.js';
7
- export * from './NonEmptyString.js';
8
- export * from './toJsonSchema.js';
9
- export * from './createDefaultCodec.js';
10
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/codecTools/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Checks the error message to see if it is an io-ts codec error
3
- * @param err - The error obj
4
- * @returns whether it is a io-ts codec error
5
- */
6
- export declare function isCodecError(err: Error): boolean;
7
- //# sourceMappingURL=isCodecError.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isCodecError.d.ts","sourceRoot":"","sources":["../../src/codecTools/isCodecError.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,KAAK,GAAG,OAAO,CAEhD"}
@@ -1,9 +0,0 @@
1
- /**
2
- * Checks the error message to see if it is an io-ts codec error
3
- * @param err - The error obj
4
- * @returns whether it is a io-ts codec error
5
- */
6
- export function isCodecError(err) {
7
- return err.message.startsWith('Failed to decode codec');
8
- }
9
- //# sourceMappingURL=isCodecError.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isCodecError.js","sourceRoot":"","sources":["../../src/codecTools/isCodecError.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,GAAU;IACrC,OAAO,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC;AAC1D,CAAC"}
@@ -1,16 +0,0 @@
1
- import * as t from 'io-ts';
2
- export interface PartialRecordC<D extends t.Mixed, C extends t.Mixed> extends t.DictionaryType<D, C, {
3
- [K in t.TypeOf<D>]?: t.TypeOf<C>;
4
- }, {
5
- [K in t.OutputOf<D>]?: t.OutputOf<C>;
6
- }, unknown> {
7
- }
8
- /**
9
- * Like t.record, but where the keys are all optional to include
10
- * @param domain - The key type, like `'a' | 'b' | 'c'`. In this example, 0 or more of those keys would need to be present.
11
- * @param codomain - The value type
12
- * @param name - The optional name of the record type
13
- * @returns an io-ts compatible type
14
- */
15
- export declare const partialRecord: <D extends t.Mixed, C extends t.Mixed>(domain: D, codomain: C, name?: string) => PartialRecordC<D, C>;
16
- //# sourceMappingURL=partialRecord.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"partialRecord.d.ts","sourceRoot":"","sources":["../../src/codecTools/partialRecord.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAG3B,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,CAAC,SAAS,CAAC,CAAC,KAAK,CAClE,SAAQ,CAAC,CAAC,cAAc,CACtB,CAAC,EACD,CAAC,EACD;KACG,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;CACjC,EACD;KACG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;CACrC,EACD,OAAO,CACR;CAAG;AAEN;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,wEAGjB,MAAM,yBAMuB,CAAC"}
@@ -1,11 +0,0 @@
1
- // external
2
- import * as t from 'io-ts';
3
- /**
4
- * Like t.record, but where the keys are all optional to include
5
- * @param domain - The key type, like `'a' | 'b' | 'c'`. In this example, 0 or more of those keys would need to be present.
6
- * @param codomain - The value type
7
- * @param name - The optional name of the record type
8
- * @returns an io-ts compatible type
9
- */
10
- export const partialRecord = (domain, codomain, name) => t.record(t.union([domain, t.undefined]), codomain, name);
11
- //# sourceMappingURL=partialRecord.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"partialRecord.js","sourceRoot":"","sources":["../../src/codecTools/partialRecord.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAgB3B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,MAAS,EACT,QAAW,EACX,IAAa,EACS,EAAE,CACxB,CAAC,CAAC,MAAM,CACN,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAC9B,QAAQ,EACR,IAAI,CAC8B,CAAC"}
@@ -1,11 +0,0 @@
1
- import type { JSONSchema7 } from 'json-schema';
2
- /**
3
- * Convert an io-ts codec to a JSON Schema (v7)
4
- * @param _type - an io-ts codec
5
- * @param strict - whether to enable strict mode
6
- * @param alwaysIncludeRequired - whether to always include required fields (OpenAI requires this)
7
- * @returns a JSON schema object
8
- * @see https://json-schema.org/understanding-json-schema/basics.html
9
- */
10
- export declare const toJsonSchema: (_type: any, strict?: boolean, alwaysIncludeRequired?: boolean) => JSONSchema7;
11
- //# sourceMappingURL=toJsonSchema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"toJsonSchema.d.ts","sourceRoot":"","sources":["../../src/codecTools/toJsonSchema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAsB/C;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,UAChB,GAAG,wDAGT,WA0HF,CAAC"}
@@ -1,115 +0,0 @@
1
- /**
2
- * Convert an io-ts codec to a JSON Schema (v7)
3
- * @param _type - an io-ts codec
4
- * @param strict - whether to enable strict mode
5
- * @param alwaysIncludeRequired - whether to always include required fields (OpenAI requires this)
6
- * @returns a JSON schema object
7
- * @see https://json-schema.org/understanding-json-schema/basics.html
8
- */
9
- export const toJsonSchema = (_type, strict = false, alwaysIncludeRequired = false) => {
10
- const type = _type;
11
- if (type._tag === 'StringType') {
12
- return { type: 'string' };
13
- }
14
- if (type._tag === 'NumberType') {
15
- return { type: 'number' };
16
- }
17
- if (type._tag === 'NullType') {
18
- return { type: 'null' };
19
- }
20
- if (type._tag === 'BooleanType') {
21
- return { type: 'boolean' };
22
- }
23
- if (type._tag === 'LiteralType') {
24
- return { const: type.value };
25
- }
26
- if (type._tag === 'KeyofType') {
27
- return { type: 'string', enum: Object.keys(type.keys) };
28
- }
29
- if (type._tag === 'UnionType') {
30
- return {
31
- anyOf: type.types.map((t) => toJsonSchema(t, strict, alwaysIncludeRequired)),
32
- };
33
- }
34
- if (type._tag === 'IntersectionType' && !alwaysIncludeRequired) {
35
- return {
36
- allOf: type.types.map((t) => toJsonSchema(t, strict, alwaysIncludeRequired)),
37
- };
38
- }
39
- if (type._tag === 'IntersectionType' && alwaysIncludeRequired) {
40
- const results = type.types.map((t) => toJsonSchema(t, strict, alwaysIncludeRequired));
41
- if (!results.every((r) => r.type === 'object')) {
42
- throw new Error('InterfaceType must have all children as type=object');
43
- }
44
- return {
45
- type: 'object',
46
- required: results.map((r) => r.required).flat(),
47
- properties: results.reduce((acc, r) => ({ ...acc, ...r.properties }), {}),
48
- ...(strict ? { additionalProperties: false } : {}),
49
- };
50
- }
51
- if (type._tag === 'InterfaceType') {
52
- return {
53
- type: 'object',
54
- required: Object.keys(type.props),
55
- properties: Object.fromEntries(Object.entries(type.props).map(([key, subtype]) => [
56
- key,
57
- toJsonSchema(subtype, strict, alwaysIncludeRequired),
58
- ])),
59
- ...(strict ? { additionalProperties: false } : {}),
60
- };
61
- }
62
- if (type._tag === 'DictionaryType') {
63
- return {
64
- type: 'object',
65
- additionalProperties: toJsonSchema(type.codomain, strict, alwaysIncludeRequired),
66
- };
67
- }
68
- if (type._tag === 'PartialType') {
69
- return {
70
- type: 'object',
71
- ...(alwaysIncludeRequired ? { required: Object.keys(type.props) } : {}),
72
- properties: Object.fromEntries(Object.entries(type.props).map(([key, subtype]) => {
73
- const result = toJsonSchema(subtype, strict, alwaysIncludeRequired);
74
- return [
75
- key,
76
- alwaysIncludeRequired && result.type
77
- ? {
78
- ...result,
79
- type: [result.type, 'null'],
80
- }
81
- : result,
82
- ];
83
- })),
84
- ...(strict ? { additionalProperties: false } : {}),
85
- };
86
- }
87
- if (type._tag === 'ArrayType') {
88
- return {
89
- type: 'array',
90
- items: toJsonSchema(type.type, strict, alwaysIncludeRequired),
91
- };
92
- }
93
- if (type._tag === 'TupleType') {
94
- return {
95
- type: 'array',
96
- items: type.types.map((t) => toJsonSchema(t, strict, alwaysIncludeRequired)),
97
- };
98
- }
99
- if (type._tag === 'RefinementType') {
100
- if (type.name === 'Int') {
101
- return { type: 'integer' };
102
- }
103
- return {
104
- ...toJsonSchema(type.type, strict, alwaysIncludeRequired),
105
- description: `Predicate: ${type.predicate.name || type.name}`,
106
- };
107
- }
108
- // could add more here for DateFromISOString, etc. etc.
109
- return unhandledType(type);
110
- };
111
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-unused-vars
112
- const unhandledType = (_shouldBeNever) => ({});
113
- /* eslint-enable @typescript-eslint/no-explicit-any */
114
- /* eslint-enable no-underscore-dangle */
115
- //# sourceMappingURL=toJsonSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"toJsonSchema.js","sourceRoot":"","sources":["../../src/codecTools/toJsonSchema.ts"],"names":[],"mappings":"AAyBA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,KAAU,EACV,MAAM,GAAG,KAAK,EACd,qBAAqB,GAAG,KAAK,EAChB,EAAE;IACf,MAAM,IAAI,GAAG,KAAqB,CAAC;IAEnC,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAC/B,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC5B,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAC/B,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC5B,CAAC;IACD,IAAI,IAAI,CAA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AAO;YACb,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAC/B,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,qBAAqB,CAAC,CAC/C;SACF,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;QACnC,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACxB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC7B,CAAC;QACD,OAAO;YACL,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,qBAAqB,CAAC;YACzD,WAAW,EAAE,cAAc,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE;SAC9D,CAAC;IACJ,CAAC;IACD,uDAAuD;IACvD,OAAO,aAAa,CAAC,IAAa,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF,+GAA+G;AAC/G,MAAM,aAAa,GAAG,CAAC,cAAqB,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AAEtD,sDAAsD;AACtD,wCAAwC"}
package/build/enum.d.ts DELETED
@@ -1,47 +0,0 @@
1
- import type { ObjByString } from './types.js';
2
- /**
3
- * An enumerated value
4
- */
5
- export type Enumerate<T = string, TKey extends string = string> = {
6
- [key in TKey]: T;
7
- };
8
- /**
9
- * An enum declared in typescript. We require all values to be strings
10
- */
11
- export type TypescriptEnum = {
12
- [key in string]: string;
13
- } | {
14
- [key in number]: string;
15
- };
16
- /**
17
- * An input when defining an enum can be an object of string -> string or a list of strings
18
- */
19
- export type EnumInput<T, TKey extends string = string> = Enumerate<T, TKey> | string[];
20
- /**
21
- * Convert a list of strings to an "enum" object
22
- * @param attributes - The attributes of the enum
23
- * @returns The input to become an enum
24
- */
25
- export declare function listToEnum(attributes: string[]): Enumerate<string>;
26
- /**
27
- * Create an enum object with a proxy handler that will throw an error when a property is access that is not in the enum
28
- * @param attributes - The enums to merge into a single enum (all properties)
29
- * @returns The object proxy with error logger when a value is accessed outside of enum
30
- */
31
- export declare function createEnum<T = string, TKey extends string = string>(...attributes: EnumInput<T, TKey>[]): Enumerate<T, TKey>;
32
- /**
33
- * Filter an enum and return the keys that remain
34
- * @param obj - The object to filter
35
- * @param filterFunc - The function to filter the enum key/values by
36
- * @returns The object keys that remained
37
- */
38
- export declare function filterEnum<T extends ObjByString>(obj: T, filterFunc: (val: T[keyof T], key: keyof T, calculatedEnum: Enumerate<T[keyof T]>) => boolean): (keyof T)[];
39
- /**
40
- * Make an enum compatible with types -- in separate file because Logger/enums and Enum/index circular dependency
41
- * @param x - The enum
42
- * @returns The object proxy with error logger when a value is accessed outside of enum
43
- */
44
- export declare function makeEnum<T extends {
45
- [index: string]: U | U[];
46
- }, U extends string>(x: T): T;
47
- //# sourceMappingURL=enum.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../src/enum.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,MAAM,EAAE,IAAI,SAAS,MAAM,GAAG,MAAM,IAAI;KAC/D,GAAG,IAAI,IAAI,GAAG,CAAC;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB;KAAG,GAAG,IAAI,MAAM,GAAG,MAAM;CAAE,GAC3B;KAAG,GAAG,IAAI,MAAM,GAAG,MAAM;CAAE,CAAC;AAEhC;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,IAAI,SAAS,MAAM,GAAG,MAAM,IACjD,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,GAClB,MAAM,EAAE,CAAC;AAEb;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,CAMlE;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,GAAG,MAAM,EAAE,IAAI,SAAS,MAAM,GAAG,MAAM,EACjE,GAAG,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,GAClC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,CAOpB;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,WAAW,EAC9C,GAAG,EAAE,CAAC,EACN,UAAU,EAAE,CACV,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EACf,GAAG,EAAE,MAAM,CAAC,EACZ,cAAc,EAAE,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAClC,OAAO,GACX,CAAC,MAAM,CAAC,CAAC,EAAE,CAQb;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,CAAC,SAAS;IAAE,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,CAAC,EAAE,CAAA;CAAE,EACtC,CAAC,SAAS,MAAM,EAChB,CAAC,EAAE,CAAC,GAAG,CAAC,CAET"}
package/build/enum.js DELETED
@@ -1,44 +0,0 @@
1
- /**
2
- * Convert a list of strings to an "enum" object
3
- * @param attributes - The attributes of the enum
4
- * @returns The input to become an enum
5
- */
6
- export function listToEnum(attributes) {
7
- const init = {};
8
- return attributes.reduce((acc, val) => {
9
- acc[val] = val;
10
- return acc;
11
- }, init);
12
- }
13
- /**
14
- * Create an enum object with a proxy handler that will throw an error when a property is access that is not in the enum
15
- * @param attributes - The enums to merge into a single enum (all properties)
16
- * @returns The object proxy with error logger when a value is accessed outside of enum
17
- */
18
- export function createEnum(...attributes) {
19
- // Convert all to enums to objects
20
- const objAttributes = attributes.map((attrs) => Array.isArray(attrs) ? listToEnum(attrs) : attrs);
21
- return Object.assign({}, ...objAttributes);
22
- }
23
- /**
24
- * Filter an enum and return the keys that remain
25
- * @param obj - The object to filter
26
- * @param filterFunc - The function to filter the enum key/values by
27
- * @returns The object keys that remained
28
- */
29
- export function filterEnum(obj, filterFunc) {
30
- return (Object.keys(obj)
31
- // Filter by value
32
- .filter((key) => filterFunc(obj[key], key, obj))
33
- // Return keys
34
- .map((key) => key));
35
- }
36
- /**
37
- * Make an enum compatible with types -- in separate file because Logger/enums and Enum/index circular dependency
38
- * @param x - The enum
39
- * @returns The object proxy with error logger when a value is accessed outside of enum
40
- */
41
- export function makeEnum(x) {
42
- return x;
43
- }
44
- //# sourceMappingURL=enum.js.map
package/build/enum.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"enum.js","sourceRoot":"","sources":["../src/enum.ts"],"names":[],"mappings":"AAwBA;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,UAAoB;IAC7C,MAAM,IAAI,GAAsB,EAAE,CAAC;IACnC,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QACpC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;QACf,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,IAAI,CAAC,CAAC;AACX,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CACxB,GAAG,UAAgC;IAEnC,kCAAkC;IAClC,MAAM,aAAa,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAC7C,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CACjD,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,aAAa,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CACxB,GAAM,EACN,UAIY;IAEZ,OAAO,CACJ,MAAM,CAAC,IAAI,CAAC,GAAG,CAAiB;QAC/B,kBAAkB;SACjB,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QAChD,cAAc;SACb,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CACrB,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAGtB,CAAI;IACJ,OAAO,CAAC,CAAC;AACX,CAAC"}
package/build/enums.d.ts DELETED
@@ -1,20 +0,0 @@
1
- /**
2
- * The http method types
3
- */
4
- export declare const HttpMethod: {
5
- /** A get request */
6
- Get: "GET";
7
- /** A post request */
8
- Post: "POST";
9
- /** A delete request */
10
- Delete: "DELETE";
11
- /** A put request */
12
- Put: "PUT";
13
- /** A patch request */
14
- Patch: "PATCH";
15
- };
16
- /**
17
- * Override to cast as string
18
- */
19
- export type HttpMethod = (typeof HttpMethod)[keyof typeof HttpMethod];
20
- //# sourceMappingURL=enums.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enums.d.ts","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,UAAU;IACrB,oBAAoB;;IAEpB,qBAAqB;;IAErB,uBAAuB;;IAEvB,oBAAoB;;IAEpB,sBAAsB;;CAEtB,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC"}
package/build/enums.js DELETED
@@ -1,18 +0,0 @@
1
- // local
2
- import { makeEnum } from './enum.js';
3
- /**
4
- * The http method types
5
- */
6
- export const HttpMethod = makeEnum({
7
- /** A get request */
8
- Get: 'GET',
9
- /** A post request */
10
- Post: 'POST',
11
- /** A delete request */
12
- Delete: 'DELETE',
13
- /** A put request */
14
- Put: 'PUT',
15
- /** A patch request */
16
- Patch: 'PATCH',
17
- });
18
- //# sourceMappingURL=enums.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"enums.js","sourceRoot":"","sources":["../src/enums.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC;IACjC,oBAAoB;IACpB,GAAG,EAAE,KAAK;IACV,qBAAqB;IACrB,IAAI,EAAE,MAAM;IACZ,uBAAuB;IACvB,MAAM,EAAE,QAAQ;IAChB,oBAAoB;IACpB,GAAG,EAAE,KAAK;IACV,sBAAsB;IACtB,KAAK,EAAE,OAAO;CACf,CAAC,CAAC"}
@@ -1,41 +0,0 @@
1
- /**
2
- * The full match returned when regex.exec finds a match
3
- */
4
- export interface RegExpMatch {
5
- /** The full regex match */
6
- fullMatch: string;
7
- /** The index in the text where the match was found */
8
- matchIndex: number;
9
- /** When a strict regex is provided, check if the regex matches the strict standard */
10
- isStrict?: boolean;
11
- }
12
- /**
13
- * Use a regex with the 'g' global flag to list all items in a file. Can then map the matches back to object parameters
14
- */
15
- export interface FindAllRegExp<TMatchKeys extends string> {
16
- /** The regex to test */
17
- value: RegExp;
18
- /**
19
- * A RegExp that is stricter than `value` and can be used to test if the definition matches a certain standard.
20
- *
21
- * i.e. I may have a loose match for jsdoc properties but I want a stricter standard for linting them
22
- */
23
- strict?: RegExp;
24
- /**
25
- * The match groups in the regex will map to these object attributes.
26
- * If there are more match groups than matches, an error is thrown
27
- */
28
- matches: TMatchKeys[];
29
- /** When true, skip validation of matches being the expected length */
30
- skipMatchValidation?: boolean;
31
- }
32
- /**
33
- * Use a regex with the global flag to find all matches and return the list of matches with match groups mapped to parameter names
34
- * @param regex - The regex definition and match attributes
35
- * @param text - The text to find all in
36
- * @returns The matches all converted to type T
37
- */
38
- export declare function findAllWithRegex<TMatchKeys extends string>(regex: FindAllRegExp<TMatchKeys>, text: string): ({
39
- [k in TMatchKeys]: string;
40
- } & RegExpMatch)[];
41
- //# sourceMappingURL=findAllWithRegex.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"findAllWithRegex.d.ts","sourceRoot":"","sources":["../src/findAllWithRegex.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,2BAA2B;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,UAAU,EAAE,MAAM,CAAC;IACnB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,UAAU,SAAS,MAAM;IACtD,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,EAAE,UAAU,EAAE,CAAC;IACtB,sEAAsE;IACtE,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,SAAS,MAAM,EACxD,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,EAChC,IAAI,EAAE,MAAM,GACX,CAAC;KAAG,CAAC,IAAI,UAAU,GAAG,MAAM;CAAE,GAAG,WAAW,CAAC,EAAE,CAiDjD"}
@@ -1,41 +0,0 @@
1
- /**
2
- * Use a regex with the global flag to find all matches and return the list of matches with match groups mapped to parameter names
3
- * @param regex - The regex definition and match attributes
4
- * @param text - The text to find all in
5
- * @returns The matches all converted to type T
6
- */
7
- export function findAllWithRegex(regex, text) {
8
- // Validate the parameters
9
- if (!regex.value.flags.includes('g')) {
10
- throw new Error('Regex.value must have a g flag');
11
- }
12
- // The name of the match groups
13
- const matchParams = ['fullMatch', ...regex.matches];
14
- // The results
15
- const results = [];
16
- // Check for initial match
17
- let match = regex.value.exec(text);
18
- let i = 0;
19
- // Loop over all matches
20
- while (match) {
21
- // Ensure that each match is accounted for
22
- if (matchParams.length !== match.length && !regex.skipMatchValidation) {
23
- throw new Error(`Mismatch in match length at index [${i}]: "${match.length}" vs expected: "${matchParams.length}"`);
24
- }
25
- // Construct the match result and assert it is of type T & RegExpMatch
26
- const result = match.reduce((acc, matchResult, ind) => Object.assign(acc, { [matchParams[ind]]: matchResult }), {});
27
- // Save the index
28
- result.matchIndex = match.index;
29
- // Test if the strict regex passes
30
- if (regex.strict) {
31
- result.isStrict = regex.strict.test(result.fullMatch);
32
- }
33
- // Save the result
34
- results.push(result);
35
- // Check for another
36
- match = regex.value.exec(text);
37
- i += 1;
38
- }
39
- return results;
40
- }
41
- //# sourceMappingURL=findAllWithRegex.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"findAllWithRegex.js","sourceRoot":"","sources":["../src/findAllWithRegex.ts"],"names":[],"mappings":"AAiCA;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAgC,EAChC,IAAY;IAEZ,0BAA0B;IAC1B,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,+BAA+B;IAC/B,MAAM,WAAW,GAAG,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;IAEpD,cAAc;IACd,MAAM,OAAO,GAAoD,EAAE,CAAC;IAEpE,0BAA0B;IAC1B,IAAI,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,wBAAwB;IACxB,OAAO,KAAK,EAAE,CAAC;QACb,0CAA0C;QAC1C,IAAI,WAAW,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,mBAAmB,EAAE,CAAC;YACtE,MAAM,IAAI,KAAK,CACb,sCAAsC,CAAC,OAAO,KAAK,CAAC,MAAM,mBAAmB,WAAW,CAAC,MAAM,GAAG,CACnG,CAAC;QACJ,CAAC;QAED,sEAAsE;QACtE,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CACzB,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE,CACxB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EACzD,EAAE,CAC4C,CAAC;QAEjD,iBAAiB;QACjB,MAAM,CAAC,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC;QAEhC,kCAAkC;QAClC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,CAAC,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACxD,CAAC;QAED,kBAAkB;QAClB,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAErB,oBAAoB;QACpB,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC,IAAI,CAAC,CAAC;IACT,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1,33 +0,0 @@
1
- /**
2
- *
3
- * Flattens a nested object into a single-level object with concatenated key names. Useful
4
- * for converting objects to CSV.
5
- * @param param - The information about the object to flatten
6
- * @returns A flattened object where nested keys are joined with underscores
7
- * @example
8
- * const nested = {
9
- * user: {
10
- * name: 'John',
11
- * address: {
12
- * city: 'NY',
13
- * zip: 10001
14
- * },
15
- * hobbies: ['reading', 'gaming']
16
- * }
17
- * };
18
- *
19
- * flattenObject(nested)
20
- * // Returns: {
21
- * // user_name: 'John',
22
- * // user_address_city: 'NY',
23
- * // user_address_zip: 10001,
24
- * // user_hobbies: 'reading,gaming'
25
- * // }
26
- */
27
- export declare const flattenObject: ({ obj, prefix, }: {
28
- /** the object to flatten */
29
- obj: any;
30
- /** The prefix to prepend to keys (used in recursion) */
31
- prefix?: string | undefined;
32
- }) => any;
33
- //# sourceMappingURL=flattenObject.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"flattenObject.d.ts","sourceRoot":"","sources":["../src/flattenObject.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,aAAa;IAIxB,4BAA4B;SACvB,GAAG;IACR,wDAAwD;;MAEtD,GAsDG,CAAC"}