@naanlang/naan 1.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 (98) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +46 -0
  3. package/dist/env_web.js +431 -0
  4. package/dist/naan.min.js +73 -0
  5. package/frameworks/browser/browser.nlg +30 -0
  6. package/frameworks/browser/pouchdb/pouchdb.min.js +7 -0
  7. package/frameworks/browser/spark-md5/spark-md5.min.js +1 -0
  8. package/frameworks/browser/sworker.js +192 -0
  9. package/frameworks/browser/terminals.nlg +787 -0
  10. package/frameworks/browser/workers.nlg +386 -0
  11. package/frameworks/client/apiclient.nlg +183 -0
  12. package/frameworks/client/client.nlg +29 -0
  13. package/frameworks/client/psm_client.nlg +572 -0
  14. package/frameworks/common/common.nlg +464 -0
  15. package/frameworks/common/preferences.nlg +131 -0
  16. package/frameworks/common/repltools.nlg +100 -0
  17. package/frameworks/common/watching.nlg +97 -0
  18. package/frameworks/node/apiserver.nlg +399 -0
  19. package/frameworks/node/filesystem.nlg +1012 -0
  20. package/frameworks/node/gitter.nlg +234 -0
  21. package/frameworks/node/node.nlg +81 -0
  22. package/frameworks/node/psm_server.nlg +465 -0
  23. package/frameworks/node/worker.nlg +560 -0
  24. package/frameworks/project/build.nlg +1229 -0
  25. package/frameworks/project/jszip.js +30 -0
  26. package/frameworks/project/jszip.nlg +87 -0
  27. package/frameworks/project/proj_cliser.nlg +139 -0
  28. package/frameworks/project/proj_console.nlg +137 -0
  29. package/frameworks/project/proj_folder.nlg +143 -0
  30. package/frameworks/project/proj_lambda.nlg +137 -0
  31. package/frameworks/project/proj_static.nlg +138 -0
  32. package/frameworks/project/project.nlg +29 -0
  33. package/frameworks/project/projects.nlg +587 -0
  34. package/frameworks/project/uglifyjs.js +1 -0
  35. package/frameworks/project/uglifyjs.nlg +79 -0
  36. package/frameworks/running/debugcom.nlg +163 -0
  37. package/frameworks/running/debugnub.nlg +565 -0
  38. package/frameworks/running/debugutil.nlg +510 -0
  39. package/frameworks/running/executors.nlg +767 -0
  40. package/frameworks/running/running.nlg +151 -0
  41. package/frameworks/running/sourcecode.nlg +346 -0
  42. package/frameworks/running/taskexec.nlg +196 -0
  43. package/frameworks/storage/dbt_pouch.nlg +773 -0
  44. package/frameworks/storage/file_manager.nlg +772 -0
  45. package/frameworks/storage/psm.nlg +326 -0
  46. package/frameworks/storage/psm_dbtables.nlg +814 -0
  47. package/frameworks/storage/resources.nlg +445 -0
  48. package/frameworks/storage/storage.nlg +52 -0
  49. package/lib/browser/env_web.js +431 -0
  50. package/lib/browser/env_webworker.js +146 -0
  51. package/lib/browser/require.js +1653 -0
  52. package/lib/core/naanlib.js +73 -0
  53. package/lib/env_node.js +282 -0
  54. package/lib/env_nodeworker.js +165 -0
  55. package/lib/node_repl.js +25 -0
  56. package/lib/node_repl_init.nlg +52 -0
  57. package/package.json +13 -0
  58. package/plugins/gitClient/clientops.nlg +317 -0
  59. package/plugins/gitClient/gitClient.nlg +63 -0
  60. package/plugins/gitClient/gitutils.nlg +1331 -0
  61. package/plugins/gitClient/minimatch.js +945 -0
  62. package/plugins/gitClient/minimatch_license.txt +15 -0
  63. package/plugins/gitClient/minimatch_readme.md +208 -0
  64. package/plugins/nodeLib/nodeLib.nlg +26 -0
  65. package/plugins/nodeLib/node_cp.nlg +65 -0
  66. package/plugins/nodeLib/node_fs.nlg +137 -0
  67. package/plugins/nodeLib/node_https.nlg +172 -0
  68. package/plugins/nodeLib/node_util.nlg +180 -0
  69. package/plugins/serviceAws/aws/aws-sdk.min.js +88 -0
  70. package/plugins/serviceAws/aws/lambda_rest_index.js +122 -0
  71. package/plugins/serviceAws/aws/lambda_rest_init.nlg +58 -0
  72. package/plugins/serviceAws/aws/lambda_ws_index.js +498 -0
  73. package/plugins/serviceAws/aws/lambda_ws_init.nlg +49 -0
  74. package/plugins/serviceAws/aws_cloudwatchlogs.nlg +122 -0
  75. package/plugins/serviceAws/aws_cognito.nlg +76 -0
  76. package/plugins/serviceAws/aws_dynamo.nlg +509 -0
  77. package/plugins/serviceAws/aws_lambda.nlg +95 -0
  78. package/plugins/serviceAws/aws_s3.nlg +134 -0
  79. package/plugins/serviceAws/aws_utils.nlg +86 -0
  80. package/plugins/serviceAws/dbt_aws.nlg +769 -0
  81. package/plugins/serviceAws/lambda_naan_control.nlg +175 -0
  82. package/plugins/serviceAws/psm_aws.nlg +258 -0
  83. package/plugins/serviceAws/serviceAws.nlg +38 -0
  84. package/plugins/serviceGitHub/gitops.nlg +522 -0
  85. package/plugins/serviceGitHub/psm_github.nlg +205 -0
  86. package/plugins/serviceGitHub/serviceGitHub.nlg +65 -0
  87. package/plugins/serviceGitLab/gitops.nlg +528 -0
  88. package/plugins/serviceGitLab/psm_gitlab.nlg +205 -0
  89. package/plugins/serviceGitLab/serviceGitLab.nlg +65 -0
  90. package/test/harness.nlg +312 -0
  91. package/test/node_test.js +33 -0
  92. package/test/test_01_core.nlg +768 -0
  93. package/test/test_02_context.nlg +269 -0
  94. package/test/test_03_jsinterop.nlg +137 -0
  95. package/test/test_04_numerics.nlg +450 -0
  96. package/test/test_05_strings.nlg +63 -0
  97. package/test/test_06_lingoparse.nlg +500 -0
  98. package/test/test_07_lingo.nlg +623 -0
