@gaearon/lex-builder 0.0.13

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 (62) hide show
  1. package/CHANGELOG.md +144 -0
  2. package/dist/filter.d.ts +7 -0
  3. package/dist/filter.d.ts.map +1 -0
  4. package/dist/filter.js +30 -0
  5. package/dist/filter.js.map +1 -0
  6. package/dist/filtered-indexer.d.ts +2100 -0
  7. package/dist/filtered-indexer.d.ts.map +1 -0
  8. package/dist/filtered-indexer.js +56 -0
  9. package/dist/filtered-indexer.js.map +1 -0
  10. package/dist/formatter.d.ts +13 -0
  11. package/dist/formatter.d.ts.map +1 -0
  12. package/dist/formatter.js +34 -0
  13. package/dist/formatter.js.map +1 -0
  14. package/dist/index.d.ts +8 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +16 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/lex-builder.d.ts +36 -0
  19. package/dist/lex-builder.d.ts.map +1 -0
  20. package/dist/lex-builder.js +144 -0
  21. package/dist/lex-builder.js.map +1 -0
  22. package/dist/lex-def-builder.d.ts +69 -0
  23. package/dist/lex-def-builder.d.ts.map +1 -0
  24. package/dist/lex-def-builder.js +734 -0
  25. package/dist/lex-def-builder.js.map +1 -0
  26. package/dist/lexicon-directory-indexer.d.ts +11 -0
  27. package/dist/lexicon-directory-indexer.d.ts.map +1 -0
  28. package/dist/lexicon-directory-indexer.js +46 -0
  29. package/dist/lexicon-directory-indexer.js.map +1 -0
  30. package/dist/polyfill.d.ts +1 -0
  31. package/dist/polyfill.d.ts.map +1 -0
  32. package/dist/polyfill.js +7 -0
  33. package/dist/polyfill.js.map +1 -0
  34. package/dist/ref-resolver.d.ts +53 -0
  35. package/dist/ref-resolver.d.ts.map +1 -0
  36. package/dist/ref-resolver.js +277 -0
  37. package/dist/ref-resolver.js.map +1 -0
  38. package/dist/ts-lang.d.ts +6 -0
  39. package/dist/ts-lang.d.ts.map +1 -0
  40. package/dist/ts-lang.js +150 -0
  41. package/dist/ts-lang.js.map +1 -0
  42. package/dist/util.d.ts +12 -0
  43. package/dist/util.d.ts.map +1 -0
  44. package/dist/util.js +72 -0
  45. package/dist/util.js.map +1 -0
  46. package/package.json +53 -0
  47. package/src/filter.ts +41 -0
  48. package/src/filtered-indexer.test.ts +84 -0
  49. package/src/filtered-indexer.ts +60 -0
  50. package/src/formatter.ts +42 -0
  51. package/src/index.ts +23 -0
  52. package/src/lex-builder.ts +186 -0
  53. package/src/lex-def-builder.ts +980 -0
  54. package/src/lexicon-directory-indexer.ts +52 -0
  55. package/src/polyfill.ts +7 -0
  56. package/src/ref-resolver.test.ts +75 -0
  57. package/src/ref-resolver.ts +368 -0
  58. package/src/ts-lang.ts +150 -0
  59. package/src/util.ts +72 -0
  60. package/tsconfig.build.json +13 -0
  61. package/tsconfig.json +7 -0
  62. package/tsconfig.tests.json +9 -0
package/src/util.ts ADDED
@@ -0,0 +1,72 @@
1
+ import { relative } from 'node:path'
2
+
3
+ export function memoize<T extends (arg: string) => NonNullable<unknown> | null>(
4
+ fn: T,
5
+ ): T {
6
+ const cache = new Map<string, NonNullable<unknown> | null>()
7
+ return ((arg: string) => {
8
+ const cached = cache.get(arg)
9
+ if (cached !== undefined) return cached
10
+ const result = fn(arg)
11
+ cache.set(arg, result)
12
+ return result
13
+ }) as T
14
+ }
15
+
16
+ export function startsWithLower(str: string) {
17
+ const code = str.charCodeAt(0)
18
+ return code >= 97 && code <= 122 // 'a' to 'z'
19
+ }
20
+
21
+ export function ucFirst(str: string) {
22
+ return str.charAt(0).toUpperCase() + str.slice(1)
23
+ }
24
+
25
+ export function lcFirst(str: string) {
26
+ return str.charAt(0).toLowerCase() + str.slice(1)
27
+ }
28
+
29
+ export function toPascalCase(str: string): string {
30
+ return extractWords(str).map(toLowerCase).map(ucFirst).join('')
31
+ }
32
+
33
+ export function toCamelCase(str: string): string {
34
+ return lcFirst(toPascalCase(str))
35
+ }
36
+
37
+ export function toConstantCase(str: string): string {
38
+ return extractWords(str).map(toUpperCase).join('_')
39
+ }
40
+
41
+ export function toLowerCase(str: string): string {
42
+ return str.toLowerCase()
43
+ }
44
+
45
+ export function toUpperCase(str: string): string {
46
+ return str.toUpperCase()
47
+ }
48
+
49
+ function extractWords(str: string): string[] {
50
+ const processedStr = str
51
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2') // split camelCase
52
+ .replace(/([A-Z])([A-Z][a-z])/g, '$1 $2') // split ALLCAPSWords
53
+ .replace(/([0-9])([A-Za-z])/g, '$1 $2') // split number followed by letter
54
+ .replace(/[^a-zA-Z0-9]+/g, ' ') // replace non-alphanumeric with space
55
+ .trim() // trim leading/trailing spaces
56
+
57
+ return processedStr
58
+ ? processedStr.split(/\s+/) // split by spaces
59
+ : [] // Avoid returning [''] for empty strings
60
+ }
61
+
62
+ export function asRelativePath(from: string, to: string) {
63
+ const relPath = relative(from, to)
64
+ return relPath.startsWith('./') || relPath.startsWith('../')
65
+ ? relPath
66
+ : `./${relPath}`
67
+ }
68
+
69
+ export function startsWithDigit(str: string) {
70
+ const code = str.charCodeAt(0)
71
+ return code >= 48 && code <= 57 // '0' to '9'
72
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": ["../../../tsconfig/node.json"],
3
+ "include": ["./src"],
4
+ "exclude": ["**/*.test.ts"],
5
+ "compilerOptions": {
6
+ "noImplicitAny": true,
7
+ "importHelpers": true,
8
+ "target": "ES2023",
9
+ "rootDir": "./src",
10
+ "outDir": "./dist",
11
+ "types": ["node"]
12
+ }
13
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "include": [],
3
+ "references": [
4
+ { "path": "./tsconfig.build.json" },
5
+ { "path": "./tsconfig.tests.json" }
6
+ ]
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../../tsconfig/vitest.json",
3
+ "include": ["./tests", "./src/**/*.test.ts"],
4
+ "compilerOptions": {
5
+ "noImplicitAny": true,
6
+ "rootDir": "./",
7
+ "baseUrl": "./"
8
+ }
9
+ }