migrate from underscore to lodash

This commit is contained in:
Jeff Williams 2019-01-21 10:52:46 -08:00
parent 8d7a70c3f6
commit 3b8b0b479b
11 changed files with 20 additions and 31 deletions

2
cli.js
View File

@ -47,7 +47,7 @@ module.exports = (() => {
// TODO: docs // TODO: docs
cli.loadConfig = () => { cli.loadConfig = () => {
const _ = require('underscore'); const _ = require('lodash');
const args = require('jsdoc/opts/args'); const args = require('jsdoc/opts/args');
const Config = require('jsdoc/config'); const Config = require('jsdoc/config');
let config; let config;

View File

@ -1,7 +1,7 @@
/** /**
* @module jsdoc/doclet * @module jsdoc/doclet
*/ */
const _ = require('underscore'); const _ = require('lodash');
const jsdoc = { const jsdoc = {
env: require('jsdoc/env'), env: require('jsdoc/env'),
name: require('jsdoc/name'), name: require('jsdoc/name'),

View File

@ -2,7 +2,7 @@
* A collection of functions relating to JSDoc symbol name manipulation. * A collection of functions relating to JSDoc symbol name manipulation.
* @module jsdoc/name * @module jsdoc/name
*/ */
const _ = require('underscore'); const _ = require('lodash');
const escape = require('escape-string-regexp'); const escape = require('escape-string-regexp');
const hasOwnProp = Object.prototype.hasOwnProperty; const hasOwnProp = Object.prototype.hasOwnProperty;

View File

@ -2,21 +2,16 @@
* Parse the command line arguments. * Parse the command line arguments.
* @module jsdoc/opts/argparser * @module jsdoc/opts/argparser
*/ */
const _ = require('underscore'); const _ = require('lodash');
const util = require('util');
const hasOwnProp = Object.prototype.hasOwnProperty; const hasOwnProp = Object.prototype.hasOwnProperty;
function padding(length) {
return new Array(length + 1).join(' ');
}
function padLeft(str, length) { function padLeft(str, length) {
return padding(length) + str; return str.padStart(str.length + length);
} }
function padRight(str, length) { function padRight(str, length) {
return str + padding(length); return str.padEnd(str.length + length);
} }
function findMaxLength(arr) { function findMaxLength(arr) {
@ -37,7 +32,7 @@ function concatWithMaxLength(items, maxLength) {
// to prevent endless loops, always use the first item, regardless of length // to prevent endless loops, always use the first item, regardless of length
result += items.shift(); result += items.shift();
while ( items.length && (result.length + items[0].length < maxLength) ) { while (items.length && (result.length + items[0].length < maxLength)) {
result += ` ${items.shift()}`; result += ` ${items.shift()}`;
} }
@ -72,7 +67,7 @@ function formatHelpInfo({names, descriptions}) {
result += concatWithMaxLength(words, wrapDescriptionAt); result += concatWithMaxLength(words, wrapDescriptionAt);
// if there's anything left, keep going until we've consumed the description // if there's anything left, keep going until we've consumed the description
while (words.length) { while (words.length) {
partialDescription = padding( maxNameLength + (MARGIN_LENGTH * 2) ); partialDescription = padLeft('', maxNameLength + (MARGIN_LENGTH * 2));
partialDescription += concatWithMaxLength(words, wrapDescriptionAt); partialDescription += concatWithMaxLength(words, wrapDescriptionAt);
result += `\n${partialDescription}`; result += `\n${partialDescription}`;
} }
@ -226,7 +221,7 @@ class ArgParser {
let arg; let arg;
let next; let next;
let option; let option;
const result = ( defaults && _.defaults({}, defaults) ) || {}; const result = (defaults && _.defaults({}, defaults)) || {};
let shortName; let shortName;
let longName; let longName;
let name; let name;
@ -252,7 +247,7 @@ class ArgParser {
} }
if (option === null) { if (option === null) {
throw new Error( util.format('Unknown command-line option "%s".', name) ); throw new Error(`Unknown command-line option "${name}".`);
} }
if (option.hasValue) { if (option.hasValue) {
@ -260,7 +255,7 @@ class ArgParser {
i++; i++;
if (value === null || value.charAt(0) === '-') { if (value === null || value.charAt(0) === '-') {
throw new Error( util.format('The command-line option "%s" requires a value.', name) ); throw new Error(`The command-line option "${name}" requires a value.`);
} }
} }
else { else {

View File

@ -2,7 +2,7 @@
* Define tags that are known in JSDoc. * Define tags that are known in JSDoc.
* @module jsdoc/tag/dictionary/definitions * @module jsdoc/tag/dictionary/definitions
*/ */
const _ = require('underscore'); const _ = require('lodash');
const jsdoc = { const jsdoc = {
env: require('jsdoc/env'), env: require('jsdoc/env'),
name: require('jsdoc/name'), name: require('jsdoc/name'),

View File

@ -2,7 +2,7 @@
* Wrapper for underscore's template utility to allow loading templates from files. * Wrapper for underscore's template utility to allow loading templates from files.
* @module jsdoc/template * @module jsdoc/template
*/ */
const _ = require('underscore'); const _ = require('lodash');
const fs = require('jsdoc/fs'); const fs = require('jsdoc/fs');
const path = require('path'); const path = require('path');

8
package-lock.json generated
View File

@ -5864,8 +5864,7 @@
"lodash": { "lodash": {
"version": "4.17.11", "version": "4.17.11",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
"dev": true
}, },
"lodash._reinterpolate": { "lodash._reinterpolate": {
"version": "3.0.0", "version": "3.0.0",
@ -9858,11 +9857,6 @@
"integrity": "sha1-5z3T17DXxe2G+6xrCufYxqadUPo=", "integrity": "sha1-5z3T17DXxe2G+6xrCufYxqadUPo=",
"dev": true "dev": true
}, },
"underscore": {
"version": "1.9.1",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.9.1.tgz",
"integrity": "sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg=="
},
"underscore-contrib": { "underscore-contrib": {
"version": "0.3.0", "version": "0.3.0",
"resolved": "https://registry.npmjs.org/underscore-contrib/-/underscore-contrib-0.3.0.tgz", "resolved": "https://registry.npmjs.org/underscore-contrib/-/underscore-contrib-0.3.0.tgz",

View File

@ -1,7 +1,7 @@
{ {
"name": "jsdoc", "name": "jsdoc",
"version": "4.0.0-dev", "version": "4.0.0-dev",
"revision": "1547932905034", "revision": "1548096695580",
"description": "An API documentation generator for JavaScript.", "description": "An API documentation generator for JavaScript.",
"keywords": [ "keywords": [
"documentation", "documentation",
@ -21,14 +21,14 @@
"escape-string-regexp": "~1.0.5", "escape-string-regexp": "~1.0.5",
"js2xmlparser": "~3.0.0", "js2xmlparser": "~3.0.0",
"klaw": "~3.0.0", "klaw": "~3.0.0",
"lodash": "^4.17.11",
"markdown-it": "~8.4.2", "markdown-it": "~8.4.2",
"markdown-it-anchor": "~5.0.2", "markdown-it-anchor": "~5.0.2",
"marked": "~0.6.0", "marked": "~0.6.0",
"mkdirp": "~0.5.1", "mkdirp": "~0.5.1",
"requizzle": "~0.2.1", "requizzle": "~0.2.1",
"strip-json-comments": "~2.0.1", "strip-json-comments": "~2.0.1",
"taffydb": "2.6.2", "taffydb": "2.6.2"
"underscore": "~1.9.1"
}, },
"devDependencies": { "devDependencies": {
"ajv": "~6.7.0", "ajv": "~6.7.0",

View File

@ -3,7 +3,7 @@
* *
* @module plugins/eventDumper * @module plugins/eventDumper
*/ */
const _ = require('underscore'); const _ = require('lodash');
const doop = require('jsdoc/util/doop'); const doop = require('jsdoc/util/doop');
const dump = require('jsdoc/util/dumper').dump; const dump = require('jsdoc/util/dumper').dump;
const env = require('jsdoc/env'); const env = require('jsdoc/env');

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
var _ = require('underscore'); var _ = require('lodash');
/** /**
* Socket class. * Socket class.

View File

@ -1,6 +1,6 @@
describe('jsdoc/doclet', () => { describe('jsdoc/doclet', () => {
// TODO: more tests // TODO: more tests
const _ = require('underscore'); const _ = require('lodash');
const jsdoc = { const jsdoc = {
doclet: require('jsdoc/doclet') doclet: require('jsdoc/doclet')
}; };