@docusaurus/utils 2.0.0-beta.fbdeefcac → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/constants.d.ts +73 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +78 -0
- package/lib/constants.js.map +1 -0
- package/lib/dataFileUtils.d.ts +60 -0
- package/lib/dataFileUtils.d.ts.map +1 -0
- package/lib/dataFileUtils.js +91 -0
- package/lib/dataFileUtils.js.map +1 -0
- package/lib/emitUtils.d.ts +32 -0
- package/lib/emitUtils.d.ts.map +1 -0
- package/lib/emitUtils.js +80 -0
- package/lib/emitUtils.js.map +1 -0
- package/lib/gitUtils.d.ts +66 -0
- package/lib/gitUtils.d.ts.map +1 -0
- package/lib/gitUtils.js +63 -0
- package/lib/gitUtils.js.map +1 -0
- package/lib/globUtils.d.ts +40 -0
- package/lib/globUtils.d.ts.map +1 -0
- package/lib/globUtils.js +71 -0
- package/lib/globUtils.js.map +1 -0
- package/lib/hashUtils.d.ts +6 -4
- package/lib/hashUtils.d.ts.map +1 -0
- package/lib/hashUtils.js +13 -10
- package/lib/hashUtils.js.map +1 -0
- package/lib/i18nUtils.d.ts +53 -0
- package/lib/i18nUtils.d.ts.map +1 -0
- package/lib/i18nUtils.js +70 -0
- package/lib/i18nUtils.js.map +1 -0
- package/lib/index.d.ts +16 -75
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +91 -395
- package/lib/index.js.map +1 -0
- package/lib/jsUtils.d.ts +28 -0
- package/lib/jsUtils.d.ts.map +1 -0
- package/lib/jsUtils.js +57 -0
- package/lib/jsUtils.js.map +1 -0
- package/lib/markdownLinks.d.ts +49 -5
- package/lib/markdownLinks.d.ts.map +1 -0
- package/lib/markdownLinks.js +57 -13
- package/lib/markdownLinks.js.map +1 -0
- package/lib/markdownUtils.d.ts +112 -0
- package/lib/markdownUtils.d.ts.map +1 -0
- package/lib/markdownUtils.js +271 -0
- package/lib/markdownUtils.js.map +1 -0
- package/lib/pathUtils.d.ts +45 -1
- package/lib/pathUtils.d.ts.map +1 -0
- package/lib/pathUtils.js +92 -12
- package/lib/pathUtils.js.map +1 -0
- package/lib/shellUtils.d.ts +8 -0
- package/lib/shellUtils.d.ts.map +1 -0
- package/lib/shellUtils.js +21 -0
- package/lib/shellUtils.js.map +1 -0
- package/lib/slugger.d.ts +24 -0
- package/lib/slugger.d.ts.map +1 -0
- package/lib/slugger.js +23 -0
- package/lib/slugger.js.map +1 -0
- package/lib/tags.d.ts +59 -0
- package/lib/tags.d.ts.map +1 -0
- package/lib/tags.js +91 -0
- package/lib/tags.js.map +1 -0
- package/lib/urlUtils.d.ts +66 -0
- package/lib/urlUtils.d.ts.map +1 -0
- package/lib/urlUtils.js +207 -0
- package/lib/urlUtils.js.map +1 -0
- package/lib/webpackUtils.d.ts +35 -0
- package/lib/webpackUtils.d.ts.map +1 -0
- package/lib/webpackUtils.js +115 -0
- package/lib/webpackUtils.js.map +1 -0
- package/package.json +28 -10
- package/src/constants.ts +98 -0
- package/src/dataFileUtils.ts +122 -0
- package/src/deps.d.ts +10 -0
- package/src/emitUtils.ts +99 -0
- package/src/gitUtils.ts +146 -0
- package/src/globUtils.ts +85 -0
- package/src/hashUtils.ts +9 -8
- package/src/i18nUtils.ts +114 -0
- package/src/index.ts +97 -502
- package/src/jsUtils.ts +59 -0
- package/src/markdownLinks.ts +101 -30
- package/src/markdownUtils.ts +357 -0
- package/src/pathUtils.ts +93 -12
- package/src/shellUtils.ts +18 -0
- package/src/slugger.ts +36 -0
- package/src/tags.ts +130 -0
- package/src/urlUtils.ts +234 -0
- package/src/webpackUtils.ts +153 -0
- package/lib/.tsbuildinfo +0 -1
- package/lib/codeTranslationsUtils.d.ts +0 -11
- package/lib/codeTranslationsUtils.js +0 -50
- package/lib/escapePath.d.ts +0 -17
- package/lib/escapePath.js +0 -25
- package/lib/markdownParser.d.ts +0 -30
- package/lib/markdownParser.js +0 -140
- package/lib/posixPath.d.ts +0 -14
- package/lib/posixPath.js +0 -28
- package/src/__tests__/__fixtures__/defaultCodeTranslations/en.json +0 -4
- package/src/__tests__/__fixtures__/defaultCodeTranslations/fr-FR.json +0 -5
- package/src/__tests__/__fixtures__/defaultCodeTranslations/fr.json +0 -4
- package/src/__tests__/__snapshots__/index.test.ts.snap +0 -8
- package/src/__tests__/codeTranslationsUtils.test.ts +0 -112
- package/src/__tests__/escapePath.test.ts +0 -25
- package/src/__tests__/hashUtils.test.ts +0 -51
- package/src/__tests__/index.test.ts +0 -631
- package/src/__tests__/markdownParser.test.ts +0 -817
- package/src/__tests__/pathUtils.test.ts +0 -63
- package/src/__tests__/posixPath.test.ts +0 -25
- package/src/codeTranslationsUtils.ts +0 -56
- package/src/escapePath.ts +0 -23
- package/src/markdownParser.ts +0 -182
- package/src/posixPath.ts +0 -27
- package/tsconfig.json +0 -9
package/lib/index.js
CHANGED
|
@@ -6,398 +6,94 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.parseMarkdownHeadingId = exports.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
exports
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Object.defineProperty(exports, "
|
|
30
|
-
Object.defineProperty(exports, "
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
exports.
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
exports.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
exports.
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
exports.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
function
|
|
99
|
-
|
|
100
|
-
return 'index';
|
|
101
|
-
}
|
|
102
|
-
const pageHash = hashUtils_1.docuHash(pagePath);
|
|
103
|
-
return upperFirst(lodash_1.camelCase(pageHash));
|
|
104
|
-
}
|
|
105
|
-
exports.genComponentName = genComponentName;
|
|
106
|
-
// When you want to display a path in a message/warning/error,
|
|
107
|
-
// it's more convenient to:
|
|
108
|
-
// - make it relative to cwd()
|
|
109
|
-
// - convert to posix (ie not using windows \ path separator)
|
|
110
|
-
// This way, Jest tests can run more reliably on any computer/CI
|
|
111
|
-
// on both Unix/Windows
|
|
112
|
-
// For Windows users this is not perfect (as they see / instead of \) but it's probably good enough
|
|
113
|
-
function toMessageRelativeFilePath(filePath) {
|
|
114
|
-
return exports.posixPath(path_1.default.relative(process.cwd(), filePath));
|
|
115
|
-
}
|
|
116
|
-
exports.toMessageRelativeFilePath = toMessageRelativeFilePath;
|
|
117
|
-
const chunkNameCache = new Map();
|
|
118
|
-
/**
|
|
119
|
-
* Generate unique chunk name given a module path.
|
|
120
|
-
*/
|
|
121
|
-
function genChunkName(modulePath, prefix, preferredName, shortId = process.env.NODE_ENV === 'production') {
|
|
122
|
-
let chunkName = chunkNameCache.get(modulePath);
|
|
123
|
-
if (!chunkName) {
|
|
124
|
-
if (shortId) {
|
|
125
|
-
chunkName = hashUtils_1.simpleHash(modulePath, 8);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
let str = modulePath;
|
|
129
|
-
if (preferredName) {
|
|
130
|
-
const shortHash = hashUtils_1.simpleHash(modulePath, 3);
|
|
131
|
-
str = `${preferredName}${shortHash}`;
|
|
132
|
-
}
|
|
133
|
-
const name = str === '/' ? 'index' : hashUtils_1.docuHash(str);
|
|
134
|
-
chunkName = prefix ? `${prefix}---${name}` : name;
|
|
135
|
-
}
|
|
136
|
-
chunkNameCache.set(modulePath, chunkName);
|
|
137
|
-
}
|
|
138
|
-
return chunkName;
|
|
139
|
-
}
|
|
140
|
-
exports.genChunkName = genChunkName;
|
|
141
|
-
// Too dynamic
|
|
142
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
143
|
-
function idx(target, keyPaths) {
|
|
144
|
-
return (target &&
|
|
145
|
-
keyPaths &&
|
|
146
|
-
(Array.isArray(keyPaths)
|
|
147
|
-
? keyPaths.reduce((obj, key) => obj && obj[key], target)
|
|
148
|
-
: target[keyPaths]));
|
|
149
|
-
}
|
|
150
|
-
exports.idx = idx;
|
|
151
|
-
/**
|
|
152
|
-
* Given a filepath and dirpath, get the first directory.
|
|
153
|
-
*/
|
|
154
|
-
function getSubFolder(file, refDir) {
|
|
155
|
-
const separator = escape_string_regexp_1.default(path_1.default.sep);
|
|
156
|
-
const baseDir = escape_string_regexp_1.default(path_1.default.basename(refDir));
|
|
157
|
-
const regexSubFolder = new RegExp(`${baseDir}${separator}(.*?)${separator}.*`);
|
|
158
|
-
const match = regexSubFolder.exec(file);
|
|
159
|
-
return match && match[1];
|
|
160
|
-
}
|
|
161
|
-
exports.getSubFolder = getSubFolder;
|
|
162
|
-
function normalizeUrl(rawUrls) {
|
|
163
|
-
const urls = [...rawUrls];
|
|
164
|
-
const resultArray = [];
|
|
165
|
-
let hasStartingSlash = false;
|
|
166
|
-
let hasEndingSlash = false;
|
|
167
|
-
// If the first part is a plain protocol, we combine it with the next part.
|
|
168
|
-
if (urls[0].match(/^[^/:]+:\/*$/) && urls.length > 1) {
|
|
169
|
-
const first = urls.shift();
|
|
170
|
-
urls[0] = first + urls[0];
|
|
171
|
-
}
|
|
172
|
-
// There must be two or three slashes in the file protocol,
|
|
173
|
-
// two slashes in anything else.
|
|
174
|
-
const replacement = urls[0].match(/^file:\/\/\//) ? '$1:///' : '$1://';
|
|
175
|
-
urls[0] = urls[0].replace(/^([^/:]+):\/*/, replacement);
|
|
176
|
-
// eslint-disable-next-line
|
|
177
|
-
for (let i = 0; i < urls.length; i++) {
|
|
178
|
-
let component = urls[i];
|
|
179
|
-
if (typeof component !== 'string') {
|
|
180
|
-
throw new TypeError(`Url must be a string. Received ${typeof component}`);
|
|
181
|
-
}
|
|
182
|
-
if (component === '') {
|
|
183
|
-
if (i === urls.length - 1 && hasEndingSlash) {
|
|
184
|
-
resultArray.push('/');
|
|
185
|
-
}
|
|
186
|
-
// eslint-disable-next-line
|
|
187
|
-
continue;
|
|
188
|
-
}
|
|
189
|
-
if (component !== '/') {
|
|
190
|
-
if (i > 0) {
|
|
191
|
-
// Removing the starting slashes for each component but the first.
|
|
192
|
-
component = component.replace(/^[/]+/,
|
|
193
|
-
// Special case where the first element of rawUrls is empty ["", "/hello"] => /hello
|
|
194
|
-
component[0] === '/' && !hasStartingSlash ? '/' : '');
|
|
195
|
-
}
|
|
196
|
-
hasEndingSlash = component[component.length - 1] === '/';
|
|
197
|
-
// Removing the ending slashes for each component but the last.
|
|
198
|
-
// For the last component we will combine multiple slashes to a single one.
|
|
199
|
-
component = component.replace(/[/]+$/, i < urls.length - 1 ? '' : '/');
|
|
200
|
-
}
|
|
201
|
-
hasStartingSlash = true;
|
|
202
|
-
resultArray.push(component);
|
|
203
|
-
}
|
|
204
|
-
let str = resultArray.join('/');
|
|
205
|
-
// Each input component is now separated by a single slash
|
|
206
|
-
// except the possible first plain protocol part.
|
|
207
|
-
// Remove trailing slash before parameters or hash.
|
|
208
|
-
str = str.replace(/\/(\?|&|#[^!])/g, '$1');
|
|
209
|
-
// Replace ? in parameters with &.
|
|
210
|
-
const parts = str.split('?');
|
|
211
|
-
str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
|
|
212
|
-
// Dedupe forward slashes in the entire path, avoiding protocol slashes.
|
|
213
|
-
str = str.replace(/([^:]\/)\/+/g, '$1');
|
|
214
|
-
// Dedupe forward slashes at the beginning of the path.
|
|
215
|
-
str = str.replace(/^\/+/g, '/');
|
|
216
|
-
return str;
|
|
217
|
-
}
|
|
218
|
-
exports.normalizeUrl = normalizeUrl;
|
|
219
|
-
/**
|
|
220
|
-
* Alias filepath relative to site directory, very useful so that we
|
|
221
|
-
* don't expose user's site structure.
|
|
222
|
-
* Example: some/path/to/website/docs/foo.md -> @site/docs/foo.md
|
|
223
|
-
*/
|
|
224
|
-
function aliasedSitePath(filePath, siteDir) {
|
|
225
|
-
const relativePath = exports.posixPath(path_1.default.relative(siteDir, filePath));
|
|
226
|
-
// Cannot use path.join() as it resolves '../' and removes
|
|
227
|
-
// the '@site'. Let webpack loader resolve it.
|
|
228
|
-
return `@site/${relativePath}`;
|
|
229
|
-
}
|
|
230
|
-
exports.aliasedSitePath = aliasedSitePath;
|
|
231
|
-
function getEditUrl(fileRelativePath, editUrl) {
|
|
232
|
-
return editUrl
|
|
233
|
-
? normalizeUrl([editUrl, exports.posixPath(fileRelativePath)])
|
|
234
|
-
: undefined;
|
|
235
|
-
}
|
|
236
|
-
exports.getEditUrl = getEditUrl;
|
|
237
|
-
function isValidPathname(str) {
|
|
238
|
-
if (!str.startsWith('/')) {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
try {
|
|
242
|
-
// weird, but is there a better way?
|
|
243
|
-
const parsedPathname = new url_1.URL(str, 'https://domain.com').pathname;
|
|
244
|
-
return parsedPathname === str || parsedPathname === encodeURI(str);
|
|
245
|
-
}
|
|
246
|
-
catch (e) {
|
|
247
|
-
return false;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
exports.isValidPathname = isValidPathname;
|
|
251
|
-
// resolve pathname and fail fast if resolution fails
|
|
252
|
-
function resolvePathname(to, from) {
|
|
253
|
-
return resolve_pathname_1.default(to, from);
|
|
254
|
-
}
|
|
255
|
-
exports.resolvePathname = resolvePathname;
|
|
256
|
-
function addLeadingSlash(str) {
|
|
257
|
-
return str.startsWith('/') ? str : `/${str}`;
|
|
258
|
-
}
|
|
259
|
-
exports.addLeadingSlash = addLeadingSlash;
|
|
260
|
-
function addTrailingPathSeparator(str) {
|
|
261
|
-
return str.endsWith(path_1.default.sep) ? str : `${str}${path_1.default.sep}`;
|
|
262
|
-
}
|
|
263
|
-
exports.addTrailingPathSeparator = addTrailingPathSeparator;
|
|
264
|
-
// TODO deduplicate: also present in @docusaurus/utils-common
|
|
265
|
-
function addTrailingSlash(str) {
|
|
266
|
-
return str.endsWith('/') ? str : `${str}/`;
|
|
267
|
-
}
|
|
268
|
-
exports.addTrailingSlash = addTrailingSlash;
|
|
269
|
-
function removeTrailingSlash(str) {
|
|
270
|
-
return removeSuffix(str, '/');
|
|
271
|
-
}
|
|
272
|
-
exports.removeTrailingSlash = removeTrailingSlash;
|
|
273
|
-
function removeSuffix(str, suffix) {
|
|
274
|
-
if (suffix === '') {
|
|
275
|
-
return str; // always returns "" otherwise!
|
|
276
|
-
}
|
|
277
|
-
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
|
|
278
|
-
}
|
|
279
|
-
exports.removeSuffix = removeSuffix;
|
|
280
|
-
function removePrefix(str, prefix) {
|
|
281
|
-
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
|
|
282
|
-
}
|
|
283
|
-
exports.removePrefix = removePrefix;
|
|
284
|
-
function getElementsAround(array, aroundIndex) {
|
|
285
|
-
const min = 0;
|
|
286
|
-
const max = array.length - 1;
|
|
287
|
-
if (aroundIndex < min || aroundIndex > max) {
|
|
288
|
-
throw new Error(`Valid "aroundIndex" for array (of size ${array.length}) are between ${min} and ${max}, but you provided ${aroundIndex}.`);
|
|
289
|
-
}
|
|
290
|
-
const previous = aroundIndex === min ? undefined : array[aroundIndex - 1];
|
|
291
|
-
const next = aroundIndex === max ? undefined : array[aroundIndex + 1];
|
|
292
|
-
return { previous, next };
|
|
293
|
-
}
|
|
294
|
-
exports.getElementsAround = getElementsAround;
|
|
295
|
-
function getPluginI18nPath({ siteDir, locale, pluginName, pluginId = 'default', // TODO duplicated constant
|
|
296
|
-
subPaths = [], }) {
|
|
297
|
-
return path_1.default.join(siteDir, 'i18n',
|
|
298
|
-
// namespace first by locale: convenient to work in a single folder for a translator
|
|
299
|
-
locale,
|
|
300
|
-
// Make it convenient to use for single-instance
|
|
301
|
-
// ie: return "docs", not "docs-default" nor "docs/default"
|
|
302
|
-
`${pluginName}${
|
|
303
|
-
// TODO duplicate constant :(
|
|
304
|
-
pluginId === 'default' ? '' : `-${pluginId}`}`, ...subPaths);
|
|
305
|
-
}
|
|
306
|
-
exports.getPluginI18nPath = getPluginI18nPath;
|
|
307
|
-
async function mapAsyncSequencial(array, action) {
|
|
308
|
-
const results = [];
|
|
309
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
310
|
-
for (const t of array) {
|
|
311
|
-
// eslint-disable-next-line no-await-in-loop
|
|
312
|
-
const result = await action(t);
|
|
313
|
-
results.push(result);
|
|
314
|
-
}
|
|
315
|
-
return results;
|
|
316
|
-
}
|
|
317
|
-
exports.mapAsyncSequencial = mapAsyncSequencial;
|
|
318
|
-
async function findAsyncSequential(array, predicate) {
|
|
319
|
-
// eslint-disable-next-line no-restricted-syntax
|
|
320
|
-
for (const t of array) {
|
|
321
|
-
// eslint-disable-next-line no-await-in-loop
|
|
322
|
-
if (await predicate(t)) {
|
|
323
|
-
return t;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return undefined;
|
|
327
|
-
}
|
|
328
|
-
exports.findAsyncSequential = findAsyncSequential;
|
|
329
|
-
// return the first folder path in which the file exists in
|
|
330
|
-
async function findFolderContainingFile(folderPaths, relativeFilePath) {
|
|
331
|
-
return findAsyncSequential(folderPaths, (folderPath) => fs_extra_1.default.pathExists(path_1.default.join(folderPath, relativeFilePath)));
|
|
332
|
-
}
|
|
333
|
-
exports.findFolderContainingFile = findFolderContainingFile;
|
|
334
|
-
async function getFolderContainingFile(folderPaths, relativeFilePath) {
|
|
335
|
-
const maybeFolderPath = await findFolderContainingFile(folderPaths, relativeFilePath);
|
|
336
|
-
// should never happen, as the source was read from the FS anyway...
|
|
337
|
-
if (!maybeFolderPath) {
|
|
338
|
-
throw new Error(`File "${relativeFilePath}" does not exist in any of these folders:\n- ${folderPaths.join('\n- ')}]`);
|
|
339
|
-
}
|
|
340
|
-
return maybeFolderPath;
|
|
341
|
-
}
|
|
342
|
-
exports.getFolderContainingFile = getFolderContainingFile;
|
|
343
|
-
function reportMessage(message, reportingSeverity) {
|
|
344
|
-
switch (reportingSeverity) {
|
|
345
|
-
case 'ignore':
|
|
346
|
-
break;
|
|
347
|
-
case 'log':
|
|
348
|
-
console.log(chalk_1.default.bold.blue('info ') + chalk_1.default.blue(message));
|
|
349
|
-
break;
|
|
350
|
-
case 'warn':
|
|
351
|
-
console.warn(chalk_1.default.bold.yellow('warn ') + chalk_1.default.yellow(message));
|
|
352
|
-
break;
|
|
353
|
-
case 'error':
|
|
354
|
-
console.error(chalk_1.default.bold.red('error ') + chalk_1.default.red(message));
|
|
355
|
-
break;
|
|
356
|
-
case 'throw':
|
|
357
|
-
throw new Error(message);
|
|
358
|
-
default:
|
|
359
|
-
throw new Error(`Unexpected "reportingSeverity" value: ${reportingSeverity}.`);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
exports.reportMessage = reportMessage;
|
|
363
|
-
function mergeTranslations(contents) {
|
|
364
|
-
return contents.reduce((acc, content) => {
|
|
365
|
-
return { ...acc, ...content };
|
|
366
|
-
}, {});
|
|
367
|
-
}
|
|
368
|
-
exports.mergeTranslations = mergeTranslations;
|
|
369
|
-
function getSwizzledComponent(componentPath) {
|
|
370
|
-
const swizzledComponentPath = path_1.default.resolve(process.cwd(), 'src', componentPath);
|
|
371
|
-
return fs_extra_1.default.existsSync(swizzledComponentPath)
|
|
372
|
-
? swizzledComponentPath
|
|
373
|
-
: undefined;
|
|
374
|
-
}
|
|
375
|
-
exports.getSwizzledComponent = getSwizzledComponent;
|
|
376
|
-
// Useful to update all the messages of a translation file
|
|
377
|
-
// Used in tests to simulate translations
|
|
378
|
-
function updateTranslationFileMessages(translationFile, updateMessage) {
|
|
379
|
-
return {
|
|
380
|
-
...translationFile,
|
|
381
|
-
content: lodash_1.mapValues(translationFile.content, (translation) => ({
|
|
382
|
-
...translation,
|
|
383
|
-
message: updateMessage(translation.message),
|
|
384
|
-
})),
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
exports.updateTranslationFileMessages = updateTranslationFileMessages;
|
|
388
|
-
// Input: ## Some heading {#some-heading}
|
|
389
|
-
// Output: {text: "## Some heading", id: "some-heading"}
|
|
390
|
-
function parseMarkdownHeadingId(heading) {
|
|
391
|
-
const customHeadingIdRegex = /^(.*?)\s*\{#([\w-]+)\}$/;
|
|
392
|
-
const matches = customHeadingIdRegex.exec(heading);
|
|
393
|
-
if (matches) {
|
|
394
|
-
return {
|
|
395
|
-
text: matches[1],
|
|
396
|
-
id: matches[2],
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
return { text: heading, id: undefined };
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
exports.parseMarkdownHeadingId = parseMarkdownHeadingId;
|
|
9
|
+
exports.replaceMarkdownLinks = exports.writeMarkdownHeadingId = exports.parseMarkdownString = exports.parseMarkdownContentTitle = exports.parseFrontMatter = exports.createExcerpt = exports.parseMarkdownHeadingId = exports.groupTaggedItems = exports.normalizeFrontMatterTags = exports.buildSshUrl = exports.buildHttpsUrl = exports.hasSSHProtocol = exports.removeTrailingSlash = exports.addTrailingSlash = exports.addLeadingSlash = exports.resolvePathname = exports.isValidPathname = exports.encodePath = exports.fileToPath = exports.getEditUrl = exports.normalizeUrl = exports.findAsyncSequential = exports.mapAsyncSequential = exports.removePrefix = exports.removeSuffix = exports.localizePath = exports.getPluginI18nPath = exports.updateTranslationFileMessages = exports.mergeTranslations = exports.GitNotFoundError = exports.FileNotTrackedError = exports.getFileCommitDate = exports.readOutputHTMLFile = exports.generate = exports.WEBPACK_URL_LOADER_LIMIT = exports.DEFAULT_PLUGIN_ID = exports.DEFAULT_PORT = exports.CODE_TRANSLATIONS_FILE_NAME = exports.DEFAULT_I18N_DIR_NAME = exports.THEME_PATH = exports.OUTPUT_STATIC_ASSETS_DIR_NAME = exports.DEFAULT_STATIC_DIR_NAME = exports.SRC_DIR_NAME = exports.GENERATED_FILES_DIR_NAME = exports.BABEL_CONFIG_FILE_NAME = exports.DEFAULT_CONFIG_FILE_NAME = exports.DEFAULT_BUILD_DIR_NAME = exports.DOCUSAURUS_VERSION = exports.NODE_MINOR_VERSION = exports.NODE_MAJOR_VERSION = void 0;
|
|
10
|
+
exports.getFolderContainingFile = exports.findFolderContainingFile = exports.getContentPathList = exports.getDataFileData = exports.getDataFilePath = exports.escapeShellArg = exports.getFileLoaderUtils = exports.createAbsoluteFilePathMatcher = exports.createMatcher = exports.GlobExcludeDefault = exports.Globby = exports.docuHash = exports.simpleHash = exports.md5Hash = exports.addTrailingPathSeparator = exports.escapePath = exports.aliasedSitePath = exports.toMessageRelativeFilePath = exports.posixPath = exports.shortName = exports.isNameTooLong = exports.createSlugger = void 0;
|
|
11
|
+
var constants_1 = require("./constants");
|
|
12
|
+
Object.defineProperty(exports, "NODE_MAJOR_VERSION", { enumerable: true, get: function () { return constants_1.NODE_MAJOR_VERSION; } });
|
|
13
|
+
Object.defineProperty(exports, "NODE_MINOR_VERSION", { enumerable: true, get: function () { return constants_1.NODE_MINOR_VERSION; } });
|
|
14
|
+
Object.defineProperty(exports, "DOCUSAURUS_VERSION", { enumerable: true, get: function () { return constants_1.DOCUSAURUS_VERSION; } });
|
|
15
|
+
Object.defineProperty(exports, "DEFAULT_BUILD_DIR_NAME", { enumerable: true, get: function () { return constants_1.DEFAULT_BUILD_DIR_NAME; } });
|
|
16
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG_FILE_NAME", { enumerable: true, get: function () { return constants_1.DEFAULT_CONFIG_FILE_NAME; } });
|
|
17
|
+
Object.defineProperty(exports, "BABEL_CONFIG_FILE_NAME", { enumerable: true, get: function () { return constants_1.BABEL_CONFIG_FILE_NAME; } });
|
|
18
|
+
Object.defineProperty(exports, "GENERATED_FILES_DIR_NAME", { enumerable: true, get: function () { return constants_1.GENERATED_FILES_DIR_NAME; } });
|
|
19
|
+
Object.defineProperty(exports, "SRC_DIR_NAME", { enumerable: true, get: function () { return constants_1.SRC_DIR_NAME; } });
|
|
20
|
+
Object.defineProperty(exports, "DEFAULT_STATIC_DIR_NAME", { enumerable: true, get: function () { return constants_1.DEFAULT_STATIC_DIR_NAME; } });
|
|
21
|
+
Object.defineProperty(exports, "OUTPUT_STATIC_ASSETS_DIR_NAME", { enumerable: true, get: function () { return constants_1.OUTPUT_STATIC_ASSETS_DIR_NAME; } });
|
|
22
|
+
Object.defineProperty(exports, "THEME_PATH", { enumerable: true, get: function () { return constants_1.THEME_PATH; } });
|
|
23
|
+
Object.defineProperty(exports, "DEFAULT_I18N_DIR_NAME", { enumerable: true, get: function () { return constants_1.DEFAULT_I18N_DIR_NAME; } });
|
|
24
|
+
Object.defineProperty(exports, "CODE_TRANSLATIONS_FILE_NAME", { enumerable: true, get: function () { return constants_1.CODE_TRANSLATIONS_FILE_NAME; } });
|
|
25
|
+
Object.defineProperty(exports, "DEFAULT_PORT", { enumerable: true, get: function () { return constants_1.DEFAULT_PORT; } });
|
|
26
|
+
Object.defineProperty(exports, "DEFAULT_PLUGIN_ID", { enumerable: true, get: function () { return constants_1.DEFAULT_PLUGIN_ID; } });
|
|
27
|
+
Object.defineProperty(exports, "WEBPACK_URL_LOADER_LIMIT", { enumerable: true, get: function () { return constants_1.WEBPACK_URL_LOADER_LIMIT; } });
|
|
28
|
+
var emitUtils_1 = require("./emitUtils");
|
|
29
|
+
Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return emitUtils_1.generate; } });
|
|
30
|
+
Object.defineProperty(exports, "readOutputHTMLFile", { enumerable: true, get: function () { return emitUtils_1.readOutputHTMLFile; } });
|
|
31
|
+
var gitUtils_1 = require("./gitUtils");
|
|
32
|
+
Object.defineProperty(exports, "getFileCommitDate", { enumerable: true, get: function () { return gitUtils_1.getFileCommitDate; } });
|
|
33
|
+
Object.defineProperty(exports, "FileNotTrackedError", { enumerable: true, get: function () { return gitUtils_1.FileNotTrackedError; } });
|
|
34
|
+
Object.defineProperty(exports, "GitNotFoundError", { enumerable: true, get: function () { return gitUtils_1.GitNotFoundError; } });
|
|
35
|
+
var i18nUtils_1 = require("./i18nUtils");
|
|
36
|
+
Object.defineProperty(exports, "mergeTranslations", { enumerable: true, get: function () { return i18nUtils_1.mergeTranslations; } });
|
|
37
|
+
Object.defineProperty(exports, "updateTranslationFileMessages", { enumerable: true, get: function () { return i18nUtils_1.updateTranslationFileMessages; } });
|
|
38
|
+
Object.defineProperty(exports, "getPluginI18nPath", { enumerable: true, get: function () { return i18nUtils_1.getPluginI18nPath; } });
|
|
39
|
+
Object.defineProperty(exports, "localizePath", { enumerable: true, get: function () { return i18nUtils_1.localizePath; } });
|
|
40
|
+
var jsUtils_1 = require("./jsUtils");
|
|
41
|
+
Object.defineProperty(exports, "removeSuffix", { enumerable: true, get: function () { return jsUtils_1.removeSuffix; } });
|
|
42
|
+
Object.defineProperty(exports, "removePrefix", { enumerable: true, get: function () { return jsUtils_1.removePrefix; } });
|
|
43
|
+
Object.defineProperty(exports, "mapAsyncSequential", { enumerable: true, get: function () { return jsUtils_1.mapAsyncSequential; } });
|
|
44
|
+
Object.defineProperty(exports, "findAsyncSequential", { enumerable: true, get: function () { return jsUtils_1.findAsyncSequential; } });
|
|
45
|
+
var urlUtils_1 = require("./urlUtils");
|
|
46
|
+
Object.defineProperty(exports, "normalizeUrl", { enumerable: true, get: function () { return urlUtils_1.normalizeUrl; } });
|
|
47
|
+
Object.defineProperty(exports, "getEditUrl", { enumerable: true, get: function () { return urlUtils_1.getEditUrl; } });
|
|
48
|
+
Object.defineProperty(exports, "fileToPath", { enumerable: true, get: function () { return urlUtils_1.fileToPath; } });
|
|
49
|
+
Object.defineProperty(exports, "encodePath", { enumerable: true, get: function () { return urlUtils_1.encodePath; } });
|
|
50
|
+
Object.defineProperty(exports, "isValidPathname", { enumerable: true, get: function () { return urlUtils_1.isValidPathname; } });
|
|
51
|
+
Object.defineProperty(exports, "resolvePathname", { enumerable: true, get: function () { return urlUtils_1.resolvePathname; } });
|
|
52
|
+
Object.defineProperty(exports, "addLeadingSlash", { enumerable: true, get: function () { return urlUtils_1.addLeadingSlash; } });
|
|
53
|
+
Object.defineProperty(exports, "addTrailingSlash", { enumerable: true, get: function () { return urlUtils_1.addTrailingSlash; } });
|
|
54
|
+
Object.defineProperty(exports, "removeTrailingSlash", { enumerable: true, get: function () { return urlUtils_1.removeTrailingSlash; } });
|
|
55
|
+
Object.defineProperty(exports, "hasSSHProtocol", { enumerable: true, get: function () { return urlUtils_1.hasSSHProtocol; } });
|
|
56
|
+
Object.defineProperty(exports, "buildHttpsUrl", { enumerable: true, get: function () { return urlUtils_1.buildHttpsUrl; } });
|
|
57
|
+
Object.defineProperty(exports, "buildSshUrl", { enumerable: true, get: function () { return urlUtils_1.buildSshUrl; } });
|
|
58
|
+
var tags_1 = require("./tags");
|
|
59
|
+
Object.defineProperty(exports, "normalizeFrontMatterTags", { enumerable: true, get: function () { return tags_1.normalizeFrontMatterTags; } });
|
|
60
|
+
Object.defineProperty(exports, "groupTaggedItems", { enumerable: true, get: function () { return tags_1.groupTaggedItems; } });
|
|
61
|
+
var markdownUtils_1 = require("./markdownUtils");
|
|
62
|
+
Object.defineProperty(exports, "parseMarkdownHeadingId", { enumerable: true, get: function () { return markdownUtils_1.parseMarkdownHeadingId; } });
|
|
63
|
+
Object.defineProperty(exports, "createExcerpt", { enumerable: true, get: function () { return markdownUtils_1.createExcerpt; } });
|
|
64
|
+
Object.defineProperty(exports, "parseFrontMatter", { enumerable: true, get: function () { return markdownUtils_1.parseFrontMatter; } });
|
|
65
|
+
Object.defineProperty(exports, "parseMarkdownContentTitle", { enumerable: true, get: function () { return markdownUtils_1.parseMarkdownContentTitle; } });
|
|
66
|
+
Object.defineProperty(exports, "parseMarkdownString", { enumerable: true, get: function () { return markdownUtils_1.parseMarkdownString; } });
|
|
67
|
+
Object.defineProperty(exports, "writeMarkdownHeadingId", { enumerable: true, get: function () { return markdownUtils_1.writeMarkdownHeadingId; } });
|
|
68
|
+
var markdownLinks_1 = require("./markdownLinks");
|
|
69
|
+
Object.defineProperty(exports, "replaceMarkdownLinks", { enumerable: true, get: function () { return markdownLinks_1.replaceMarkdownLinks; } });
|
|
70
|
+
var slugger_1 = require("./slugger");
|
|
71
|
+
Object.defineProperty(exports, "createSlugger", { enumerable: true, get: function () { return slugger_1.createSlugger; } });
|
|
72
|
+
var pathUtils_1 = require("./pathUtils");
|
|
73
|
+
Object.defineProperty(exports, "isNameTooLong", { enumerable: true, get: function () { return pathUtils_1.isNameTooLong; } });
|
|
74
|
+
Object.defineProperty(exports, "shortName", { enumerable: true, get: function () { return pathUtils_1.shortName; } });
|
|
75
|
+
Object.defineProperty(exports, "posixPath", { enumerable: true, get: function () { return pathUtils_1.posixPath; } });
|
|
76
|
+
Object.defineProperty(exports, "toMessageRelativeFilePath", { enumerable: true, get: function () { return pathUtils_1.toMessageRelativeFilePath; } });
|
|
77
|
+
Object.defineProperty(exports, "aliasedSitePath", { enumerable: true, get: function () { return pathUtils_1.aliasedSitePath; } });
|
|
78
|
+
Object.defineProperty(exports, "escapePath", { enumerable: true, get: function () { return pathUtils_1.escapePath; } });
|
|
79
|
+
Object.defineProperty(exports, "addTrailingPathSeparator", { enumerable: true, get: function () { return pathUtils_1.addTrailingPathSeparator; } });
|
|
80
|
+
var hashUtils_1 = require("./hashUtils");
|
|
81
|
+
Object.defineProperty(exports, "md5Hash", { enumerable: true, get: function () { return hashUtils_1.md5Hash; } });
|
|
82
|
+
Object.defineProperty(exports, "simpleHash", { enumerable: true, get: function () { return hashUtils_1.simpleHash; } });
|
|
83
|
+
Object.defineProperty(exports, "docuHash", { enumerable: true, get: function () { return hashUtils_1.docuHash; } });
|
|
84
|
+
var globUtils_1 = require("./globUtils");
|
|
85
|
+
Object.defineProperty(exports, "Globby", { enumerable: true, get: function () { return globUtils_1.Globby; } });
|
|
86
|
+
Object.defineProperty(exports, "GlobExcludeDefault", { enumerable: true, get: function () { return globUtils_1.GlobExcludeDefault; } });
|
|
87
|
+
Object.defineProperty(exports, "createMatcher", { enumerable: true, get: function () { return globUtils_1.createMatcher; } });
|
|
88
|
+
Object.defineProperty(exports, "createAbsoluteFilePathMatcher", { enumerable: true, get: function () { return globUtils_1.createAbsoluteFilePathMatcher; } });
|
|
89
|
+
var webpackUtils_1 = require("./webpackUtils");
|
|
90
|
+
Object.defineProperty(exports, "getFileLoaderUtils", { enumerable: true, get: function () { return webpackUtils_1.getFileLoaderUtils; } });
|
|
91
|
+
var shellUtils_1 = require("./shellUtils");
|
|
92
|
+
Object.defineProperty(exports, "escapeShellArg", { enumerable: true, get: function () { return shellUtils_1.escapeShellArg; } });
|
|
93
|
+
var dataFileUtils_1 = require("./dataFileUtils");
|
|
94
|
+
Object.defineProperty(exports, "getDataFilePath", { enumerable: true, get: function () { return dataFileUtils_1.getDataFilePath; } });
|
|
95
|
+
Object.defineProperty(exports, "getDataFileData", { enumerable: true, get: function () { return dataFileUtils_1.getDataFileData; } });
|
|
96
|
+
Object.defineProperty(exports, "getContentPathList", { enumerable: true, get: function () { return dataFileUtils_1.getContentPathList; } });
|
|
97
|
+
Object.defineProperty(exports, "findFolderContainingFile", { enumerable: true, get: function () { return dataFileUtils_1.findFolderContainingFile; } });
|
|
98
|
+
Object.defineProperty(exports, "getFolderContainingFile", { enumerable: true, get: function () { return dataFileUtils_1.getFolderContainingFile; } });
|
|
99
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,yCAiBqB;AAhBnB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,+GAAA,kBAAkB,OAAA;AAClB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,mHAAA,sBAAsB,OAAA;AACtB,qHAAA,wBAAwB,OAAA;AACxB,yGAAA,YAAY,OAAA;AACZ,oHAAA,uBAAuB,OAAA;AACvB,0HAAA,6BAA6B,OAAA;AAC7B,uGAAA,UAAU,OAAA;AACV,kHAAA,qBAAqB,OAAA;AACrB,wHAAA,2BAA2B,OAAA;AAC3B,yGAAA,YAAY,OAAA;AACZ,8GAAA,iBAAiB,OAAA;AACjB,qHAAA,wBAAwB,OAAA;AAE1B,yCAAyD;AAAjD,qGAAA,QAAQ,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AACpC,uCAIoB;AAHlB,6GAAA,iBAAiB,OAAA;AACjB,+GAAA,mBAAmB,OAAA;AACnB,4GAAA,gBAAgB,OAAA;AAElB,yCAKqB;AAJnB,8GAAA,iBAAiB,OAAA;AACjB,0HAAA,6BAA6B,OAAA;AAC7B,8GAAA,iBAAiB,OAAA;AACjB,yGAAA,YAAY,OAAA;AAEd,qCAKmB;AAJjB,uGAAA,YAAY,OAAA;AACZ,uGAAA,YAAY,OAAA;AACZ,6GAAA,kBAAkB,OAAA;AAClB,8GAAA,mBAAmB,OAAA;AAErB,uCAaoB;AAZlB,wGAAA,YAAY,OAAA;AACZ,sGAAA,UAAU,OAAA;AACV,sGAAA,UAAU,OAAA;AACV,sGAAA,UAAU,OAAA;AACV,2GAAA,eAAe,OAAA;AACf,2GAAA,eAAe,OAAA;AACf,2GAAA,eAAe,OAAA;AACf,4GAAA,gBAAgB,OAAA;AAChB,+GAAA,mBAAmB,OAAA;AACnB,0GAAA,cAAc,OAAA;AACd,yGAAA,aAAa,OAAA;AACb,uGAAA,WAAW,OAAA;AAEb,+BAOgB;AAFd,gHAAA,wBAAwB,OAAA;AACxB,wGAAA,gBAAgB,OAAA;AAElB,iDAQyB;AAPvB,uHAAA,sBAAsB,OAAA;AACtB,8GAAA,aAAa,OAAA;AACb,iHAAA,gBAAgB,OAAA;AAChB,0HAAA,yBAAyB,OAAA;AACzB,oHAAA,mBAAmB,OAAA;AACnB,uHAAA,sBAAsB,OAAA;AAGxB,iDAIyB;AADvB,qHAAA,oBAAoB,OAAA;AAEtB,qCAA2E;AAAhC,wGAAA,aAAa,OAAA;AACxD,yCAQqB;AAPnB,0GAAA,aAAa,OAAA;AACb,sGAAA,SAAS,OAAA;AACT,sGAAA,SAAS,OAAA;AACT,sHAAA,yBAAyB,OAAA;AACzB,4GAAA,eAAe,OAAA;AACf,uGAAA,UAAU,OAAA;AACV,qHAAA,wBAAwB,OAAA;AAE1B,yCAA0D;AAAlD,oGAAA,OAAO,OAAA;AAAE,uGAAA,UAAU,OAAA;AAAE,qGAAA,QAAQ,OAAA;AACrC,yCAKqB;AAJnB,mGAAA,MAAM,OAAA;AACN,+GAAA,kBAAkB,OAAA;AAClB,0GAAA,aAAa,OAAA;AACb,0HAAA,6BAA6B,OAAA;AAE/B,+CAAkD;AAA1C,kHAAA,kBAAkB,OAAA;AAC1B,2CAA4C;AAApC,4GAAA,cAAc,OAAA;AACtB,iDAMyB;AALvB,gHAAA,eAAe,OAAA;AACf,gHAAA,eAAe,OAAA;AACf,mHAAA,kBAAkB,OAAA;AAClB,yHAAA,wBAAwB,OAAA;AACxB,wHAAA,uBAAuB,OAAA"}
|
package/lib/jsUtils.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/** Removes a given string suffix from `str`. */
|
|
8
|
+
export declare function removeSuffix(str: string, suffix: string): string;
|
|
9
|
+
/** Removes a given string prefix from `str`. */
|
|
10
|
+
export declare function removePrefix(str: string, prefix: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* `Array#map` for async operations where order matters.
|
|
13
|
+
* @param array The array to traverse.
|
|
14
|
+
* @param action An async action to be performed on every array item. Will be
|
|
15
|
+
* awaited before working on the next.
|
|
16
|
+
* @returns The list of results returned from every `action(item)`
|
|
17
|
+
*/
|
|
18
|
+
export declare function mapAsyncSequential<T, R>(array: T[], action: (t: T) => Promise<R>): Promise<R[]>;
|
|
19
|
+
/**
|
|
20
|
+
* `Array#find` for async operations where order matters.
|
|
21
|
+
* @param array The array to traverse.
|
|
22
|
+
* @param predicate An async predicate to be called on every array item. Should
|
|
23
|
+
* return a boolean indicating whether the currently element should be returned.
|
|
24
|
+
* @returns The function immediately returns the first item on which `predicate`
|
|
25
|
+
* returns `true`, or `undefined` if none matches the predicate.
|
|
26
|
+
*/
|
|
27
|
+
export declare function findAsyncSequential<T>(array: T[], predicate: (t: T) => Promise<boolean>): Promise<T | undefined>;
|
|
28
|
+
//# sourceMappingURL=jsUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsUtils.d.ts","sourceRoot":"","sources":["../src/jsUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAMhE;AAED,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EAAE,CAAC,EAC3C,KAAK,EAAE,CAAC,EAAE,EACV,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC3B,OAAO,CAAC,CAAC,EAAE,CAAC,CAOd;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CAAC,CAAC,EACzC,KAAK,EAAE,CAAC,EAAE,EACV,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,GACpC,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAOxB"}
|
package/lib/jsUtils.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.findAsyncSequential = exports.mapAsyncSequential = exports.removePrefix = exports.removeSuffix = void 0;
|
|
10
|
+
/** Removes a given string suffix from `str`. */
|
|
11
|
+
function removeSuffix(str, suffix) {
|
|
12
|
+
if (suffix === '') {
|
|
13
|
+
// str.slice(0, 0) is ""
|
|
14
|
+
return str;
|
|
15
|
+
}
|
|
16
|
+
return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
|
|
17
|
+
}
|
|
18
|
+
exports.removeSuffix = removeSuffix;
|
|
19
|
+
/** Removes a given string prefix from `str`. */
|
|
20
|
+
function removePrefix(str, prefix) {
|
|
21
|
+
return str.startsWith(prefix) ? str.slice(prefix.length) : str;
|
|
22
|
+
}
|
|
23
|
+
exports.removePrefix = removePrefix;
|
|
24
|
+
/**
|
|
25
|
+
* `Array#map` for async operations where order matters.
|
|
26
|
+
* @param array The array to traverse.
|
|
27
|
+
* @param action An async action to be performed on every array item. Will be
|
|
28
|
+
* awaited before working on the next.
|
|
29
|
+
* @returns The list of results returned from every `action(item)`
|
|
30
|
+
*/
|
|
31
|
+
async function mapAsyncSequential(array, action) {
|
|
32
|
+
const results = [];
|
|
33
|
+
for (const t of array) {
|
|
34
|
+
const result = await action(t);
|
|
35
|
+
results.push(result);
|
|
36
|
+
}
|
|
37
|
+
return results;
|
|
38
|
+
}
|
|
39
|
+
exports.mapAsyncSequential = mapAsyncSequential;
|
|
40
|
+
/**
|
|
41
|
+
* `Array#find` for async operations where order matters.
|
|
42
|
+
* @param array The array to traverse.
|
|
43
|
+
* @param predicate An async predicate to be called on every array item. Should
|
|
44
|
+
* return a boolean indicating whether the currently element should be returned.
|
|
45
|
+
* @returns The function immediately returns the first item on which `predicate`
|
|
46
|
+
* returns `true`, or `undefined` if none matches the predicate.
|
|
47
|
+
*/
|
|
48
|
+
async function findAsyncSequential(array, predicate) {
|
|
49
|
+
for (const t of array) {
|
|
50
|
+
if (await predicate(t)) {
|
|
51
|
+
return t;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
exports.findAsyncSequential = findAsyncSequential;
|
|
57
|
+
//# sourceMappingURL=jsUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsUtils.js","sourceRoot":"","sources":["../src/jsUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,gDAAgD;AAChD,SAAgB,YAAY,CAAC,GAAW,EAAE,MAAc;IACtD,IAAI,MAAM,KAAK,EAAE,EAAE;QACjB,wBAAwB;QACxB,OAAO,GAAG,CAAC;KACZ;IACD,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACnE,CAAC;AAND,oCAMC;AAED,gDAAgD;AAChD,SAAgB,YAAY,CAAC,GAAW,EAAE,MAAc;IACtD,OAAO,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACjE,CAAC;AAFD,oCAEC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,kBAAkB,CACtC,KAAU,EACV,MAA4B;IAE5B,MAAM,OAAO,GAAQ,EAAE,CAAC;IACxB,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;QACrB,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,CAAC,CAAC,CAAC;QAC/B,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;KACtB;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAVD,gDAUC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,mBAAmB,CACvC,KAAU,EACV,SAAqC;IAErC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE;QACrB,IAAI,MAAM,SAAS,CAAC,CAAC,CAAC,EAAE;YACtB,OAAO,CAAC,CAAC;SACV;KACF;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAVD,kDAUC"}
|