@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.
- package/CHANGELOG.md +144 -0
- package/dist/filter.d.ts +7 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +30 -0
- package/dist/filter.js.map +1 -0
- package/dist/filtered-indexer.d.ts +2100 -0
- package/dist/filtered-indexer.d.ts.map +1 -0
- package/dist/filtered-indexer.js +56 -0
- package/dist/filtered-indexer.js.map +1 -0
- package/dist/formatter.d.ts +13 -0
- package/dist/formatter.d.ts.map +1 -0
- package/dist/formatter.js +34 -0
- package/dist/formatter.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/lex-builder.d.ts +36 -0
- package/dist/lex-builder.d.ts.map +1 -0
- package/dist/lex-builder.js +144 -0
- package/dist/lex-builder.js.map +1 -0
- package/dist/lex-def-builder.d.ts +69 -0
- package/dist/lex-def-builder.d.ts.map +1 -0
- package/dist/lex-def-builder.js +734 -0
- package/dist/lex-def-builder.js.map +1 -0
- package/dist/lexicon-directory-indexer.d.ts +11 -0
- package/dist/lexicon-directory-indexer.d.ts.map +1 -0
- package/dist/lexicon-directory-indexer.js +46 -0
- package/dist/lexicon-directory-indexer.js.map +1 -0
- package/dist/polyfill.d.ts +1 -0
- package/dist/polyfill.d.ts.map +1 -0
- package/dist/polyfill.js +7 -0
- package/dist/polyfill.js.map +1 -0
- package/dist/ref-resolver.d.ts +53 -0
- package/dist/ref-resolver.d.ts.map +1 -0
- package/dist/ref-resolver.js +277 -0
- package/dist/ref-resolver.js.map +1 -0
- package/dist/ts-lang.d.ts +6 -0
- package/dist/ts-lang.d.ts.map +1 -0
- package/dist/ts-lang.js +150 -0
- package/dist/ts-lang.js.map +1 -0
- package/dist/util.d.ts +12 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +72 -0
- package/dist/util.js.map +1 -0
- package/package.json +53 -0
- package/src/filter.ts +41 -0
- package/src/filtered-indexer.test.ts +84 -0
- package/src/filtered-indexer.ts +60 -0
- package/src/formatter.ts +42 -0
- package/src/index.ts +23 -0
- package/src/lex-builder.ts +186 -0
- package/src/lex-def-builder.ts +980 -0
- package/src/lexicon-directory-indexer.ts +52 -0
- package/src/polyfill.ts +7 -0
- package/src/ref-resolver.test.ts +75 -0
- package/src/ref-resolver.ts +368 -0
- package/src/ts-lang.ts +150 -0
- package/src/util.ts +72 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.json +7 -0
- 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