@zap-js/client 0.0.2 → 0.0.5

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 (115) hide show
  1. package/README.md +310 -24
  2. package/bin/zap +0 -0
  3. package/bin/zap-codegen +0 -0
  4. package/dist/cli/commands/build.d.ts +11 -0
  5. package/dist/cli/commands/build.js +282 -0
  6. package/dist/cli/commands/codegen.d.ts +8 -0
  7. package/dist/cli/commands/codegen.js +95 -0
  8. package/dist/cli/commands/dev.d.ts +20 -0
  9. package/dist/cli/commands/dev.js +78 -0
  10. package/dist/cli/commands/new.d.ts +9 -0
  11. package/dist/cli/commands/new.js +307 -0
  12. package/dist/cli/commands/routes-old.d.ts +9 -0
  13. package/dist/cli/commands/routes-old.js +106 -0
  14. package/dist/cli/commands/routes.d.ts +11 -0
  15. package/dist/cli/commands/routes.js +280 -0
  16. package/dist/cli/commands/serve.d.ts +17 -0
  17. package/dist/cli/commands/serve.js +386 -0
  18. package/dist/cli/index.d.ts +2 -0
  19. package/dist/cli/index.js +76 -0
  20. package/dist/cli/utils/index.d.ts +2 -0
  21. package/dist/cli/utils/index.js +2 -0
  22. package/dist/cli/utils/logger.d.ts +84 -0
  23. package/dist/cli/utils/logger.js +181 -0
  24. package/dist/cli/utils/port-finder.d.ts +8 -0
  25. package/dist/cli/utils/port-finder.js +48 -0
  26. package/dist/dev-server/codegen-runner.d.ts +41 -0
  27. package/dist/dev-server/codegen-runner.js +172 -0
  28. package/dist/dev-server/hot-reload.d.ts +72 -0
  29. package/dist/dev-server/hot-reload.js +280 -0
  30. package/dist/dev-server/index.d.ts +8 -0
  31. package/dist/dev-server/index.js +8 -0
  32. package/dist/dev-server/route-scanner.d.ts +84 -0
  33. package/dist/dev-server/route-scanner.js +113 -0
  34. package/dist/dev-server/rust-builder.d.ts +66 -0
  35. package/dist/dev-server/rust-builder.js +286 -0
  36. package/dist/dev-server/server.d.ts +147 -0
  37. package/dist/dev-server/server.js +660 -0
  38. package/dist/dev-server/vite-proxy.d.ts +56 -0
  39. package/dist/dev-server/vite-proxy.js +212 -0
  40. package/dist/dev-server/watcher.d.ts +48 -0
  41. package/dist/dev-server/watcher.js +127 -0
  42. package/dist/router/codegen-enhanced.d.ts +5 -0
  43. package/dist/router/codegen-enhanced.js +275 -0
  44. package/dist/router/codegen.d.ts +17 -0
  45. package/dist/router/codegen.js +654 -0
  46. package/dist/router/index.d.ts +16 -0
  47. package/dist/router/index.js +19 -0
  48. package/dist/router/scanner.d.ts +86 -0
  49. package/dist/router/scanner.js +689 -0
  50. package/dist/router/ssg.d.ts +115 -0
  51. package/dist/router/ssg.js +202 -0
  52. package/dist/router/types.d.ts +124 -0
  53. package/dist/router/types.js +9 -0
  54. package/dist/router/watch.d.ts +38 -0
  55. package/dist/router/watch.js +135 -0
  56. package/dist/runtime/csrf.d.ts +146 -0
  57. package/dist/runtime/csrf.js +166 -0
  58. package/dist/runtime/error-boundary.d.ts +129 -0
  59. package/dist/runtime/error-boundary.js +287 -0
  60. package/dist/runtime/hooks.d.ts +83 -0
  61. package/dist/runtime/hooks.js +96 -0
  62. package/dist/runtime/index.d.ts +229 -0
  63. package/dist/runtime/index.js +449 -0
  64. package/dist/runtime/ipc-client.d.ts +144 -0
  65. package/dist/runtime/ipc-client.js +621 -0
  66. package/dist/runtime/logger.d.ts +71 -0
  67. package/dist/runtime/logger.js +164 -0
  68. package/dist/runtime/middleware.d.ts +66 -0
  69. package/dist/runtime/middleware.js +114 -0
  70. package/dist/runtime/process-manager.d.ts +51 -0
  71. package/dist/runtime/process-manager.js +207 -0
  72. package/dist/runtime/router-simple.d.ts +98 -0
  73. package/dist/runtime/router-simple.js +330 -0
  74. package/dist/runtime/router.d.ts +103 -0
  75. package/dist/runtime/router.js +435 -0
  76. package/dist/runtime/rpc-client.d.ts +35 -0
  77. package/dist/runtime/rpc-client.js +140 -0
  78. package/dist/runtime/streaming-utils.d.ts +86 -0
  79. package/dist/runtime/streaming-utils.js +150 -0
  80. package/dist/runtime/types.d.ts +465 -0
  81. package/dist/runtime/types.js +60 -0
  82. package/dist/runtime/websockets-utils.d.ts +50 -0
  83. package/dist/runtime/websockets-utils.js +92 -0
  84. package/package.json +30 -20
  85. package/index.js +0 -29
  86. package/internal/cli/package.json +0 -46
  87. package/internal/cli/tsconfig.tsbuildinfo +0 -1
  88. package/internal/dev-server/node_modules/ora/index.d.ts +0 -332
  89. package/internal/dev-server/node_modules/ora/index.js +0 -416
  90. package/internal/dev-server/node_modules/ora/license +0 -9
  91. package/internal/dev-server/node_modules/ora/node_modules/string-width/index.d.ts +0 -36
  92. package/internal/dev-server/node_modules/ora/node_modules/string-width/index.js +0 -65
  93. package/internal/dev-server/node_modules/ora/node_modules/string-width/license +0 -9
  94. package/internal/dev-server/node_modules/ora/node_modules/string-width/node_modules/emoji-regex/LICENSE-MIT.txt +0 -20
  95. package/internal/dev-server/node_modules/ora/node_modules/string-width/node_modules/emoji-regex/README.md +0 -107
  96. package/internal/dev-server/node_modules/ora/node_modules/string-width/node_modules/emoji-regex/index.d.ts +0 -3
  97. package/internal/dev-server/node_modules/ora/node_modules/string-width/node_modules/emoji-regex/index.js +0 -4
  98. package/internal/dev-server/node_modules/ora/node_modules/string-width/node_modules/emoji-regex/index.mjs +0 -4
  99. package/internal/dev-server/node_modules/ora/node_modules/string-width/node_modules/emoji-regex/package.json +0 -46
  100. package/internal/dev-server/node_modules/ora/node_modules/string-width/package.json +0 -60
  101. package/internal/dev-server/node_modules/ora/node_modules/string-width/readme.md +0 -62
  102. package/internal/dev-server/node_modules/ora/package.json +0 -66
  103. package/internal/dev-server/node_modules/ora/readme.md +0 -325
  104. package/internal/dev-server/package.json +0 -41
  105. package/internal/router/package.json +0 -28
  106. package/internal/runtime/package.json +0 -41
  107. package/internal/runtime/src/error-boundary.tsx +0 -476
  108. package/internal/runtime/src/router-simple.tsx +0 -640
  109. package/internal/runtime/src/router.tsx +0 -771
  110. package/internal/runtime/tsconfig.tsbuildinfo +0 -1
  111. package/src/errors.js +0 -33
  112. package/src/logger.js +0 -10
  113. package/src/middleware.js +0 -32
  114. package/src/router.js +0 -41
  115. package/src/types.js +0 -39
