Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@docusaurus/utils

Package Overview
Dependencies
Maintainers
3
Versions
1839
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@docusaurus/utils - npm Package Compare versions

Comparing version 2.0.0-alpha.13 to 2.0.0-alpha.14

6

package.json
{
"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;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc