@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/CHANGELOG.md ADDED
@@ -0,0 +1,144 @@
1
+ # @atproto/lex-builder
2
+
3
+ ## 0.0.13
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @atproto/lex-document@0.0.12
9
+ - @atproto/lex-schema@0.0.11
10
+
11
+ ## 0.0.12
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [[`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`99963d0`](https://github.com/bluesky-social/atproto/commit/99963d002a9e030e79aed5fba700e0a68f31e101), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b), [`7310b97`](https://github.com/bluesky-social/atproto/commit/7310b9704de678a3b389a741784d58bb7f79b10b)]:
16
+ - @atproto/lex-schema@0.0.10
17
+ - @atproto/lex-document@0.0.11
18
+
19
+ ## 0.0.11
20
+
21
+ ### Patch Changes
22
+
23
+ - Updated dependencies []:
24
+ - @atproto/lex-document@0.0.10
25
+ - @atproto/lex-schema@0.0.9
26
+
27
+ ## 0.0.10
28
+
29
+ ### Patch Changes
30
+
31
+ - [#4512](https://github.com/bluesky-social/atproto/pull/4512) [`d78484f`](https://github.com/bluesky-social/atproto/commit/d78484f94d8ba1352ec66030115000d515c9dafe) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Improve naming of exported types
32
+
33
+ - Updated dependencies [[`d78484f`](https://github.com/bluesky-social/atproto/commit/d78484f94d8ba1352ec66030115000d515c9dafe), [`d78484f`](https://github.com/bluesky-social/atproto/commit/d78484f94d8ba1352ec66030115000d515c9dafe)]:
34
+ - @atproto/lex-schema@0.0.8
35
+ - @atproto/lex-document@0.0.9
36
+
37
+ ## 0.0.9
38
+
39
+ ### Patch Changes
40
+
41
+ - [#4501](https://github.com/bluesky-social/atproto/pull/4501) [`2f78893`](https://github.com/bluesky-social/atproto/commit/2f78893ace3bbf14d4bac36837820ddb46658c98) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Better prevent use of conflicting identifiers in generated code
42
+
43
+ - [#4501](https://github.com/bluesky-social/atproto/pull/4501) [`2f78893`](https://github.com/bluesky-social/atproto/commit/2f78893ace3bbf14d4bac36837820ddb46658c98) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add an `indexFile` option that allows generating an "index.ts" file that re-exports every tld namespaces.
44
+
45
+ - [#4501](https://github.com/bluesky-social/atproto/pull/4501) [`2f78893`](https://github.com/bluesky-social/atproto/commit/2f78893ace3bbf14d4bac36837820ddb46658c98) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Ensure generated "import" identifiers start with a lower case letter
46
+
47
+ - [#4501](https://github.com/bluesky-social/atproto/pull/4501) [`2f78893`](https://github.com/bluesky-social/atproto/commit/2f78893ace3bbf14d4bac36837820ddb46658c98) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Avoid escaping export identifier when it is a known global
48
+
49
+ - Updated dependencies [[`2f78893`](https://github.com/bluesky-social/atproto/commit/2f78893ace3bbf14d4bac36837820ddb46658c98)]:
50
+ - @atproto/lex-schema@0.0.7
51
+ - @atproto/lex-document@0.0.8
52
+
53
+ ## 0.0.8
54
+
55
+ ### Patch Changes
56
+
57
+ - [#4443](https://github.com/bluesky-social/atproto/pull/4443) [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Use `jsonPayload` for json payloads
58
+
59
+ - Updated dependencies [[`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c), [`9af7a2d`](https://github.com/bluesky-social/atproto/commit/9af7a2d12240e91248610ce4fe7d93387733c59c)]:
60
+ - @atproto/lex-schema@0.0.6
61
+ - @atproto/lex-document@0.0.7
62
+
63
+ ## 0.0.7
64
+
65
+ ### Patch Changes
66
+
67
+ - [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Refactor JSDoc generation to use ts-morph's native `JSDocStructure`
68
+
69
+ - [#4457](https://github.com/bluesky-social/atproto/pull/4457) [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Build additional `$lxm` utility variable for xrpc methods
70
+
71
+ - Updated dependencies [[`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece), [`e6b6107`](https://github.com/bluesky-social/atproto/commit/e6b6107e028fee964972274b71f5da1329a7bece)]:
72
+ - @atproto/lex-schema@0.0.5
73
+ - @atproto/lex-document@0.0.6
74
+
75
+ ## 0.0.6
76
+
77
+ ### Patch Changes
78
+
79
+ - [#4413](https://github.com/bluesky-social/atproto/pull/4413) [`e39ca11`](https://github.com/bluesky-social/atproto/commit/e39ca114accac65070dcdd424a181821aad6d99d) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add support for NodeJS version <18.18, 19.x, <20.4 and 21.x
80
+
81
+ - Updated dependencies [[`d551b0e`](https://github.com/bluesky-social/atproto/commit/d551b0e3527714c111c3ec6e4c90ad7f46369fab)]:
82
+ - @atproto/lex-document@0.0.5
83
+ - @atproto/lex-schema@0.0.4
84
+
85
+ ## 0.0.5
86
+
87
+ ### Patch Changes
88
+
89
+ - [#4390](https://github.com/bluesky-social/atproto/pull/4390) [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rework object validation logic to work without `options` argument
90
+
91
+ - [#4390](https://github.com/bluesky-social/atproto/pull/4390) [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Use `l.nullable` for nullable object properties and `l.optional` for optional object properties in lex schemas.
92
+
93
+ - [#4390](https://github.com/bluesky-social/atproto/pull/4390) [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Replace use of `CID` with `Cid`
94
+
95
+ - [#4389](https://github.com/bluesky-social/atproto/pull/4389) [`bcae2b7`](https://github.com/bluesky-social/atproto/commit/bcae2b77b68da6dc2ec202651c8bf41fd5769f69) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Use string formats from `@atproto/syntax`
96
+
97
+ - [#4390](https://github.com/bluesky-social/atproto/pull/4390) [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Remove `knownValues` from string options (as it had not runtime effect)
98
+
99
+ - [#4390](https://github.com/bluesky-social/atproto/pull/4390) [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Rename schema methods `validate`, `check` and `maybe` to `safeParse`, `matches` and `ifMatches` respectively.
100
+
101
+ - [#4397](https://github.com/bluesky-social/atproto/pull/4397) [`688f9d6`](https://github.com/bluesky-social/atproto/commit/688f9d67597ba96d6e9c4a4aec4d394d42f4cbf4) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `CHANGELOG.md` to npm package
102
+
103
+ - [#4398](https://github.com/bluesky-social/atproto/pull/4398) [`a17d2e8`](https://github.com/bluesky-social/atproto/commit/a17d2e8a59ceb00fa8197642e0767fcc776d5b70) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `ignoreInvalidLexicons` option when building lexicon schemas
104
+
105
+ - [#4390](https://github.com/bluesky-social/atproto/pull/4390) [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Strip unknown properties from schema options
106
+
107
+ - [#4390](https://github.com/bluesky-social/atproto/pull/4390) [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add `default` option to `const` and `enum` schemas
108
+
109
+ - Updated dependencies [[`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`a487ab8`](https://github.com/bluesky-social/atproto/commit/a487ab8afe8f18d00662e666049be8d28de2b57e), [`a487ab8`](https://github.com/bluesky-social/atproto/commit/a487ab8afe8f18d00662e666049be8d28de2b57e), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`bcae2b7`](https://github.com/bluesky-social/atproto/commit/bcae2b77b68da6dc2ec202651c8bf41fd5769f69), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`a487ab8`](https://github.com/bluesky-social/atproto/commit/a487ab8afe8f18d00662e666049be8d28de2b57e), [`a487ab8`](https://github.com/bluesky-social/atproto/commit/a487ab8afe8f18d00662e666049be8d28de2b57e), [`03a2a4b`](https://github.com/bluesky-social/atproto/commit/03a2a4bb3814ced7ad1d4fe6c94b5348a3bbc097), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`bcae2b7`](https://github.com/bluesky-social/atproto/commit/bcae2b77b68da6dc2ec202651c8bf41fd5769f69), [`bcae2b7`](https://github.com/bluesky-social/atproto/commit/bcae2b77b68da6dc2ec202651c8bf41fd5769f69), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`a487ab8`](https://github.com/bluesky-social/atproto/commit/a487ab8afe8f18d00662e666049be8d28de2b57e), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`9f87ff3`](https://github.com/bluesky-social/atproto/commit/9f87ff3aa60090c8c38b6ce400cba6ceff5cd2e9), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba), [`688f9d6`](https://github.com/bluesky-social/atproto/commit/688f9d67597ba96d6e9c4a4aec4d394d42f4cbf4), [`1d445af`](https://github.com/bluesky-social/atproto/commit/1d445af2a7fc27eca5a45869b29266e6a2a7f3ba)]:
110
+ - @atproto/lex-schema@0.0.3
111
+ - @atproto/lex-document@0.0.4
112
+
113
+ ## 0.0.4
114
+
115
+ ### Patch Changes
116
+
117
+ - [#4380](https://github.com/bluesky-social/atproto/pull/4380) [`23c271f`](https://github.com/bluesky-social/atproto/commit/23c271fcac27f090727e2f835697d4733784bdb4) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Add ability to configure file extenstion and import file extension in `lex build`
118
+
119
+ - Updated dependencies [[`23c271f`](https://github.com/bluesky-social/atproto/commit/23c271fcac27f090727e2f835697d4733784bdb4)]:
120
+ - @atproto/lex-schema@0.0.2
121
+ - @atproto/lex-document@0.0.3
122
+
123
+ ## 0.0.3
124
+
125
+ ### Patch Changes
126
+
127
+ - Updated dependencies [[`5ffd612`](https://github.com/bluesky-social/atproto/commit/5ffd6129909071e979c30f31266119865ab582b6)]:
128
+ - @atproto/lex-document@0.0.2
129
+
130
+ ## 0.0.2
131
+
132
+ ### Patch Changes
133
+
134
+ - [#4372](https://github.com/bluesky-social/atproto/pull/4372) [`7456f53`](https://github.com/bluesky-social/atproto/commit/7456f53e45fb3eef2f3bbdf2513da2d8ab078d80) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Fix error when running `install` command
135
+
136
+ ## 0.0.1
137
+
138
+ ### Patch Changes
139
+
140
+ - [#4371](https://github.com/bluesky-social/atproto/pull/4371) [`46550d6`](https://github.com/bluesky-social/atproto/commit/46550d6c1ffb298f57d54eb1904067b2df5a40af) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Release
141
+
142
+ - Updated dependencies [[`46550d6`](https://github.com/bluesky-social/atproto/commit/46550d6c1ffb298f57d54eb1904067b2df5a40af)]:
143
+ - @atproto/lex-document@0.0.1
144
+ - @atproto/lex-schema@0.0.1
@@ -0,0 +1,7 @@
1
+ export type BuildFilterOptions = {
2
+ include?: string | string[];
3
+ exclude?: string | string[];
4
+ };
5
+ export type Filter = (input: string) => boolean;
6
+ export declare function buildFilter(options: BuildFilterOptions): Filter;
7
+ //# sourceMappingURL=filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;IAC3B,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;AAE/C,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAK/D"}
package/dist/filter.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildFilter = buildFilter;
4
+ function buildFilter(options) {
5
+ const include = createMatcher(options.include, () => true);
6
+ const exclude = createMatcher(options.exclude, () => false);
7
+ return (id) => include(id) && !exclude(id);
8
+ }
9
+ function createMatcher(pattern, fallback) {
10
+ if (!pattern?.length) {
11
+ return fallback;
12
+ }
13
+ else if (Array.isArray(pattern)) {
14
+ return pattern.map(buildMatcher).reduce(combineFilters);
15
+ }
16
+ else {
17
+ return buildMatcher(pattern);
18
+ }
19
+ }
20
+ function combineFilters(a, b) {
21
+ return (input) => a(input) || b(input);
22
+ }
23
+ function buildMatcher(pattern) {
24
+ if (pattern.includes('*')) {
25
+ const regex = new RegExp(`^${pattern.replaceAll('.', '\\.').replaceAll('*', '.+')}$`);
26
+ return (input) => regex.test(input);
27
+ }
28
+ return (input) => pattern === input;
29
+ }
30
+ //# sourceMappingURL=filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.js","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":";;AAOA,kCAKC;AALD,SAAgB,WAAW,CAAC,OAA2B;IACrD,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;IAC1D,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;IAE3D,OAAO,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;AAC5C,CAAC;AAED,SAAS,aAAa,CACpB,OAAsC,EACtC,QAAgB;IAEhB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,QAAQ,CAAA;IACjB,CAAC;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAClC,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;IACzD,CAAC;SAAM,CAAC;QACN,OAAO,YAAY,CAAC,OAAO,CAAC,CAAA;IAC9B,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,CAAS,EAAE,CAAS;IAC1C,OAAO,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAA;AAChD,CAAC;AAED,SAAS,YAAY,CAAC,OAAe;IACnC,IAAI,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,IAAI,MAAM,CACtB,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAC5D,CAAA;QACD,OAAO,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC7C,CAAC;IAED,OAAO,CAAC,KAAa,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,CAAA;AAC7C,CAAC","sourcesContent":["export type BuildFilterOptions = {\n include?: string | string[]\n exclude?: string | string[]\n}\n\nexport type Filter = (input: string) => boolean\n\nexport function buildFilter(options: BuildFilterOptions): Filter {\n const include = createMatcher(options.include, () => true)\n const exclude = createMatcher(options.exclude, () => false)\n\n return (id) => include(id) && !exclude(id)\n}\n\nfunction createMatcher(\n pattern: undefined | string | string[],\n fallback: Filter,\n): Filter {\n if (!pattern?.length) {\n return fallback\n } else if (Array.isArray(pattern)) {\n return pattern.map(buildMatcher).reduce(combineFilters)\n } else {\n return buildMatcher(pattern)\n }\n}\n\nfunction combineFilters(a: Filter, b: Filter): Filter {\n return (input: string) => a(input) || b(input)\n}\n\nfunction buildMatcher(pattern: string): Filter {\n if (pattern.includes('*')) {\n const regex = new RegExp(\n `^${pattern.replaceAll('.', '\\\\.').replaceAll('*', '.+')}$`,\n )\n return (input: string) => regex.test(input)\n }\n\n return (input: string) => pattern === input\n}\n"]}