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

@docusaurus/utils

Package Overview
Dependencies
Maintainers
4
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.50 to 2.0.0-alpha.51

lib/index.js.map

11

lib/index.d.ts

@@ -7,5 +7,6 @@ /**

*/
import _ from 'lodash';
export declare function generate(generatedFilesDir: string, file: string, content: any, skipCache?: boolean): Promise<void>;
export declare function objectWithKeySorted(obj: Object): _.Dictionary<any>;
export declare function objectWithKeySorted(obj: {
[index: string]: any;
}): any;
/**

@@ -23,2 +24,7 @@ * Convert filepath to url path.

/**
* Convert first string character to the upper case.
* E.g: docusaurus -> Docusaurus
*/
export declare function upperFirst(str: string): string;
/**
* Generate unique React Component Name.

@@ -56,2 +62,3 @@ * E.g: /foo-bar -> FooBar096

export declare function aliasedSitePath(filePath: string, siteDir: string): string;
export declare function getEditUrl(fileRelativePath: string, editUrl?: string): string | undefined;
//# sourceMappingURL=index.d.ts.map

66

lib/index.js

@@ -15,3 +15,4 @@ "use strict";

const crypto_1 = require("crypto");
const lodash_1 = __importDefault(require("lodash"));
const lodash_camelcase_1 = __importDefault(require("lodash.camelcase"));
const lodash_kebabcase_1 = __importDefault(require("lodash.kebabcase"));
const escape_string_regexp_1 = __importDefault(require("escape-string-regexp"));

@@ -33,10 +34,6 @@ const fs_extra_1 = __importDefault(require("fs-extra"));

const lastContent = await fs_extra_1.default.readFile(filepath, 'utf8');
lastHash = crypto_1.createHash('md5')
.update(lastContent)
.digest('hex');
lastHash = crypto_1.createHash('md5').update(lastContent).digest('hex');
fileHash.set(filepath, lastHash);
}
const currentHash = crypto_1.createHash('md5')
.update(content)
.digest('hex');
const currentHash = crypto_1.createHash('md5').update(content).digest('hex');
if (lastHash !== currentHash) {

@@ -50,8 +47,9 @@ await fs_extra_1.default.ensureDir(path_1.default.dirname(filepath));

function objectWithKeySorted(obj) {
// https://github.com/lodash/lodash/issues/1459#issuecomment-253969771
return lodash_1.default(obj)
.toPairs()
.sortBy(0)
.fromPairs()
.value();
// https://github.com/lodash/lodash/issues/1459#issuecomment-460941233
return Object.keys(obj)
.sort()
.reduce((acc, key) => {
acc[key] = obj[key];
return acc;
}, {});
}

@@ -75,3 +73,3 @@ exports.objectWithKeySorted = objectWithKeySorted;

.split('/')
.map(item => encodeURIComponent(item))
.map((item) => encodeURIComponent(item))
.join('/');

@@ -88,10 +86,15 @@ }

}
const shortHash = crypto_1.createHash('md5')
.update(str)
.digest('hex')
.substr(0, 3);
return `${lodash_1.default.kebabCase(str)}-${shortHash}`;
const shortHash = crypto_1.createHash('md5').update(str).digest('hex').substr(0, 3);
return `${lodash_kebabcase_1.default(str)}-${shortHash}`;
}
exports.docuHash = docuHash;
/**
* Convert first string character to the upper case.
* E.g: docusaurus -> Docusaurus
*/
function upperFirst(str) {
return str ? str.charAt(0).toUpperCase() + str.slice(1) : '';
}
exports.upperFirst = upperFirst;
/**
* Generate unique React Component Name.

@@ -105,4 +108,3 @@ * E.g: /foo-bar -> FooBar096

const pageHash = docuHash(pagePath);
const pascalCase = lodash_1.default.flow(lodash_1.default.camelCase, lodash_1.default.upperFirst);
return pascalCase(pageHash);
return upperFirst(lodash_camelcase_1.default(pageHash));
}

@@ -172,9 +174,17 @@ exports.genComponentName = genComponentName;

exports.getSubFolder = getSubFolder;
// Regex for an import statement.
const importRegexString = '^(.*import){1}(.+){0,1}\\s[\'"](.+)[\'"];';
function parse(fileString) {
const options = {
excerpt: (file) => {
file.excerpt = file.content
.trim()
.split('\n', 1)
.shift();
let fileContent = file.content.trimLeft();
// Hacky way of stripping out import statements from the excerpt
// TODO: Find a better way to do so, possibly by compiling the Markdown content,
// stripping out HTML tags and obtaining the first line.
if (RegExp(importRegexString).test(fileContent)) {
fileContent = fileContent
.replace(RegExp(importRegexString, 'gm'), '')
.trimLeft();
}
file.excerpt = fileContent.split('\n', 1).shift();
},

@@ -244,1 +254,7 @@ };

exports.aliasedSitePath = aliasedSitePath;
function getEditUrl(fileRelativePath, editUrl) {
return editUrl
? normalizeUrl([editUrl, posixPath(fileRelativePath)])
: undefined;
}
exports.getEditUrl = getEditUrl;
{
"name": "@docusaurus/utils",
"version": "2.0.0-alpha.50",
"version": "2.0.0-alpha.51",
"description": "Node utility functions for Docusaurus packages",

@@ -18,3 +18,4 @@ "main": "./lib/index.js",

"gray-matter": "^4.0.2",
"lodash": "^4.17.15"
"lodash.camelcase": "^4.3.0",
"lodash.kebabcase": "^4.1.1"
},

@@ -24,3 +25,3 @@ "engines": {

},
"gitHead": "c207c3ba31b16eb91ac3c6dbe7a295e698c9413c"
"gitHead": "c9c5aedcb59e56b2e404bb010bd0ec3055d6c4c6"
}

@@ -30,3 +30,3 @@ /**

};
Object.keys(asserts).forEach(file => {
Object.keys(asserts).forEach((file) => {
expect(aliasedSitePath(file, 'user/website')).toBe(asserts[file]);

@@ -46,3 +46,3 @@ });

};
Object.keys(asserts).forEach(file => {
Object.keys(asserts).forEach((file) => {
expect(posixPath(file)).toBe(asserts[file]);

@@ -64,3 +64,3 @@ });

};
Object.keys(asserts).forEach(file => {
Object.keys(asserts).forEach((file) => {
expect(genComponentName(file)).toBe(asserts[file]);

@@ -81,3 +81,3 @@ });

};
Object.keys(asserts).forEach(file => {
Object.keys(asserts).forEach((file) => {
expect(docuHash(file)).toBe(asserts[file]);

@@ -98,3 +98,3 @@ });

};
Object.keys(asserts).forEach(file => {
Object.keys(asserts).forEach((file) => {
expect(fileToPath(file)).toBe(asserts[file]);

@@ -150,3 +150,3 @@ });

};
Object.keys(firstAssert).forEach(str => {
Object.keys(firstAssert).forEach((str) => {
expect(genChunkName(str)).toBe(firstAssert[str]);

@@ -165,3 +165,3 @@ });

};
Object.keys(secondAssert).forEach(str => {
Object.keys(secondAssert).forEach((str) => {
expect(genChunkName(str, undefined, 'blog')).toBe(secondAssert[str]);

@@ -177,3 +177,3 @@ });

};
Object.keys(thirdAssert).forEach(str => {
Object.keys(thirdAssert).forEach((str) => {
expect(genChunkName(str, undefined, undefined, true)).toBe(

@@ -221,6 +221,5 @@ thirdAssert[str],

expect(idx(obj, ['translation', 'enabled'])).toEqual(true);
expect(idx(obj, ['translation', variable]).map(lang => lang.tag)).toEqual([
'en',
'ja',
]);
expect(
idx(obj, ['translation', variable]).map((lang) => lang.tag),
).toEqual(['en', 'ja']);
expect(idx(test, ['arr', 0])).toEqual(1);

@@ -295,3 +294,3 @@ expect(idx(undefined)).toBeUndefined();

];
asserts.forEach(testCase => {
asserts.forEach((testCase) => {
expect(normalizeUrl(testCase.input)).toBe(testCase.output);

@@ -298,0 +297,0 @@ });

@@ -11,3 +11,4 @@ /**

import {createHash} from 'crypto';
import _ from 'lodash';
import camelCase from 'lodash.camelcase';
import kebabCase from 'lodash.kebabcase';
import escapeStringRegexp from 'escape-string-regexp';

@@ -38,11 +39,7 @@ import fs from 'fs-extra';

const lastContent = await fs.readFile(filepath, 'utf8');
lastHash = createHash('md5')
.update(lastContent)
.digest('hex');
lastHash = createHash('md5').update(lastContent).digest('hex');
fileHash.set(filepath, lastHash);
}
const currentHash = createHash('md5')
.update(content)
.digest('hex');
const currentHash = createHash('md5').update(content).digest('hex');

@@ -56,9 +53,10 @@ if (lastHash !== currentHash) {

export function objectWithKeySorted(obj: Object) {
// https://github.com/lodash/lodash/issues/1459#issuecomment-253969771
return _(obj)
.toPairs()
.sortBy(0)
.fromPairs()
.value();
export function objectWithKeySorted(obj: {[index: string]: any}) {
// https://github.com/lodash/lodash/issues/1459#issuecomment-460941233
return Object.keys(obj)
.sort()
.reduce((acc: any, key: string) => {
acc[key] = obj[key];
return acc;
}, {});
}

@@ -83,3 +81,3 @@

.split('/')
.map(item => encodeURIComponent(item))
.map((item) => encodeURIComponent(item))
.join('/');

@@ -96,10 +94,15 @@ }

}
const shortHash = createHash('md5')
.update(str)
.digest('hex')
.substr(0, 3);
return `${_.kebabCase(str)}-${shortHash}`;
const shortHash = createHash('md5').update(str).digest('hex').substr(0, 3);
return `${kebabCase(str)}-${shortHash}`;
}
/**
* Convert first string character to the upper case.
* E.g: docusaurus -> Docusaurus
*/
export function upperFirst(str: string): string {
return str ? str.charAt(0).toUpperCase() + str.slice(1) : '';
}
/**
* Generate unique React Component Name.

@@ -113,4 +116,3 @@ * E.g: /foo-bar -> FooBar096

const pageHash = docuHash(pagePath);
const pascalCase = _.flow(_.camelCase, _.upperFirst);
return pascalCase(pageHash);
return upperFirst(camelCase(pageHash));
}

@@ -189,2 +191,5 @@

// Regex for an import statement.
const importRegexString = '^(.*import){1}(.+){0,1}\\s[\'"](.+)[\'"];';
export function parse(

@@ -201,6 +206,14 @@ fileString: string,

excerpt: (file: matter.GrayMatterFile<string>): void => {
file.excerpt = file.content
.trim()
.split('\n', 1)
.shift();
let fileContent = file.content.trimLeft();
// Hacky way of stripping out import statements from the excerpt
// TODO: Find a better way to do so, possibly by compiling the Markdown content,
// stripping out HTML tags and obtaining the first line.
if (RegExp(importRegexString).test(fileContent)) {
fileContent = fileContent
.replace(RegExp(importRegexString, 'gm'), '')
.trimLeft();
}
file.excerpt = fileContent.split('\n', 1).shift();
},

@@ -284,1 +297,7 @@ };

}
export function getEditUrl(fileRelativePath: string, editUrl?: string) {
return editUrl
? normalizeUrl([editUrl, posixPath(fileRelativePath)])
: undefined;
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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