@@ -1,416 +0,0 @@
1
- import process from 'node:process';
2
- import chalk from 'chalk';
3
- import cliCursor from 'cli-cursor';
4
- import cliSpinners from 'cli-spinners';
5
- import logSymbols from 'log-symbols';
6
- import stripAnsi from 'strip-ansi';
7
- import stringWidth from 'string-width';
8
- import isInteractive from 'is-interactive';
9
- import isUnicodeSupported from 'is-unicode-supported';
10
- import stdinDiscarder from 'stdin-discarder';
11
-
12
- class Ora {
13
- #linesToClear = 0;
14
- #isDiscardingStdin = false;
15
- #lineCount = 0;
16
- #frameIndex = 0;
17
- #options;
18
- #spinner;
19
- #stream;
20
- #id;
21
- #initialInterval;
22
- #isEnabled;
23
- #isSilent;
24
- #indent;
25
- #text;
26
- #prefixText;
27
- #suffixText;
28
-
29
- color;
30
-
31
- constructor(options) {
32
- if (typeof options === 'string') {
33
- options = {
34
- text: options,
35
- };
36
- }
37
-
38
- this.#options = {
39
- color: 'cyan',
40
- stream: process.stderr,
41
- discardStdin: true,
42
- hideCursor: true,
43
- ...options,
44
- };
45
-
46
- // Public
47
- this.color = this.#options.color;
48
-
49
- // It's important that these use the public setters.
50
- this.spinner = this.#options.spinner;
51
-
52
- this.#initialInterval = this.#options.interval;
53
- this.#stream = this.#options.stream;
54
- this.#isEnabled = typeof this.#options.isEnabled === 'boolean' ? this.#options.isEnabled : isInteractive({stream: this.#stream});
55
- this.#isSilent = typeof this.#options.isSilent === 'boolean' ? this.#options.isSilent : false;
56
-
57
- // Set *after* `this.#stream`.
58
- // It's important that these use the public setters.
59
- this.text = this.#options.text;
60
- this.prefixText = this.#options.prefixText;
61
- this.suffixText = this.#options.suffixText;
62
- this.indent = this.#options.indent;
63
-
64
- if (process.env.NODE_ENV === 'test') {
65
- this._stream = this.#stream;
66
- this._isEnabled = this.#isEnabled;
67
-
68
- Object.defineProperty(this, '_linesToClear', {
69
- get() {
70
- return this.#linesToClear;
71
- },
72
- set(newValue) {
73
- this.#linesToClear = newValue;
74
- },
75
- });
76
-
77
- Object.defineProperty(this, '_frameIndex', {
78
- get() {
79
- return this.#frameIndex;
80
- },
81
- });
82
-
83
- Object.defineProperty(this, '_lineCount', {
84
- get() {
85
- return this.#lineCount;
86
- },
87
- });
88
- }
89
- }
90
-
91
- get indent() {
92
- return this.#indent;
93
- }
94
-
95
- set indent(indent = 0) {
96
- if (!(indent >= 0 && Number.isInteger(indent))) {
97
- throw new Error('The `indent` option must be an integer from 0 and up');
98
- }
99
-
100
- this.#indent = indent;
101
- this.#updateLineCount();
102
- }
103
-
104
- get interval() {
105
- return this.#initialInterval ?? this.#spinner.interval ?? 100;
106
- }
107
-
108
- get spinner() {
109
- return this.#spinner;
110
- }
111
-
112
- set spinner(spinner) {
113
- this.#frameIndex = 0;
114
- this.#initialInterval = undefined;
115
-
116
- if (typeof spinner === 'object') {
117
- if (spinner.frames === undefined) {
118
- throw new Error('The given spinner must have a `frames` property');
119
- }
120
-
121
- this.#spinner = spinner;
122
- } else if (!isUnicodeSupported()) {
123
- this.#spinner = cliSpinners.line;
124
- } else if (spinner === undefined) {
125
- // Set default spinner
126
- this.#spinner = cliSpinners.dots;
127
- } else if (spinner !== 'default' && cliSpinners[spinner]) {
128
- this.#spinner = cliSpinners[spinner];
129
- } else {
130
- throw new Error(`There is no built-in spinner named '${spinner}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`);
131
- }
132
- }
133
-
134
- get text() {
135
- return this.#text;
136
- }
137
-
138
- set text(value = '') {
139
- this.#text = value;
140
- this.#updateLineCount();
141
- }
142
-
143
- get prefixText() {
144
- return this.#prefixText;
145
- }
146
-
147
- set prefixText(value = '') {
148
- this.#prefixText = value;
149
- this.#updateLineCount();
150
- }
151
-
152
- get suffixText() {
153
- return this.#suffixText;
154
- }
155
-
156
- set suffixText(value = '') {
157
- this.#suffixText = value;
158
- this.#updateLineCount();
159
- }
160
-
161
- get isSpinning() {
162
- return this.#id !== undefined;
163
- }
164
-
165
- #getFullPrefixText(prefixText = this.#prefixText, postfix = ' ') {
166
- if (typeof prefixText === 'string' && prefixText !== '') {
167
- return prefixText + postfix;
168
- }
169
-
170
- if (typeof prefixText === 'function') {
171
- return prefixText() + postfix;
172
- }
173
-
174
- return '';
175
- }
176
-
177
- #getFullSuffixText(suffixText = this.#suffixText, prefix = ' ') {
178
- if (typeof suffixText === 'string' && suffixText !== '') {
179
- return prefix + suffixText;
180
- }
181
-
182
- if (typeof suffixText === 'function') {
183
- return prefix + suffixText();
184
- }
185
-
186
- return '';
187
- }
188
-
189
- #updateLineCount() {
190
- const columns = this.#stream.columns ?? 80;
191
- const fullPrefixText = this.#getFullPrefixText(this.#prefixText, '-');
192
- const fullSuffixText = this.#getFullSuffixText(this.#suffixText, '-');
193
- const fullText = ' '.repeat(this.#indent) + fullPrefixText + '--' + this.#text + '--' + fullSuffixText;
194
-
195
- this.#lineCount = 0;
196
- for (const line of stripAnsi(fullText).split('\n')) {
197
- this.#lineCount += Math.max(1, Math.ceil(stringWidth(line, {countAnsiEscapeCodes: true}) / columns));
198
- }
199
- }
200
-
201
- get isEnabled() {
202
- return this.#isEnabled && !this.#isSilent;
203
- }
204
-
205
- set isEnabled(value) {
206
- if (typeof value !== 'boolean') {
207
- throw new TypeError('The `isEnabled` option must be a boolean');
208
- }
209
-
210
- this.#isEnabled = value;
211
- }
212
-
213
- get isSilent() {
214
- return this.#isSilent;
215
- }
216
-
217
- set isSilent(value) {
218
- if (typeof value !== 'boolean') {
219
- throw new TypeError('The `isSilent` option must be a boolean');
220
- }
221
-
222
- this.#isSilent = value;
223
- }
224
-
225
- frame() {
226
- const {frames} = this.#spinner;
227
- let frame = frames[this.#frameIndex];
228
-
229
- if (this.color) {
230
- frame = chalk[this.color](frame);
231
- }
232
-
233
- this.#frameIndex = ++this.#frameIndex % frames.length;
234
- const fullPrefixText = (typeof this.#prefixText === 'string' && this.#prefixText !== '') ? this.#prefixText + ' ' : '';
235
- const fullText = typeof this.text === 'string' ? ' ' + this.text : '';
236
- const fullSuffixText = (typeof this.#suffixText === 'string' && this.#suffixText !== '') ? ' ' + this.#suffixText : '';
237
-
238
- return fullPrefixText + frame + fullText + fullSuffixText;
239
- }
240
-
241
- clear() {
242
- if (!this.#isEnabled || !this.#stream.isTTY) {
243
- return this;
244
- }
245
-
246
- this.#stream.cursorTo(0);
247
-
248
- for (let index = 0; index < this.#linesToClear; index++) {
249
- if (index > 0) {
250
- this.#stream.moveCursor(0, -1);
251
- }
252
-
253
- this.#stream.clearLine(1);
254
- }
255
-
256
- if (this.#indent || this.lastIndent !== this.#indent) {
257
- this.#stream.cursorTo(this.#indent);
258
- }
259
-
260
- this.lastIndent = this.#indent;
261
- this.#linesToClear = 0;
262
-
263
- return this;
264
- }
265
-
266
- render() {
267
- if (this.#isSilent) {
268
- return this;
269
- }
270
-
271
- this.clear();
272
- this.#stream.write(this.frame());
273
- this.#linesToClear = this.#lineCount;
274
-
275
- return this;
276
- }
277
-
278
- start(text) {
279
- if (text) {
280
- this.text = text;
281
- }
282
-
283
- if (this.#isSilent) {
284
- return this;
285
- }
286
-
287
- if (!this.#isEnabled) {
288
- if (this.text) {
289
- this.#stream.write(`- ${this.text}\n`);
290
- }
291
-
292
- return this;
293
- }
294
-
295
- if (this.isSpinning) {
296
- return this;
297
- }
298
-
299
- if (this.#options.hideCursor) {
300
- cliCursor.hide(this.#stream);
301
- }
302
-
303
- if (this.#options.discardStdin && process.stdin.isTTY) {
304
- this.#isDiscardingStdin = true;
305
- stdinDiscarder.start();
306
- }
307
-
308
- this.render();
309
- this.#id = setInterval(this.render.bind(this), this.interval);
310
-
311
- return this;
312
- }
313
-
314
- stop() {
315
- if (!this.#isEnabled) {
316
- return this;
317
- }
318
-
319
- clearInterval(this.#id);
320
- this.#id = undefined;
321
- this.#frameIndex = 0;
322
- this.clear();
323
- if (this.#options.hideCursor) {
324
- cliCursor.show(this.#stream);
325
- }
326
-
327
- if (this.#options.discardStdin && process.stdin.isTTY && this.#isDiscardingStdin) {
328
- stdinDiscarder.stop();
329
- this.#isDiscardingStdin = false;
330
- }
331
-
332
- return this;
333
- }
334
-
335
- succeed(text) {
336
- return this.stopAndPersist({symbol: logSymbols.success, text});
337
- }
338
-
339
- fail(text) {
340
- return this.stopAndPersist({symbol: logSymbols.error, text});
341
- }
342
-
343
- warn(text) {
344
- return this.stopAndPersist({symbol: logSymbols.warning, text});
345
- }
346
-
347
- info(text) {
348
- return this.stopAndPersist({symbol: logSymbols.info, text});
349
- }
350
-
351
- stopAndPersist(options = {}) {
352
- if (this.#isSilent) {
353
- return this;
354
- }
355
-
356
- const prefixText = options.prefixText ?? this.#prefixText;
357
- const fullPrefixText = this.#getFullPrefixText(prefixText, ' ');
358
-
359
- const symbolText = options.symbol ?? ' ';
360
-
361
- const text = options.text ?? this.text;
362
- const fullText = (typeof text === 'string') ? ' ' + text : '';
363
-
364
- const suffixText = options.suffixText ?? this.#suffixText;
365
- const fullSuffixText = this.#getFullSuffixText(suffixText, ' ');
366
-
367
- const textToWrite = fullPrefixText + symbolText + fullText + fullSuffixText + '\n';
368
-
369
- this.stop();
370
- this.#stream.write(textToWrite);
371
-
372
- return this;
373
- }
374
- }
375
-
376
- export default function ora(options) {
377
- return new Ora(options);
378
- }
379
-
380
- export async function oraPromise(action, options) {
381
- const actionIsFunction = typeof action === 'function';
382
- const actionIsPromise = typeof action.then === 'function';
383
-
384
- if (!actionIsFunction && !actionIsPromise) {
385
- throw new TypeError('Parameter `action` must be a Function or a Promise');
386
- }
387
-
388
- const {successText, failText} = typeof options === 'object'
389
- ? options
390
- : {successText: undefined, failText: undefined};
391
-
392
- const spinner = ora(options).start();
393
-
394
- try {
395
- const promise = actionIsFunction ? action(spinner) : action;
396
- const result = await promise;
397
-
398
- spinner.succeed(
399
- successText === undefined
400
- ? undefined
401
- : (typeof successText === 'string' ? successText : successText(result)),
402
- );
403
-
404
- return result;
405
- } catch (error) {
406
- spinner.fail(
407
- failText === undefined
408
- ? undefined
409
- : (typeof failText === 'string' ? failText : failText(error)),
410
- );
411
-
412
- throw error;
413
- }
414
- }
415
-
416
- export {default as spinners} from 'cli-spinners';
@@ -1,9 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,36 +0,0 @@
1
- export type Options = {
2
- /**
3
- Count [ambiguous width characters](https://www.unicode.org/reports/tr11/#Ambiguous) as having narrow width (count of 1) instead of wide width (count of 2).
4
-
5
- @default true
6
- */
7
- readonly ambiguousIsNarrow?: boolean;
8
-
9
- /**
10
- Whether [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) should be counted.
11
-
12
- @default false
13
- */
14
- readonly countAnsiEscapeCodes?: boolean;
15
- };
16
-
17
- /**
18
- Get the visual width of a string - the number of columns required to display it.
19
-
20
- Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
21
-
22
- @example
23
- ```
24
- import stringWidth from 'string-width';
25
-
26
- stringWidth('a');
27
- //=> 1
28
-
29
- stringWidth('古');
30
- //=> 2
31
-
32
- stringWidth('\u001B[1m古\u001B[22m');
33
- //=> 2
34
- ```
35
- */
36
- export default function stringWidth(string: string, options?: Options): number;
@@ -1,65 +0,0 @@
1
- import stripAnsi from 'strip-ansi';
2
- import eastAsianWidth from 'eastasianwidth';
3
- import emojiRegex from 'emoji-regex';
4
-
5
- export default function stringWidth(string, options) {
6
- if (typeof string !== 'string' || string.length === 0) {
7
- return 0;
8
- }
9
-
10
- options = {
11
- ambiguousIsNarrow: true,
12
- countAnsiEscapeCodes: false,
13
- ...options,
14
- };
15
-
16
- if (!options.countAnsiEscapeCodes) {
17
- string = stripAnsi(string);
18
- }
19
-
20
- if (string.length === 0) {
21
- return 0;
22
- }
23
-
24
- const ambiguousCharacterWidth = options.ambiguousIsNarrow ? 1 : 2;
25
- let width = 0;
26
-
27
- for (const {segment: character} of new Intl.Segmenter().segment(string)) {
28
- const codePoint = character.codePointAt(0);
29
-
30
- // Ignore control characters
31
- if (codePoint <= 0x1F || (codePoint >= 0x7F && codePoint <= 0x9F)) {
32
- continue;
33
- }
34
-
35
- // Ignore combining characters
36
- if (codePoint >= 0x3_00 && codePoint <= 0x3_6F) {
37
- continue;
38
- }
39
-
40
- if (emojiRegex().test(character)) {
41
- width += 2;
42
- continue;
43
- }
44
-
45
- const code = eastAsianWidth.eastAsianWidth(character);
46
- switch (code) {
47
- case 'F':
48
- case 'W': {
49
- width += 2;
50
- break;
51
- }
52
-
53
- case 'A': {
54
- width += ambiguousCharacterWidth;
55
- break;
56
- }
57
-
58
- default: {
59
- width += 1;
60
- }
61
- }
62
- }
63
-
64
- return width;
65
- }
@@ -1,9 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,20 +0,0 @@
1
- Copyright Mathias Bynens <https://mathiasbynens.be/>
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,107 +0,0 @@
1
- # emoji-regex [![Build status](https://github.com/mathiasbynens/emoji-regex/actions/workflows/main.yml/badge.svg)](https://github.com/mathiasbynens/emoji-regex/actions/workflows/main.yml) [![emoji-regex on npm](https://img.shields.io/npm/v/emoji-regex)](https://www.npmjs.com/package/emoji-regex)
2
-
3
- _emoji-regex_ offers a regular expression to match all emoji symbols and sequences (including textual representations of emoji) as per the Unicode Standard. It’s based on [_emoji-test-regex-pattern_](https://github.com/mathiasbynens/emoji-test-regex-pattern), which generates (at build time) the regular expression pattern based on the Unicode Standard. As a result, _emoji-regex_ can easily be updated whenever new emoji are added to Unicode.
4
-
5
- Since each version of _emoji-regex_ is tied to the latest Unicode version at the time of release, results are deterministic. This is important for use cases like image replacement, where you want to guarantee that an image asset is available for every possibly matched emoji. If you don’t need a deterministic regex, a lighter-weight, general emoji pattern is available via the [_emoji-regex-xs_](https://github.com/slevithan/emoji-regex-xs) package that follows the same API.
6
-
7
- ## Installation
8
-
9
- Via [npm](https://www.npmjs.com/):
10
-
11
- ```bash
12
- npm install emoji-regex
13
- ```
14
-
15
- In [Node.js](https://nodejs.org/):
16
-
17
- ```js
18
- const emojiRegex = require('emoji-regex');
19
- // Note: because the regular expression has the global flag set, this module
20
- // exports a function that returns the regex rather than exporting the regular
21
- // expression itself, to make it impossible to (accidentally) mutate the
22
- // original regular expression.
23
-
24
- const text = `
25
- \u{231A}: ⌚ default emoji presentation character (Emoji_Presentation)
26
- \u{2194}\u{FE0F}: ↔️ default text presentation character rendered as emoji
27
- \u{1F469}: 👩 emoji modifier base (Emoji_Modifier_Base)
28
- \u{1F469}\u{1F3FF}: 👩🏿 emoji modifier base followed by a modifier
29
- `;
30
-
31
- const regex = emojiRegex();
32
- for (const match of text.matchAll(regex)) {
33
- const emoji = match[0];
34
- console.log(`Matched sequence ${ emoji } — code points: ${ [...emoji].length }`);
35
- }
36
- ```
37
-
38
- Console output:
39
-
40
- ```
41
- Matched sequence ⌚ — code points: 1
42
- Matched sequence ⌚ — code points: 1
43
- Matched sequence ↔️ — code points: 2
44
- Matched sequence ↔️ — code points: 2
45
- Matched sequence 👩 — code points: 1
46
- Matched sequence 👩 — code points: 1
47
- Matched sequence 👩🏿 — code points: 2
48
- Matched sequence 👩🏿 — code points: 2
49
- ```
50
-
51
- ## For maintainers
52
-
53
- ### How to update emoji-regex after new Unicode Standard releases
54
-
55
- 1. [Update _emoji-test-regex-pattern_ as described in its repository](https://github.com/mathiasbynens/emoji-test-regex-pattern#how-to-update-emoji-test-regex-pattern-after-new-uts51-releases).
56
-
57
- 1. Bump the _emoji-test-regex-pattern_ dependency to the latest version.
58
-
59
- 1. Update the Unicode data dependency in `package.json` by running the following commands:
60
-
61
- ```sh
62
- # Example: updating from Unicode v13 to Unicode v14.
63
- npm uninstall @unicode/unicode-13.0.0
64
- npm install @unicode/unicode-14.0.0 --save-dev
65
- ````
66
-
67
- 1. Generate the new output:
68
-
69
- ```sh
70
- npm run build
71
- ```
72
-
73
- 1. Verify that tests still pass:
74
-
75
- ```sh
76
- npm test
77
- ```
78
-
79
- ### How to publish a new release
80
-
81
- 1. On the `main` branch, bump the emoji-regex version number in `package.json`:
82
-
83
- ```sh
84
- npm version patch -m 'Release v%s'
85
- ```
86
-
87
- Instead of `patch`, use `minor` or `major` [as needed](https://semver.org/).
88
-
89
- Note that this produces a Git commit + tag.
90
-
91
- 1. Push the release commit and tag:
92
-
93
- ```sh
94
- git push && git push --tags
95
- ```
96
-
97
- Our CI then automatically publishes the new release to npm.
98
-
99
- ## Author
100
-
101
- | [![twitter/mathias](https://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") |
102
- |---|
103
- | [Mathias Bynens](https://mathiasbynens.be/) |
104
-
105
- ## License
106
-
107
- _emoji-regex_ is available under the [MIT](https://mths.be/mit) license.
@@ -1,3 +0,0 @@
1
- declare module 'emoji-regex' {
2
- export default function emojiRegex(): RegExp;
3
- }