@@ -0,0 +1,1653 @@
1
+ /*
2
+ * require.js
3
+ *
4
+ * Customized implementation of NodeJS "require" for running Naan in the browser.
5
+ *
6
+ * column positioning: // // !
7
+ *
8
+ * Copyright (c) 2019-2021 by Richard C. Zulch
9
+ *
10
+ */
11
+
12
+ (function(exports){
13
+
14
+ /*
15
+ * require
16
+ *
17
+ * A web-based analog to the Node.js require function.
18
+ *
19
+ */
20
+
21
+ exports.require = function require(modpath) {
22
+ 'use strict';
23
+
24
+ // require
25
+ //
26
+ // Emulate the require function for our little subset of available modules.
27
+
28
+ var methods = {
29
+ './naan_interpreter.js': exports.NaanInterpreter,
30
+ './bigint.js': exports.LeemonBigIntegerLib,
31
+ './naan_io.js': exports.NaanChannel,
32
+ './naan_lingo.js': exports.BootLingo,
33
+ './naan_module.js': exports.BootModule,
34
+ './naan_start.js': exports.BootRoot,
35
+ };
36
+
37
+ /*
38
+ * path utilities
39
+ *
40
+ * From https://raw.githubusercontent.com/nodejs/node/v9.5.0/lib/path.js
41
+ *
42
+ * Copyright Joyent, Inc. and other Node contributors.
43
+ *
44
+ * Permission is hereby granted, free of charge, to any person obtaining a
45
+ * copy of this software and associated documentation files (the
46
+ * "Software"), to deal in the Software without restriction, including
47
+ * without limitation the rights to use, copy, modify, merge, publish,
48
+ * distribute, sublicense, and/or sell copies of the Software, and to permit
49
+ * persons to whom the Software is furnished to do so, subject to the
50
+ * following conditions:
51
+ *
52
+ * The above copyright notice and this permission notice shall be included
53
+ * in all copies or substantial portions of the Software.
54
+ *
55
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
56
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
58
+ * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
59
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
60
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
61
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
62
+ *
63
+ */
64
+
65
+ function assertPath(path) {
66
+ if (typeof path !== 'string') {
67
+ throw new TypeError('Path must be a string. Received ' + typeof(path));
68
+ }
69
+ }
70
+
71
+ // Resolves . and .. elements in a path with directory names
72
+ function normalizeStringWin32(path, allowAboveRoot) {
73
+ var res = '';
74
+ var lastSegmentLength = 0;
75
+ var lastSlash = -1;
76
+ var dots = 0;
77
+ var code;
78
+ for (var i = 0; i <= path.length; ++i) {
79
+ if (i < path.length)
80
+ code = path.charCodeAt(i);
81
+ else if (code === 47 /*/*/ || code === 92 /*\*/ )
82
+ break;
83
+ else
84
+ code = 47 /*/*/ ;
85
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
86
+ if (lastSlash === i - 1 || dots === 1) {
87
+ // NOOP
88
+ } else if (lastSlash !== i - 1 && dots === 2) {
89
+ if (res.length < 2 || lastSegmentLength !== 2 ||
90
+ res.charCodeAt(res.length - 1) !== 46 /*.*/ ||
91
+ res.charCodeAt(res.length - 2) !== 46 /*.*/ ) {
92
+ if (res.length > 2) {
93
+ const lastSlashIndex = res.lastIndexOf('\\');
94
+ if (lastSlashIndex !== res.length - 1) {
95
+ if (lastSlashIndex === -1) {
96
+ res = '';
97
+ lastSegmentLength = 0;
98
+ } else {
99
+ res = res.slice(0, lastSlashIndex);
100
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('\\');
101
+ }
102
+ lastSlash = i;
103
+ dots = 0;
104
+ continue;
105
+ }
106
+ } else if (res.length === 2 || res.length === 1) {
107
+ res = '';
108
+ lastSegmentLength = 0;
109
+ lastSlash = i;
110
+ dots = 0;
111
+ continue;
112
+ }
113
+ }
114
+ if (allowAboveRoot) {
115
+ if (res.length > 0)
116
+ res += '\\..';
117
+ else
118
+ res = '..';
119
+ lastSegmentLength = 2;
120
+ }
121
+ } else {
122
+ if (res.length > 0)
123
+ res += '\\' + path.slice(lastSlash + 1, i);
124
+ else
125
+ res = path.slice(lastSlash + 1, i);
126
+ lastSegmentLength = i - lastSlash - 1;
127
+ }
128
+ lastSlash = i;
129
+ dots = 0;
130
+ } else if (code === 46 /*.*/ && dots !== -1) {
131
+ ++dots;
132
+ } else {
133
+ dots = -1;
134
+ }
135
+ }
136
+ return res;
137
+ }
138
+
139
+ // Resolves . and .. elements in a path with directory names
140
+ function normalizeStringPosix(path, allowAboveRoot) {
141
+ var res = '';
142
+ var lastSegmentLength = 0;
143
+ var lastSlash = -1;
144
+ var dots = 0;
145
+ var code;
146
+ for (var i = 0; i <= path.length; ++i) {
147
+ if (i < path.length)
148
+ code = path.charCodeAt(i);
149
+ else if (code === 47 /*/*/ )
150
+ break;
151
+ else
152
+ code = 47 /*/*/ ;
153
+ if (code === 47 /*/*/ ) {
154
+ if (lastSlash === i - 1 || dots === 1) {
155
+ // NOOP
156
+ } else if (lastSlash !== i - 1 && dots === 2) {
157
+ if (res.length < 2 || lastSegmentLength !== 2 ||
158
+ res.charCodeAt(res.length - 1) !== 46 /*.*/ ||
159
+ res.charCodeAt(res.length - 2) !== 46 /*.*/ ) {
160
+ if (res.length > 2) {
161
+ const lastSlashIndex = res.lastIndexOf('/');
162
+ if (lastSlashIndex !== res.length - 1) {
163
+ if (lastSlashIndex === -1) {
164
+ res = '';
165
+ lastSegmentLength = 0;
166
+ } else {
167
+ res = res.slice(0, lastSlashIndex);
168
+ lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
169
+ }
170
+ lastSlash = i;
171
+ dots = 0;
172
+ continue;
173
+ }
174
+ } else if (res.length === 2 || res.length === 1) {
175
+ res = '';
176
+ lastSegmentLength = 0;
177
+ lastSlash = i;
178
+ dots = 0;
179
+ continue;
180
+ }
181
+ }
182
+ if (allowAboveRoot) {
183
+ if (res.length > 0)
184
+ res += '/..';
185
+ else
186
+ res = '..';
187
+ lastSegmentLength = 2;
188
+ }
189
+ } else {
190
+ if (res.length > 0)
191
+ res += '/' + path.slice(lastSlash + 1, i);
192
+ else
193
+ res = path.slice(lastSlash + 1, i);
194
+ lastSegmentLength = i - lastSlash - 1;
195
+ }
196
+ lastSlash = i;
197
+ dots = 0;
198
+ } else if (code === 46 /*.*/ && dots !== -1) {
199
+ ++dots;
200
+ } else {
201
+ dots = -1;
202
+ }
203
+ }
204
+ return res;
205
+ }
206
+
207
+ function _format(sep, pathObject) {
208
+ const dir = pathObject.dir || pathObject.root;
209
+ const base = pathObject.base ||
210
+ ((pathObject.name || '') + (pathObject.ext || ''));
211
+ if (!dir) {
212
+ return base;
213
+ }
214
+ if (dir === pathObject.root) {
215
+ return dir + base;
216
+ }
217
+ return dir + sep + base;
218
+ }
219
+
220
+ const win32 = {
221
+ // path.resolve([from ...], to)
222
+ resolve: function resolve() {
223
+ var resolvedDevice = '';
224
+ var resolvedTail = '';
225
+ var resolvedAbsolute = false;
226
+
227
+ for (var i = arguments.length - 1; i >= -1; i--) {
228
+ var path;
229
+ if (i >= 0)
230
+ path = arguments[i];
231
+ else
232
+ path = "\\";
233
+
234
+ assertPath(path);
235
+
236
+ // Skip empty entries
237
+ if (path.length === 0) {
238
+ continue;
239
+ }
240
+
241
+ var len = path.length;
242
+ var rootEnd = 0;
243
+ var code = path.charCodeAt(0);
244
+ var device = '';
245
+ var isAbsolute = false;
246
+
247
+ // Try to match a root
248
+ if (len > 1) {
249
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
250
+ // Possible UNC root
251
+
252
+ // If we started with a separator, we know we at least have an
253
+ // absolute path of some kind (UNC or otherwise)
254
+ isAbsolute = true;
255
+
256
+ code = path.charCodeAt(1);
257
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
258
+ // Matched double path separator at beginning
259
+ var j = 2;
260
+ var last = j;
261
+ // Match 1 or more non-path separators
262
+ for (; j < len; ++j) {
263
+ code = path.charCodeAt(j);
264
+ if (code === 47 /*/*/ || code === 92 /*\*/ )
265
+ break;
266
+ }
267
+ if (j < len && j !== last) {
268
+ const firstPart = path.slice(last, j);
269
+ // Matched!
270
+ last = j;
271
+ // Match 1 or more path separators
272
+ for (; j < len; ++j) {
273
+ code = path.charCodeAt(j);
274
+ if (code !== 47 /*/*/ && code !== 92 /*\*/ )
275
+ break;
276
+ }
277
+ if (j < len && j !== last) {
278
+ // Matched!
279
+ last = j;
280
+ // Match 1 or more non-path separators
281
+ for (; j < len; ++j) {
282
+ code = path.charCodeAt(j);
283
+ if (code === 47 /*/*/ || code === 92 /*\*/ )
284
+ break;
285
+ }
286
+ if (j === len) {
287
+ // We matched a UNC root only
288
+
289
+ device = '\\\\' + firstPart + '\\' + path.slice(last);
290
+ rootEnd = j;
291
+ } else if (j !== last) {
292
+ // We matched a UNC root with leftovers
293
+
294
+ device = '\\\\' + firstPart + '\\' + path.slice(last, j);
295
+ rootEnd = j;
296
+ }
297
+ }
298
+ }
299
+ } else {
300
+ rootEnd = 1;
301
+ }
302
+ } else if ((code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
303
+ (code >= 97 /*a*/ && code <= 122 /*z*/ )) {
304
+ // Possible device root
305
+
306
+ if (path.charCodeAt(1) === 58 /*:*/ ) {
307
+ device = path.slice(0, 2);
308
+ rootEnd = 2;
309
+ if (len > 2) {
310
+ code = path.charCodeAt(2);
311
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
312
+ // Treat separator following drive name as an absolute path
313
+ // indicator
314
+ isAbsolute = true;
315
+ rootEnd = 3;
316
+ }
317
+ }
318
+ }
319
+ }
320
+ } else if (code === 47 /*/*/ || code === 92 /*\*/ ) {
321
+ // `path` contains just a path separator
322
+ rootEnd = 1;
323
+ isAbsolute = true;
324
+ }
325
+
326
+ if (device.length > 0 &&
327
+ resolvedDevice.length > 0 &&
328
+ device.toLowerCase() !== resolvedDevice.toLowerCase()) {
329
+ // This path points to another device so it is not applicable
330
+ continue;
331
+ }
332
+
333
+ if (resolvedDevice.length === 0 && device.length > 0) {
334
+ resolvedDevice = device;
335
+ }
336
+ if (!resolvedAbsolute) {
337
+ resolvedTail = path.slice(rootEnd) + '\\' + resolvedTail;
338
+ resolvedAbsolute = isAbsolute;
339
+ }
340
+
341
+ if (resolvedDevice.length > 0 && resolvedAbsolute) {
342
+ break;
343
+ }
344
+ }
345
+
346
+ // At this point the path should be resolved to a full absolute path,
347
+ // but handle relative paths to be safe (might happen when process.cwd()
348
+ // fails)
349
+
350
+ // Normalize the tail path
351
+ resolvedTail = normalizeStringWin32(resolvedTail, !resolvedAbsolute);
352
+
353
+ return (resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail) ||
354
+ '.';
355
+ },
356
+
357
+ normalize: function normalize(path) {
358
+ assertPath(path);
359
+ const len = path.length;
360
+ if (len === 0)
361
+ return '.';
362
+ var rootEnd = 0;
363
+ var code = path.charCodeAt(0);
364
+ var device;
365
+ var isAbsolute = false;
366
+
367
+ // Try to match a root
368
+ if (len > 1) {
369
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
370
+ // Possible UNC root
371
+
372
+ // If we started with a separator, we know we at least have an absolute
373
+ // path of some kind (UNC or otherwise)
374
+ isAbsolute = true;
375
+
376
+ code = path.charCodeAt(1);
377
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
378
+ // Matched double path separator at beginning
379
+ var j = 2;
380
+ var last = j;
381
+ // Match 1 or more non-path separators
382
+ for (; j < len; ++j) {
383
+ code = path.charCodeAt(j);
384
+ if (code === 47 /*/*/ || code === 92 /*\*/ )
385
+ break;
386
+ }
387
+ if (j < len && j !== last) {
388
+ const firstPart = path.slice(last, j);
389
+ // Matched!
390
+ last = j;
391
+ // Match 1 or more path separators
392
+ for (; j < len; ++j) {
393
+ code = path.charCodeAt(j);
394
+ if (code !== 47 /*/*/ && code !== 92 /*\*/ )
395
+ break;
396
+ }
397
+ if (j < len && j !== last) {
398
+ // Matched!
399
+ last = j;
400
+ // Match 1 or more non-path separators
401
+ for (; j < len; ++j) {
402
+ code = path.charCodeAt(j);
403
+ if (code === 47 /*/*/ || code === 92 /*\*/ )
404
+ break;
405
+ }
406
+ if (j === len) {
407
+ // We matched a UNC root only
408
+ // Return the normalized version of the UNC root since there
409
+ // is nothing left to process
410
+
411
+ return '\\\\' + firstPart + '\\' + path.slice(last) + '\\';
412
+ } else if (j !== last) {
413
+ // We matched a UNC root with leftovers
414
+
415
+ device = '\\\\' + firstPart + '\\' + path.slice(last, j);
416
+ rootEnd = j;
417
+ }
418
+ }
419
+ }
420
+ } else {
421
+ rootEnd = 1;
422
+ }
423
+ } else if ((code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
424
+ (code >= 97 /*a*/ && code <= 122 /*z*/ )) {
425
+ // Possible device root
426
+
427
+ if (path.charCodeAt(1) === 58 /*:*/ ) {
428
+ device = path.slice(0, 2);
429
+ rootEnd = 2;
430
+ if (len > 2) {
431
+ code = path.charCodeAt(2);
432
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
433
+ // Treat separator following drive name as an absolute path
434
+ // indicator
435
+ isAbsolute = true;
436
+ rootEnd = 3;
437
+ }
438
+ }
439
+ }
440
+ }
441
+ } else if (code === 47 /*/*/ || code === 92 /*\*/ ) {
442
+ // `path` contains just a path separator, exit early to avoid unnecessary
443
+ // work
444
+ return '\\';
445
+ }
446
+
447
+ code = path.charCodeAt(len - 1);
448
+ var trailingSeparator = (code === 47 /*/*/ || code === 92 /*\*/ );
449
+ var tail;
450
+ if (rootEnd < len)
451
+ tail = normalizeStringWin32(path.slice(rootEnd), !isAbsolute);
452
+ else
453
+ tail = '';
454
+ if (tail.length === 0 && !isAbsolute)
455
+ tail = '.';
456
+ if (tail.length > 0 && trailingSeparator)
457
+ tail += '\\';
458
+ if (device === undefined) {
459
+ if (isAbsolute) {
460
+ if (tail.length > 0)
461
+ return '\\' + tail;
462
+ else
463
+ return '\\';
464
+ } else if (tail.length > 0) {
465
+ return tail;
466
+ } else {
467
+ return '';
468
+ }
469
+ } else if (isAbsolute) {
470
+ if (tail.length > 0)
471
+ return device + '\\' + tail;
472
+ else
473
+ return device + '\\';
474
+ } else if (tail.length > 0) {
475
+ return device + tail;
476
+ } else {
477
+ return device;
478
+ }
479
+ },
480
+
481
+
482
+ isAbsolute: function isAbsolute(path) {
483
+ assertPath(path);
484
+ const len = path.length;
485
+ if (len === 0)
486
+ return false;
487
+ var code = path.charCodeAt(0);
488
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
489
+ return true;
490
+ } else if ((code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
491
+ (code >= 97 /*a*/ && code <= 122 /*z*/ )) {
492
+ // Possible device root
493
+
494
+ if (len > 2 && path.charCodeAt(1) === 58 /*:*/ ) {
495
+ code = path.charCodeAt(2);
496
+ if (code === 47 /*/*/ || code === 92 /*\*/ )
497
+ return true;
498
+ }
499
+ }
500
+ return false;
501
+ },
502
+
503
+
504
+ join: function join() {
505
+ if (arguments.length === 0)
506
+ return '.';
507
+
508
+ var joined;
509
+ var firstPart;
510
+ for (var i = 0; i < arguments.length; ++i) {
511
+ var arg = arguments[i];
512
+ assertPath(arg);
513
+ if (arg.length > 0) {
514
+ if (joined === undefined)
515
+ joined = firstPart = arg;
516
+ else
517
+ joined += '\\' + arg;
518
+ }
519
+ }
520
+
521
+ if (joined === undefined)
522
+ return '.';
523
+
524
+ // Make sure that the joined path doesn't start with two slashes, because
525
+ // normalize() will mistake it for an UNC path then.
526
+ //
527
+ // This step is skipped when it is very clear that the user actually
528
+ // intended to point at an UNC path. This is assumed when the first
529
+ // non-empty string arguments starts with exactly two slashes followed by
530
+ // at least one more non-slash character.
531
+ //
532
+ // Note that for normalize() to treat a path as an UNC path it needs to
533
+ // have at least 2 components, so we don't filter for that here.
534
+ // This means that the user can use join to construct UNC paths from
535
+ // a server name and a share name; for example:
536
+ // path.join('//server', 'share') -> '\\\\server\\share\\')
537
+ var needsReplace = true;
538
+ var slashCount = 0;
539
+ var code = firstPart.charCodeAt(0);
540
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
541
+ ++slashCount;
542
+ const firstLen = firstPart.length;
543
+ if (firstLen > 1) {
544
+ code = firstPart.charCodeAt(1);
545
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
546
+ ++slashCount;
547
+ if (firstLen > 2) {
548
+ code = firstPart.charCodeAt(2);
549
+ if (code === 47 /*/*/ || code === 92 /*\*/ )
550
+ ++slashCount;
551
+ else {
552
+ // We matched a UNC path in the first part
553
+ needsReplace = false;
554
+ }
555
+ }
556
+ }
557
+ }
558
+ }
559
+ if (needsReplace) {
560
+ // Find any more consecutive slashes we need to replace
561
+ for (; slashCount < joined.length; ++slashCount) {
562
+ code = joined.charCodeAt(slashCount);
563
+ if (code !== 47 /*/*/ && code !== 92 /*\*/ )
564
+ break;
565
+ }
566
+
567
+ // Replace the slashes if needed
568
+ if (slashCount >= 2)
569
+ joined = '\\' + joined.slice(slashCount);
570
+ }
571
+
572
+ return win32.normalize(joined);
573
+ },
574
+
575
+
576
+ // It will solve the relative path from `from` to `to`, for instance:
577
+ // from = 'C:\\orandea\\test\\aaa'
578
+ // to = 'C:\\orandea\\impl\\bbb'
579
+ // The output of the function should be: '..\\..\\impl\\bbb'
580
+ relative: function relative(from, to) {
581
+ assertPath(from);
582
+ assertPath(to);
583
+
584
+ if (from === to)
585
+ return '';
586
+
587
+ var fromOrig = win32.resolve(from);
588
+ var toOrig = win32.resolve(to);
589
+
590
+ if (fromOrig === toOrig)
591
+ return '';
592
+
593
+ from = fromOrig.toLowerCase();
594
+ to = toOrig.toLowerCase();
595
+
596
+ if (from === to)
597
+ return '';
598
+
599
+ // Trim any leading backslashes
600
+ var fromStart = 0;
601
+ for (; fromStart < from.length; ++fromStart) {
602
+ if (from.charCodeAt(fromStart) !== 92 /*\*/ )
603
+ break;
604
+ }
605
+ // Trim trailing backslashes (applicable to UNC paths only)
606
+ var fromEnd = from.length;
607
+ for (; fromEnd - 1 > fromStart; --fromEnd) {
608
+ if (from.charCodeAt(fromEnd - 1) !== 92 /*\*/ )
609
+ break;
610
+ }
611
+ var fromLen = (fromEnd - fromStart);
612
+
613
+ // Trim any leading backslashes
614
+ var toStart = 0;
615
+ for (; toStart < to.length; ++toStart) {
616
+ if (to.charCodeAt(toStart) !== 92 /*\*/ )
617
+ break;
618
+ }
619
+ // Trim trailing backslashes (applicable to UNC paths only)
620
+ var toEnd = to.length;
621
+ for (; toEnd - 1 > toStart; --toEnd) {
622
+ if (to.charCodeAt(toEnd - 1) !== 92 /*\*/ )
623
+ break;
624
+ }
625
+ var toLen = (toEnd - toStart);
626
+
627
+ // Compare paths to find the longest common path from root
628
+ var length = (fromLen < toLen ? fromLen : toLen);
629
+ var lastCommonSep = -1;
630
+ var i = 0;
631
+ for (; i <= length; ++i) {
632
+ if (i === length) {
633
+ if (toLen > length) {
634
+ if (to.charCodeAt(toStart + i) === 92 /*\*/ ) {
635
+ // We get here if `from` is the exact base path for `to`.
636
+ // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
637
+ return toOrig.slice(toStart + i + 1);
638
+ } else if (i === 2) {
639
+ // We get here if `from` is the device root.
640
+ // For example: from='C:\\'; to='C:\\foo'
641
+ return toOrig.slice(toStart + i);
642
+ }
643
+ }
644
+ if (fromLen > length) {
645
+ if (from.charCodeAt(fromStart + i) === 92 /*\*/ ) {
646
+ // We get here if `to` is the exact base path for `from`.
647
+ // For example: from='C:\\foo\\bar'; to='C:\\foo'
648
+ lastCommonSep = i;
649
+ } else if (i === 2) {
650
+ // We get here if `to` is the device root.
651
+ // For example: from='C:\\foo\\bar'; to='C:\\'
652
+ lastCommonSep = 3;
653
+ }
654
+ }
655
+ break;
656
+ }
657
+ var fromCode = from.charCodeAt(fromStart + i);
658
+ var toCode = to.charCodeAt(toStart + i);
659
+ if (fromCode !== toCode)
660
+ break;
661
+ else if (fromCode === 92 /*\*/ )
662
+ lastCommonSep = i;
663
+ }
664
+
665
+ // We found a mismatch before the first common path separator was seen, so
666
+ // return the original `to`.
667
+ if (i !== length && lastCommonSep === -1) {
668
+ return toOrig;
669
+ }
670
+
671
+ var out = '';
672
+ if (lastCommonSep === -1)
673
+ lastCommonSep = 0;
674
+ // Generate the relative path based on the path difference between `to` and
675
+ // `from`
676
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
677
+ if (i === fromEnd || from.charCodeAt(i) === 92 /*\*/ ) {
678
+ if (out.length === 0)
679
+ out += '..';
680
+ else
681
+ out += '\\..';
682
+ }
683
+ }
684
+
685
+ // Lastly, append the rest of the destination (`to`) path that comes after
686
+ // the common path parts
687
+ if (out.length > 0)
688
+ return out + toOrig.slice(toStart + lastCommonSep, toEnd);
689
+ else {
690
+ toStart += lastCommonSep;
691
+ if (toOrig.charCodeAt(toStart) === 92 /*\*/ )
692
+ ++toStart;
693
+ return toOrig.slice(toStart, toEnd);
694
+ }
695
+ },
696
+
697
+
698
+ toNamespacedPath: function toNamespacedPath(path) {
699
+ // Note: this will *probably* throw somewhere.
700
+ if (typeof path !== 'string')
701
+ return path;
702
+
703
+ if (path.length === 0) {
704
+ return '';
705
+ }
706
+
707
+ const resolvedPath = win32.resolve(path);
708
+
709
+ if (resolvedPath.length >= 3) {
710
+ var code = resolvedPath.charCodeAt(0);
711
+ if (code === 92 /*\*/ ) {
712
+ // Possible UNC root
713
+
714
+ if (resolvedPath.charCodeAt(1) === 92 /*\*/ ) {
715
+ code = resolvedPath.charCodeAt(2);
716
+ if (code !== 63 /*?*/ && code !== 46 /*.*/ ) {
717
+ // Matched non-long UNC root, convert the path to a long UNC path
718
+ return '\\\\?\\UNC\\' + resolvedPath.slice(2);
719
+ }
720
+ }
721
+ } else if ((code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
722
+ (code >= 97 /*a*/ && code <= 122 /*z*/ )) {
723
+ // Possible device root
724
+
725
+ if (resolvedPath.charCodeAt(1) === 58 /*:*/ &&
726
+ resolvedPath.charCodeAt(2) === 92 /*\*/ ) {
727
+ // Matched device root, convert the path to a long UNC path
728
+ return '\\\\?\\' + resolvedPath;
729
+ }
730
+ }
731
+ }
732
+
733
+ return path;
734
+ },
735
+
736
+ dirname: function dirname(path) {
737
+ assertPath(path);
738
+ const len = path.length;
739
+ if (len === 0)
740
+ return '.';
741
+ var rootEnd = -1;
742
+ var end = -1;
743
+ var matchedSlash = true;
744
+ var offset = 0;
745
+ var code = path.charCodeAt(0);
746
+
747
+ // Try to match a root
748
+ if (len > 1) {
749
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
750
+ // Possible UNC root
751
+
752
+ rootEnd = offset = 1;
753
+
754
+ code = path.charCodeAt(1);
755
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
756
+ // Matched double path separator at beginning
757
+ var j = 2;
758
+ var last = j;
759
+ // Match 1 or more non-path separators
760
+ for (; j < len; ++j) {
761
+ code = path.charCodeAt(j);
762
+ if (code === 47 /*/*/ || code === 92 /*\*/ )
763
+ break;
764
+ }
765
+ if (j < len && j !== last) {
766
+ // Matched!
767
+ last = j;
768
+ // Match 1 or more path separators
769
+ for (; j < len; ++j) {
770
+ code = path.charCodeAt(j);
771
+ if (code !== 47 /*/*/ && code !== 92 /*\*/ )
772
+ break;
773
+ }
774
+ if (j < len && j !== last) {
775
+ // Matched!
776
+ last = j;
777
+ // Match 1 or more non-path separators
778
+ for (; j < len; ++j) {
779
+ code = path.charCodeAt(j);
780
+ if (code === 47 /*/*/ || code === 92 /*\*/ )
781
+ break;
782
+ }
783
+ if (j === len) {
784
+ // We matched a UNC root only
785
+ return path;
786
+ }
787
+ if (j !== last) {
788
+ // We matched a UNC root with leftovers
789
+
790
+ // Offset by 1 to include the separator after the UNC root to
791
+ // treat it as a "normal root" on top of a (UNC) root
792
+ rootEnd = offset = j + 1;
793
+ }
794
+ }
795
+ }
796
+ }
797
+ } else if ((code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
798
+ (code >= 97 /*a*/ && code <= 122 /*z*/ )) {
799
+ // Possible device root
800
+
801
+ if (path.charCodeAt(1) === 58 /*:*/ ) {
802
+ rootEnd = offset = 2;
803
+ if (len > 2) {
804
+ code = path.charCodeAt(2);
805
+ if (code === 47 /*/*/ || code === 92 /*\*/ )
806
+ rootEnd = offset = 3;
807
+ }
808
+ }
809
+ }
810
+ } else if (code === 47 /*/*/ || code === 92 /*\*/ ) {
811
+ // `path` contains just a path separator, exit early to avoid
812
+ // unnecessary work
813
+ return path;
814
+ }
815
+
816
+ for (var i = len - 1; i >= offset; --i) {
817
+ code = path.charCodeAt(i);
818
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
819
+ if (!matchedSlash) {
820
+ end = i;
821
+ break;
822
+ }
823
+ } else {
824
+ // We saw the first non-path separator
825
+ matchedSlash = false;
826
+ }
827
+ }
828
+
829
+ if (end === -1) {
830
+ if (rootEnd === -1)
831
+ return '.';
832
+ else
833
+ end = rootEnd;
834
+ }
835
+ return path.slice(0, end);
836
+ },
837
+
838
+
839
+ basename: function basename(path, ext) {
840
+ if (ext !== undefined && typeof ext !== 'string')
841
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ext', 'string');
842
+ assertPath(path);
843
+ var start = 0;
844
+ var end = -1;
845
+ var matchedSlash = true;
846
+ var i;
847
+
848
+ // Check for a drive letter prefix so as not to mistake the following
849
+ // path separator as an extra separator at the end of the path that can be
850
+ // disregarded
851
+ if (path.length >= 2) {
852
+ const drive = path.charCodeAt(0);
853
+ if ((drive >= 65 /*A*/ && drive <= 90 /*Z*/ ) ||
854
+ (drive >= 97 /*a*/ && drive <= 122 /*z*/ )) {
855
+ if (path.charCodeAt(1) === 58 /*:*/ )
856
+ start = 2;
857
+ }
858
+ }
859
+
860
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
861
+ if (ext.length === path.length && ext === path)
862
+ return '';
863
+ var extIdx = ext.length - 1;
864
+ var firstNonSlashEnd = -1;
865
+ for (i = path.length - 1; i >= start; --i) {
866
+ const code = path.charCodeAt(i);
867
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
868
+ // If we reached a path separator that was not part of a set of path
869
+ // separators at the end of the string, stop now
870
+ if (!matchedSlash) {
871
+ start = i + 1;
872
+ break;
873
+ }
874
+ } else {
875
+ if (firstNonSlashEnd === -1) {
876
+ // We saw the first non-path separator, remember this index in case
877
+ // we need it if the extension ends up not matching
878
+ matchedSlash = false;
879
+ firstNonSlashEnd = i + 1;
880
+ }
881
+ if (extIdx >= 0) {
882
+ // Try to match the explicit extension
883
+ if (code === ext.charCodeAt(extIdx)) {
884
+ if (--extIdx === -1) {
885
+ // We matched the extension, so mark this as the end of our path
886
+ // component
887
+ end = i;
888
+ }
889
+ } else {
890
+ // Extension does not match, so our result is the entire path
891
+ // component
892
+ extIdx = -1;
893
+ end = firstNonSlashEnd;
894
+ }
895
+ }
896
+ }
897
+ }
898
+
899
+ if (start === end)
900
+ end = firstNonSlashEnd;
901
+ else if (end === -1)
902
+ end = path.length;
903
+ return path.slice(start, end);
904
+ } else {
905
+ for (i = path.length - 1; i >= start; --i) {
906
+ const code = path.charCodeAt(i);
907
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
908
+ // If we reached a path separator that was not part of a set of path
909
+ // separators at the end of the string, stop now
910
+ if (!matchedSlash) {
911
+ start = i + 1;
912
+ break;
913
+ }
914
+ } else if (end === -1) {
915
+ // We saw the first non-path separator, mark this as the end of our
916
+ // path component
917
+ matchedSlash = false;
918
+ end = i + 1;
919
+ }
920
+ }
921
+
922
+ if (end === -1)
923
+ return '';
924
+ return path.slice(start, end);
925
+ }
926
+ },
927
+
928
+
929
+ extname: function extname(path) {
930
+ assertPath(path);
931
+ var start = 0;
932
+ var startDot = -1;
933
+ var startPart = 0;
934
+ var end = -1;
935
+ var matchedSlash = true;
936
+ // Track the state of characters (if any) we see before our first dot and
937
+ // after any path separator we find
938
+ var preDotState = 0;
939
+
940
+ // Check for a drive letter prefix so as not to mistake the following
941
+ // path separator as an extra separator at the end of the path that can be
942
+ // disregarded
943
+ if (path.length >= 2) {
944
+ const code = path.charCodeAt(0);
945
+ if (path.charCodeAt(1) === 58 /*:*/ &&
946
+ ((code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
947
+ (code >= 97 /*a*/ && code <= 122 /*z*/ ))) {
948
+ start = startPart = 2;
949
+ }
950
+ }
951
+
952
+ for (var i = path.length - 1; i >= start; --i) {
953
+ const code = path.charCodeAt(i);
954
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
955
+ // If we reached a path separator that was not part of a set of path
956
+ // separators at the end of the string, stop now
957
+ if (!matchedSlash) {
958
+ startPart = i + 1;
959
+ break;
960
+ }
961
+ continue;
962
+ }
963
+ if (end === -1) {
964
+ // We saw the first non-path separator, mark this as the end of our
965
+ // extension
966
+ matchedSlash = false;
967
+ end = i + 1;
968
+ }
969
+ if (code === 46 /*.*/ ) {
970
+ // If this is our first dot, mark it as the start of our extension
971
+ if (startDot === -1)
972
+ startDot = i;
973
+ else if (preDotState !== 1)
974
+ preDotState = 1;
975
+ } else if (startDot !== -1) {
976
+ // We saw a non-dot and non-path separator before our dot, so we should
977
+ // have a good chance at having a non-empty extension
978
+ preDotState = -1;
979
+ }
980
+ }
981
+
982
+ if (startDot === -1 ||
983
+ end === -1 ||
984
+ // We saw a non-dot character immediately before the dot
985
+ preDotState === 0 ||
986
+ // The (right-most) trimmed path component is exactly '..'
987
+ (preDotState === 1 &&
988
+ startDot === end - 1 &&
989
+ startDot === startPart + 1)) {
990
+ return '';
991
+ }
992
+ return path.slice(startDot, end);
993
+ },
994
+
995
+
996
+ format: function format(pathObject) {
997
+ if (pathObject === null || typeof pathObject !== 'object') {
998
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object',
999
+ pathObject);
1000
+ }
1001
+ return _format('\\', pathObject);
1002
+ },
1003
+
1004
+
1005
+ parse: function parse(path) {
1006
+ assertPath(path);
1007
+
1008
+ var ret = {
1009
+ root: '',
1010
+ dir: '',
1011
+ base: '',
1012
+ ext: '',
1013
+ name: ''
1014
+ };
1015
+ if (path.length === 0)
1016
+ return ret;
1017
+
1018
+ var len = path.length;
1019
+ var rootEnd = 0;
1020
+ var code = path.charCodeAt(0);
1021
+
1022
+ // Try to match a root
1023
+ if (len > 1) {
1024
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
1025
+ // Possible UNC root
1026
+
1027
+ code = path.charCodeAt(1);
1028
+ rootEnd = 1;
1029
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
1030
+ // Matched double path separator at beginning
1031
+ var j = 2;
1032
+ var last = j;
1033
+ // Match 1 or more non-path separators
1034
+ for (; j < len; ++j) {
1035
+ code = path.charCodeAt(j);
1036
+ if (code === 47 /*/*/ || code === 92 /*\*/ )
1037
+ break;
1038
+ }
1039
+ if (j < len && j !== last) {
1040
+ // Matched!
1041
+ last = j;
1042
+ // Match 1 or more path separators
1043
+ for (; j < len; ++j) {
1044
+ code = path.charCodeAt(j);
1045
+ if (code !== 47 /*/*/ && code !== 92 /*\*/ )
1046
+ break;
1047
+ }
1048
+ if (j < len && j !== last) {
1049
+ // Matched!
1050
+ last = j;
1051
+ // Match 1 or more non-path separators
1052
+ for (; j < len; ++j) {
1053
+ code = path.charCodeAt(j);
1054
+ if (code === 47 /*/*/ || code === 92 /*\*/ )
1055
+ break;
1056
+ }
1057
+ if (j === len) {
1058
+ // We matched a UNC root only
1059
+
1060
+ rootEnd = j;
1061
+ } else if (j !== last) {
1062
+ // We matched a UNC root with leftovers
1063
+
1064
+ rootEnd = j + 1;
1065
+ }
1066
+ }
1067
+ }
1068
+ }
1069
+ } else if ((code >= 65 /*A*/ && code <= 90 /*Z*/ ) ||
1070
+ (code >= 97 /*a*/ && code <= 122 /*z*/ )) {
1071
+ // Possible device root
1072
+
1073
+ if (path.charCodeAt(1) === 58 /*:*/ ) {
1074
+ rootEnd = 2;
1075
+ if (len > 2) {
1076
+ code = path.charCodeAt(2);
1077
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
1078
+ if (len === 3) {
1079
+ // `path` contains just a drive root, exit early to avoid
1080
+ // unnecessary work
1081
+ ret.root = ret.dir = path;
1082
+ return ret;
1083
+ }
1084
+ rootEnd = 3;
1085
+ }
1086
+ } else {
1087
+ // `path` contains just a drive root, exit early to avoid
1088
+ // unnecessary work
1089
+ ret.root = ret.dir = path;
1090
+ return ret;
1091
+ }
1092
+ }
1093
+ }
1094
+ } else if (code === 47 /*/*/ || code === 92 /*\*/ ) {
1095
+ // `path` contains just a path separator, exit early to avoid
1096
+ // unnecessary work
1097
+ ret.root = ret.dir = path;
1098
+ return ret;
1099
+ }
1100
+
1101
+ if (rootEnd > 0)
1102
+ ret.root = path.slice(0, rootEnd);
1103
+
1104
+ var startDot = -1;
1105
+ var startPart = rootEnd;
1106
+ var end = -1;
1107
+ var matchedSlash = true;
1108
+ var i = path.length - 1;
1109
+
1110
+ // Track the state of characters (if any) we see before our first dot and
1111
+ // after any path separator we find
1112
+ var preDotState = 0;
1113
+
1114
+ // Get non-dir info
1115
+ for (; i >= rootEnd; --i) {
1116
+ code = path.charCodeAt(i);
1117
+ if (code === 47 /*/*/ || code === 92 /*\*/ ) {
1118
+ // If we reached a path separator that was not part of a set of path
1119
+ // separators at the end of the string, stop now
1120
+ if (!matchedSlash) {
1121
+ startPart = i + 1;
1122
+ break;
1123
+ }
1124
+ continue;
1125
+ }
1126
+ if (end === -1) {
1127
+ // We saw the first non-path separator, mark this as the end of our
1128
+ // extension
1129
+ matchedSlash = false;
1130
+ end = i + 1;
1131
+ }
1132
+ if (code === 46 /*.*/ ) {
1133
+ // If this is our first dot, mark it as the start of our extension
1134
+ if (startDot === -1)
1135
+ startDot = i;
1136
+ else if (preDotState !== 1)
1137
+ preDotState = 1;
1138
+ } else if (startDot !== -1) {
1139
+ // We saw a non-dot and non-path separator before our dot, so we should
1140
+ // have a good chance at having a non-empty extension
1141
+ preDotState = -1;
1142
+ }
1143
+ }
1144
+
1145
+ if (startDot === -1 ||
1146
+ end === -1 ||
1147
+ // We saw a non-dot character immediately before the dot
1148
+ preDotState === 0 ||
1149
+ // The (right-most) trimmed path component is exactly '..'
1150
+ (preDotState === 1 &&
1151
+ startDot === end - 1 &&
1152
+ startDot === startPart + 1)) {
1153
+ if (end !== -1) {
1154
+ ret.base = ret.name = path.slice(startPart, end);
1155
+ }
1156
+ } else {
1157
+ ret.name = path.slice(startPart, startDot);
1158
+ ret.base = path.slice(startPart, end);
1159
+ ret.ext = path.slice(startDot, end);
1160
+ }
1161
+
1162
+ // If the directory is the root, use the entire root as the `dir` including
1163
+ // the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the
1164
+ // trailing slash (`C:\abc\def` -> `C:\abc`).
1165
+ if (startPart > 0 && startPart !== rootEnd)
1166
+ ret.dir = path.slice(0, startPart - 1);
1167
+ else
1168
+ ret.dir = ret.root;
1169
+
1170
+ return ret;
1171
+ },
1172
+
1173
+
1174
+ sep: '\\',
1175
+ delimiter: ';',
1176
+ win32: null,
1177
+ posix: null
1178
+ };
1179
+
1180
+
1181
+ const posix = {
1182
+ // path.resolve([from ...], to)
1183
+ resolve: function resolve() {
1184
+ var resolvedPath = '';
1185
+ var resolvedAbsolute = false;
1186
+ var cwd;
1187
+
1188
+ for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
1189
+ var path;
1190
+ if (i >= 0)
1191
+ path = arguments[i];
1192
+ else {
1193
+ if (cwd === undefined)
1194
+ "/";
1195
+ path = cwd;
1196
+ }
1197
+
1198
+ assertPath(path);
1199
+
1200
+ // Skip empty entries
1201
+ if (path.length === 0) {
1202
+ continue;
1203
+ }
1204
+
1205
+ resolvedPath = path + '/' + resolvedPath;
1206
+ resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/ ;
1207
+ }
1208
+
1209
+ // At this point the path should be resolved to a full absolute path, but
1210
+ // handle relative paths to be safe (might happen when process.cwd() fails)
1211
+
1212
+ // Normalize the path
1213
+ resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute);
1214
+
1215
+ if (resolvedAbsolute) {
1216
+ if (resolvedPath.length > 0)
1217
+ return '/' + resolvedPath;
1218
+ else
1219
+ return '/';
1220
+ } else if (resolvedPath.length > 0) {
1221
+ return resolvedPath;
1222
+ } else {
1223
+ return '.';
1224
+ }
1225
+ },
1226
+
1227
+
1228
+ normalize: function normalize(path) {
1229
+ assertPath(path);
1230
+
1231
+ if (path.length === 0)
1232
+ return '.';
1233
+
1234
+ const isAbsolute = path.charCodeAt(0) === 47 /*/*/ ;
1235
+ const trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/ ;
1236
+
1237
+ // Normalize the path
1238
+ path = normalizeStringPosix(path, !isAbsolute);
1239
+
1240
+ if (path.length === 0 && !isAbsolute)
1241
+ path = '.';
1242
+ if (path.length > 0 && trailingSeparator)
1243
+ path += '/';
1244
+
1245
+ if (isAbsolute)
1246
+ return '/' + path;
1247
+ return path;
1248
+ },
1249
+
1250
+
1251
+ isAbsolute: function isAbsolute(path) {
1252
+ assertPath(path);
1253
+ return path.length > 0 && path.charCodeAt(0) === 47 /*/*/ ;
1254
+ },
1255
+
1256
+
1257
+ join: function join() {
1258
+ if (arguments.length === 0)
1259
+ return '.';
1260
+ var joined;
1261
+ for (var i = 0; i < arguments.length; ++i) {
1262
+ var arg = arguments[i];
1263
+ assertPath(arg);
1264
+ if (arg.length > 0) {
1265
+ if (joined === undefined)
1266
+ joined = arg;
1267
+ else
1268
+ joined += '/' + arg;
1269
+ }
1270
+ }
1271
+ if (joined === undefined)
1272
+ return '.';
1273
+ return posix.normalize(joined);
1274
+ },
1275
+
1276
+
1277
+ relative: function relative(from, to) {
1278
+ assertPath(from);
1279
+ assertPath(to);
1280
+
1281
+ if (from === to)
1282
+ return '';
1283
+
1284
+ from = posix.resolve(from);
1285
+ to = posix.resolve(to);
1286
+
1287
+ if (from === to)
1288
+ return '';
1289
+
1290
+ // Trim any leading backslashes
1291
+ var fromStart = 1;
1292
+ for (; fromStart < from.length; ++fromStart) {
1293
+ if (from.charCodeAt(fromStart) !== 47 /*/*/ )
1294
+ break;
1295
+ }
1296
+ var fromEnd = from.length;
1297
+ var fromLen = (fromEnd - fromStart);
1298
+
1299
+ // Trim any leading backslashes
1300
+ var toStart = 1;
1301
+ for (; toStart < to.length; ++toStart) {
1302
+ if (to.charCodeAt(toStart) !== 47 /*/*/ )
1303
+ break;
1304
+ }
1305
+ var toEnd = to.length;
1306
+ var toLen = (toEnd - toStart);
1307
+
1308
+ // Compare paths to find the longest common path from root
1309
+ var length = (fromLen < toLen ? fromLen : toLen);
1310
+ var lastCommonSep = -1;
1311
+ var i = 0;
1312
+ for (; i <= length; ++i) {
1313
+ if (i === length) {
1314
+ if (toLen > length) {
1315
+ if (to.charCodeAt(toStart + i) === 47 /*/*/ ) {
1316
+ // We get here if `from` is the exact base path for `to`.
1317
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
1318
+ return to.slice(toStart + i + 1);
1319
+ } else if (i === 0) {
1320
+ // We get here if `from` is the root
1321
+ // For example: from='/'; to='/foo'
1322
+ return to.slice(toStart + i);
1323
+ }
1324
+ } else if (fromLen > length) {
1325
+ if (from.charCodeAt(fromStart + i) === 47 /*/*/ ) {
1326
+ // We get here if `to` is the exact base path for `from`.
1327
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
1328
+ lastCommonSep = i;
1329
+ } else if (i === 0) {
1330
+ // We get here if `to` is the root.
1331
+ // For example: from='/foo'; to='/'
1332
+ lastCommonSep = 0;
1333
+ }
1334
+ }
1335
+ break;
1336
+ }
1337
+ var fromCode = from.charCodeAt(fromStart + i);
1338
+ var toCode = to.charCodeAt(toStart + i);
1339
+ if (fromCode !== toCode)
1340
+ break;
1341
+ else if (fromCode === 47 /*/*/ )
1342
+ lastCommonSep = i;
1343
+ }
1344
+
1345
+ var out = '';
1346
+ // Generate the relative path based on the path difference between `to`
1347
+ // and `from`
1348
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
1349
+ if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/ ) {
1350
+ if (out.length === 0)
1351
+ out += '..';
1352
+ else
1353
+ out += '/..';
1354
+ }
1355
+ }
1356
+
1357
+ // Lastly, append the rest of the destination (`to`) path that comes after
1358
+ // the common path parts
1359
+ if (out.length > 0)
1360
+ return out + to.slice(toStart + lastCommonSep);
1361
+ else {
1362
+ toStart += lastCommonSep;
1363
+ if (to.charCodeAt(toStart) === 47 /*/*/ )
1364
+ ++toStart;
1365
+ return to.slice(toStart);
1366
+ }
1367
+ },
1368
+
1369
+
1370
+ toNamespacedPath: function toNamespacedPath(path) {
1371
+ // Non-op on posix systems
1372
+ return path;
1373
+ },
1374
+
1375
+ dirname: function dirname(path) {
1376
+ assertPath(path);
1377
+ if (path.length === 0)
1378
+ return '.';
1379
+ var code = path.charCodeAt(0);
1380
+ var hasRoot = (code === 47 /*/*/ );
1381
+ var end = -1;
1382
+ var matchedSlash = true;
1383
+ for (var i = path.length - 1; i >= 1; --i) {
1384
+ code = path.charCodeAt(i);
1385
+ if (code === 47 /*/*/ ) {
1386
+ if (!matchedSlash) {
1387
+ end = i;
1388
+ break;
1389
+ }
1390
+ } else {
1391
+ // We saw the first non-path separator
1392
+ matchedSlash = false;
1393
+ }
1394
+ }
1395
+
1396
+ if (end === -1)
1397
+ return hasRoot ? '/' : '.';
1398
+ if (hasRoot && end === 1)
1399
+ return '//';
1400
+ return path.slice(0, end);
1401
+ },
1402
+
1403
+
1404
+ basename: function basename(path, ext) {
1405
+ if (ext !== undefined && typeof ext !== 'string')
1406
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'ext', 'string');
1407
+ assertPath(path);
1408
+
1409
+ var start = 0;
1410
+ var end = -1;
1411
+ var matchedSlash = true;
1412
+ var i;
1413
+
1414
+ if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
1415
+ if (ext.length === path.length && ext === path)
1416
+ return '';
1417
+ var extIdx = ext.length - 1;
1418
+ var firstNonSlashEnd = -1;
1419
+ for (i = path.length - 1; i >= 0; --i) {
1420
+ const code = path.charCodeAt(i);
1421
+ if (code === 47 /*/*/ ) {
1422
+ // If we reached a path separator that was not part of a set of path
1423
+ // separators at the end of the string, stop now
1424
+ if (!matchedSlash) {
1425
+ start = i + 1;
1426
+ break;
1427
+ }
1428
+ } else {
1429
+ if (firstNonSlashEnd === -1) {
1430
+ // We saw the first non-path separator, remember this index in case
1431
+ // we need it if the extension ends up not matching
1432
+ matchedSlash = false;
1433
+ firstNonSlashEnd = i + 1;
1434
+ }
1435
+ if (extIdx >= 0) {
1436
+ // Try to match the explicit extension
1437
+ if (code === ext.charCodeAt(extIdx)) {
1438
+ if (--extIdx === -1) {
1439
+ // We matched the extension, so mark this as the end of our path
1440
+ // component
1441
+ end = i;
1442
+ }
1443
+ } else {
1444
+ // Extension does not match, so our result is the entire path
1445
+ // component
1446
+ extIdx = -1;
1447
+ end = firstNonSlashEnd;
1448
+ }
1449
+ }
1450
+ }
1451
+ }
1452
+
1453
+ if (start === end)
1454
+ end = firstNonSlashEnd;
1455
+ else if (end === -1)
1456
+ end = path.length;
1457
+ return path.slice(start, end);
1458
+ } else {
1459
+ for (i = path.length - 1; i >= 0; --i) {
1460
+ if (path.charCodeAt(i) === 47 /*/*/ ) {
1461
+ // If we reached a path separator that was not part of a set of path
1462
+ // separators at the end of the string, stop now
1463
+ if (!matchedSlash) {
1464
+ start = i + 1;
1465
+ break;
1466
+ }
1467
+ } else if (end === -1) {
1468
+ // We saw the first non-path separator, mark this as the end of our
1469
+ // path component
1470
+ matchedSlash = false;
1471
+ end = i + 1;
1472
+ }
1473
+ }
1474
+
1475
+ if (end === -1)
1476
+ return '';
1477
+ return path.slice(start, end);
1478
+ }
1479
+ },
1480
+
1481
+
1482
+ extname: function extname(path) {
1483
+ assertPath(path);
1484
+ var startDot = -1;
1485
+ var startPart = 0;
1486
+ var end = -1;
1487
+ var matchedSlash = true;
1488
+ // Track the state of characters (if any) we see before our first dot and
1489
+ // after any path separator we find
1490
+ var preDotState = 0;
1491
+ for (var i = path.length - 1; i >= 0; --i) {
1492
+ const code = path.charCodeAt(i);
1493
+ if (code === 47 /*/*/ ) {
1494
+ // If we reached a path separator that was not part of a set of path
1495
+ // separators at the end of the string, stop now
1496
+ if (!matchedSlash) {
1497
+ startPart = i + 1;
1498
+ break;
1499
+ }
1500
+ continue;
1501
+ }
1502
+ if (end === -1) {
1503
+ // We saw the first non-path separator, mark this as the end of our
1504
+ // extension
1505
+ matchedSlash = false;
1506
+ end = i + 1;
1507
+ }
1508
+ if (code === 46 /*.*/ ) {
1509
+ // If this is our first dot, mark it as the start of our extension
1510
+ if (startDot === -1)
1511
+ startDot = i;
1512
+ else if (preDotState !== 1)
1513
+ preDotState = 1;
1514
+ } else if (startDot !== -1) {
1515
+ // We saw a non-dot and non-path separator before our dot, so we should
1516
+ // have a good chance at having a non-empty extension
1517
+ preDotState = -1;
1518
+ }
1519
+ }
1520
+
1521
+ if (startDot === -1 ||
1522
+ end === -1 ||
1523
+ // We saw a non-dot character immediately before the dot
1524
+ preDotState === 0 ||
1525
+ // The (right-most) trimmed path component is exactly '..'
1526
+ (preDotState === 1 &&
1527
+ startDot === end - 1 &&
1528
+ startDot === startPart + 1)) {
1529
+ return '';
1530
+ }
1531
+ return path.slice(startDot, end);
1532
+ },
1533
+
1534
+
1535
+ format: function format(pathObject) {
1536
+ if (pathObject === null || typeof pathObject !== 'object') {
1537
+ throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object',
1538
+ pathObject);
1539
+ }
1540
+ return _format('/', pathObject);
1541
+ },
1542
+
1543
+
1544
+ parse: function parse(path) {
1545
+ assertPath(path);
1546
+
1547
+ var ret = {
1548
+ root: '',
1549
+ dir: '',
1550
+ base: '',
1551
+ ext: '',
1552
+ name: ''
1553
+ };
1554
+ if (path.length === 0)
1555
+ return ret;
1556
+ var code = path.charCodeAt(0);
1557
+ var isAbsolute = (code === 47 /*/*/ );
1558
+ var start;
1559
+ if (isAbsolute) {
1560
+ ret.root = '/';
1561
+ start = 1;
1562
+ } else {
1563
+ start = 0;
1564
+ }
1565
+ var startDot = -1;
1566
+ var startPart = 0;
1567
+ var end = -1;
1568
+ var matchedSlash = true;
1569
+ var i = path.length - 1;
1570
+
1571
+ // Track the state of characters (if any) we see before our first dot and
1572
+ // after any path separator we find
1573
+ var preDotState = 0;
1574
+
1575
+ // Get non-dir info
1576
+ for (; i >= start; --i) {
1577
+ code = path.charCodeAt(i);
1578
+ if (code === 47 /*/*/ ) {
1579
+ // If we reached a path separator that was not part of a set of path
1580
+ // separators at the end of the string, stop now
1581
+ if (!matchedSlash) {
1582
+ startPart = i + 1;
1583
+ break;
1584
+ }
1585
+ continue;
1586
+ }
1587
+ if (end === -1) {
1588
+ // We saw the first non-path separator, mark this as the end of our
1589
+ // extension
1590
+ matchedSlash = false;
1591
+ end = i + 1;
1592
+ }
1593
+ if (code === 46 /*.*/ ) {
1594
+ // If this is our first dot, mark it as the start of our extension
1595
+ if (startDot === -1)
1596
+ startDot = i;
1597
+ else if (preDotState !== 1)
1598
+ preDotState = 1;
1599
+ } else if (startDot !== -1) {
1600
+ // We saw a non-dot and non-path separator before our dot, so we should
1601
+ // have a good chance at having a non-empty extension
1602
+ preDotState = -1;
1603
+ }
1604
+ }
1605
+
1606
+ if (startDot === -1 ||
1607
+ end === -1 ||
1608
+ // We saw a non-dot character immediately before the dot
1609
+ preDotState === 0 ||
1610
+ // The (right-most) trimmed path component is exactly '..'
1611
+ (preDotState === 1 &&
1612
+ startDot === end - 1 &&
1613
+ startDot === startPart + 1)) {
1614
+ if (end !== -1) {
1615
+ if (startPart === 0 && isAbsolute)
1616
+ ret.base = ret.name = path.slice(1, end);
1617
+ else
1618
+ ret.base = ret.name = path.slice(startPart, end);
1619
+ }
1620
+ } else {
1621
+ if (startPart === 0 && isAbsolute) {
1622
+ ret.name = path.slice(1, startDot);
1623
+ ret.base = path.slice(1, end);
1624
+ } else {
1625
+ ret.name = path.slice(startPart, startDot);
1626
+ ret.base = path.slice(startPart, end);
1627
+ }
1628
+ ret.ext = path.slice(startDot, end);
1629
+ }
1630
+
1631
+ if (startPart > 0)
1632
+ ret.dir = path.slice(0, startPart - 1);
1633
+ else if (isAbsolute)
1634
+ ret.dir = '/';
1635
+
1636
+ return ret;
1637
+ },
1638
+
1639
+
1640
+ sep: '/',
1641
+ delimiter: ':',
1642
+ win32: null,
1643
+ posix: null
1644
+ };
1645
+
1646
+ posix.win32 = win32.win32 = win32;
1647
+ posix.posix = win32.posix = posix;
1648
+
1649
+ methods.path = posix; // default to Posix
1650
+ return (methods[modpath]);
1651
+ };
1652
+
1653
+ })(typeof exports === 'undefined' ? (this.Naanlang?this.Naanlang:this.Naanlang={}) : exports);