@docusaurus/utils
Advanced tools
Comparing version 2.0.0-alpha.13 to 2.0.0-alpha.14
{ | ||
"name": "@docusaurus/utils", | ||
"version": "2.0.0-alpha.13", | ||
"version": "2.0.0-alpha.14", | ||
"description": "Node utility functions for Docusaurus packages", | ||
@@ -12,7 +12,7 @@ "main": "src/index.js", | ||
"escape-string-regexp": "^1.0.5", | ||
"front-matter": "^3.0.1", | ||
"fs-extra": "^7.0.0", | ||
"gray-matter": "^4.0.2", | ||
"lodash": "^4.17.11" | ||
}, | ||
"gitHead": "76d210f1f1d7169710e08a8734f6e01465b6eec6" | ||
"gitHead": "8055d59131af9805448a915d3c9c5974546fe850" | ||
} |
@@ -116,3 +116,3 @@ /** | ||
const b = {hello: 'world'}; | ||
const env = { | ||
const obj = { | ||
translation: { | ||
@@ -143,9 +143,9 @@ enabled: true, | ||
expect(idx(b, 'hello')).toEqual('world'); | ||
expect(idx(env, 'typo')).toBeUndefined(); | ||
expect(idx(env, 'versioning')).toEqual({ | ||
expect(idx(obj, 'typo')).toBeUndefined(); | ||
expect(idx(obj, 'versioning')).toEqual({ | ||
enabled: false, | ||
versions: [], | ||
}); | ||
expect(idx(env, ['translation', 'enabled'])).toEqual(true); | ||
expect(idx(env, ['translation', variable]).map(lang => lang.tag)).toEqual([ | ||
expect(idx(obj, ['translation', 'enabled'])).toEqual(true); | ||
expect(idx(obj, ['translation', variable]).map(lang => lang.tag)).toEqual([ | ||
'en', | ||
@@ -152,0 +152,0 @@ 'ja', |
@@ -9,3 +9,3 @@ /** | ||
const path = require('path'); | ||
const fm = require('front-matter'); | ||
const matter = require('gray-matter'); | ||
const {createHash} = require('crypto'); | ||
@@ -18,2 +18,8 @@ | ||
const fileHash = new Map(); | ||
/** | ||
* @param {string} generatedFilesDir | ||
* @param {string} file | ||
* @param {*} content | ||
* @returns {Promise<void>} | ||
*/ | ||
async function generate(generatedFilesDir, file, content) { | ||
@@ -36,2 +42,6 @@ const filepath = path.join(generatedFilesDir, file); | ||
/** | ||
* @param {string} file | ||
* @returns {string} | ||
*/ | ||
function fileToPath(file) { | ||
@@ -44,2 +54,6 @@ if (indexRE.test(file)) { | ||
/** | ||
* @param {string} userpath | ||
* @returns {string} | ||
*/ | ||
function encodePath(userpath) { | ||
@@ -101,2 +115,9 @@ return userpath | ||
const chunkNameCache = new Map(); | ||
/** | ||
* Generate unique chunk name given a module path | ||
* @param {string} modulePath | ||
* @param {string=} prefix | ||
* @param {string=} preferredName | ||
* @returns {string} | ||
*/ | ||
function genChunkName(modulePath, prefix, preferredName) { | ||
@@ -119,3 +140,7 @@ let chunkName = chunkNameCache.get(modulePath); | ||
} | ||
/** | ||
* @param {*} target | ||
* @param {string|string[]} keyPaths | ||
* @returns {*} | ||
*/ | ||
function idx(target, keyPaths) { | ||
@@ -130,2 +155,7 @@ return ( | ||
/** | ||
* @param {string} file | ||
* @param {string} refDir | ||
* @returns {string} | ||
*/ | ||
function getSubFolder(file, refDir) { | ||
@@ -141,11 +171,23 @@ const separator = escapeStringRegexp(path.sep); | ||
/** | ||
* @param {string} fileString | ||
* @returns {Object} | ||
*/ | ||
function parse(fileString) { | ||
if (!fm.test(fileString)) { | ||
return {metadata: null, content: fileString}; | ||
} | ||
const {attributes: metadata, body: content} = fm(fileString); | ||
return {metadata, content}; | ||
const {data: frontMatter, content, excerpt} = matter(fileString, { | ||
excerpt(file) { | ||
// eslint-disable-next-line no-param-reassign | ||
file.excerpt = file.content | ||
.trim() | ||
.split('\n', 1) | ||
.shift(); | ||
}, | ||
}); | ||
return {frontMatter, content, excerpt}; | ||
} | ||
/** | ||
* @param {string[]} rawUrls | ||
* @returns {string} | ||
*/ | ||
function normalizeUrl(rawUrls) { | ||
@@ -152,0 +194,0 @@ const urls = rawUrls; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13900
432
+ Addedgray-matter@^4.0.2
+ Addedextend-shallow@2.0.1(transitive)
+ Addedgray-matter@4.0.3(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedkind-of@6.0.3(transitive)
+ Addedsection-matter@1.0.0(transitive)
+ Addedstrip-bom-string@1.0.0(transitive)
- Removedfront-matter@^3.0.1
- Removedfront-matter@3.2.1(transitive)