mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
refactor(v2): replace Lodash with single methods packages in utils (#2536)
This commit is contained in:
parent
ff5029893e
commit
5d65facc81
3 changed files with 23 additions and 13 deletions
|
@ -34,7 +34,7 @@
|
|||
"@types/inquirer": "^6.5.0",
|
||||
"@types/jest": "^24.0.23",
|
||||
"@types/loader-utils": "^1.1.3",
|
||||
"@types/lodash": "^4.14.149",
|
||||
"@types/lodash.camelcase": "^4.3.6",
|
||||
"@types/lodash.flatmap": "^4.5.6",
|
||||
"@types/lodash.groupby": "^4.6.6",
|
||||
"@types/lodash.has": "^4.5.6",
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
"escape-string-regexp": "^2.0.0",
|
||||
"fs-extra": "^8.1.0",
|
||||
"gray-matter": "^4.0.2",
|
||||
"lodash": "^4.17.15"
|
||||
"lodash.camelcase": "^4.3.0",
|
||||
"lodash.kebabcase": "^4.1.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.9.0"
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
import path from 'path';
|
||||
import matter from 'gray-matter';
|
||||
import {createHash} from 'crypto';
|
||||
import _ from 'lodash';
|
||||
import camelCase from 'lodash.camelcase';
|
||||
import kebabCase from 'lodash.kebabcase';
|
||||
import escapeStringRegexp from 'escape-string-regexp';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
|
@ -51,13 +52,14 @@ export async function generate(
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}, {});
|
||||
}
|
||||
|
||||
const indexRE = /(^|.*\/)index\.(md|js|jsx|ts|tsx)$/i;
|
||||
|
@ -93,7 +95,15 @@ export function docuHash(str: string): string {
|
|||
.update(str)
|
||||
.digest('hex')
|
||||
.substr(0, 3);
|
||||
return `${_.kebabCase(str)}-${shortHash}`;
|
||||
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) : '';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,8 +115,7 @@ export function genComponentName(pagePath: string): string {
|
|||
return 'index';
|
||||
}
|
||||
const pageHash = docuHash(pagePath);
|
||||
const pascalCase = _.flow(_.camelCase, _.upperFirst);
|
||||
return pascalCase(pageHash);
|
||||
return upperFirst(camelCase(pageHash));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue