From 3b8b0b479b8f00bc726f4050439f452601b823fc Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Mon, 21 Jan 2019 10:52:46 -0800 Subject: [PATCH] migrate from `underscore` to `lodash` --- cli.js | 2 +- lib/jsdoc/doclet.js | 2 +- lib/jsdoc/name.js | 2 +- lib/jsdoc/opts/argparser.js | 21 ++++++++------------- lib/jsdoc/tag/dictionary/definitions.js | 2 +- lib/jsdoc/template.js | 2 +- package-lock.json | 8 +------- package.json | 6 +++--- plugins/eventDumper.js | 2 +- test/fixtures/eventorder.js | 2 +- test/specs/jsdoc/doclet.js | 2 +- 11 files changed, 20 insertions(+), 31 deletions(-) diff --git a/cli.js b/cli.js index 7a5a3a47..fe0e6a0d 100644 --- a/cli.js +++ b/cli.js @@ -47,7 +47,7 @@ module.exports = (() => { // TODO: docs cli.loadConfig = () => { - const _ = require('underscore'); + const _ = require('lodash'); const args = require('jsdoc/opts/args'); const Config = require('jsdoc/config'); let config; diff --git a/lib/jsdoc/doclet.js b/lib/jsdoc/doclet.js index d6bda934..ade45b86 100644 --- a/lib/jsdoc/doclet.js +++ b/lib/jsdoc/doclet.js @@ -1,7 +1,7 @@ /** * @module jsdoc/doclet */ -const _ = require('underscore'); +const _ = require('lodash'); const jsdoc = { env: require('jsdoc/env'), name: require('jsdoc/name'), diff --git a/lib/jsdoc/name.js b/lib/jsdoc/name.js index 8b8dcb55..87a8ac64 100644 --- a/lib/jsdoc/name.js +++ b/lib/jsdoc/name.js @@ -2,7 +2,7 @@ * A collection of functions relating to JSDoc symbol name manipulation. * @module jsdoc/name */ -const _ = require('underscore'); +const _ = require('lodash'); const escape = require('escape-string-regexp'); const hasOwnProp = Object.prototype.hasOwnProperty; diff --git a/lib/jsdoc/opts/argparser.js b/lib/jsdoc/opts/argparser.js index 3bab52f3..a48eca8f 100644 --- a/lib/jsdoc/opts/argparser.js +++ b/lib/jsdoc/opts/argparser.js @@ -2,21 +2,16 @@ * Parse the command line arguments. * @module jsdoc/opts/argparser */ -const _ = require('underscore'); -const util = require('util'); +const _ = require('lodash'); const hasOwnProp = Object.prototype.hasOwnProperty; -function padding(length) { - return new Array(length + 1).join(' '); -} - function padLeft(str, length) { - return padding(length) + str; + return str.padStart(str.length + length); } function padRight(str, length) { - return str + padding(length); + return str.padEnd(str.length + length); } function findMaxLength(arr) { @@ -37,7 +32,7 @@ function concatWithMaxLength(items, maxLength) { // to prevent endless loops, always use the first item, regardless of length result += items.shift(); - while ( items.length && (result.length + items[0].length < maxLength) ) { + while (items.length && (result.length + items[0].length < maxLength)) { result += ` ${items.shift()}`; } @@ -72,7 +67,7 @@ function formatHelpInfo({names, descriptions}) { result += concatWithMaxLength(words, wrapDescriptionAt); // if there's anything left, keep going until we've consumed the description while (words.length) { - partialDescription = padding( maxNameLength + (MARGIN_LENGTH * 2) ); + partialDescription = padLeft('', maxNameLength + (MARGIN_LENGTH * 2)); partialDescription += concatWithMaxLength(words, wrapDescriptionAt); result += `\n${partialDescription}`; } @@ -226,7 +221,7 @@ class ArgParser { let arg; let next; let option; - const result = ( defaults && _.defaults({}, defaults) ) || {}; + const result = (defaults && _.defaults({}, defaults)) || {}; let shortName; let longName; let name; @@ -252,7 +247,7 @@ class ArgParser { } 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) { @@ -260,7 +255,7 @@ class ArgParser { i++; 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 { diff --git a/lib/jsdoc/tag/dictionary/definitions.js b/lib/jsdoc/tag/dictionary/definitions.js index fac16afb..6a72fc41 100644 --- a/lib/jsdoc/tag/dictionary/definitions.js +++ b/lib/jsdoc/tag/dictionary/definitions.js @@ -2,7 +2,7 @@ * Define tags that are known in JSDoc. * @module jsdoc/tag/dictionary/definitions */ -const _ = require('underscore'); +const _ = require('lodash'); const jsdoc = { env: require('jsdoc/env'), name: require('jsdoc/name'), diff --git a/lib/jsdoc/template.js b/lib/jsdoc/template.js index c01cb852..00ebaa49 100644 --- a/lib/jsdoc/template.js +++ b/lib/jsdoc/template.js @@ -2,7 +2,7 @@ * Wrapper for underscore's template utility to allow loading templates from files. * @module jsdoc/template */ -const _ = require('underscore'); +const _ = require('lodash'); const fs = require('jsdoc/fs'); const path = require('path'); diff --git a/package-lock.json b/package-lock.json index ab93072c..76495fed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5864,8 +5864,7 @@ "lodash": { "version": "4.17.11", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", - "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==", - "dev": true + "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" }, "lodash._reinterpolate": { "version": "3.0.0", @@ -9858,11 +9857,6 @@ "integrity": "sha1-5z3T17DXxe2G+6xrCufYxqadUPo=", "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": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/underscore-contrib/-/underscore-contrib-0.3.0.tgz", diff --git a/package.json b/package.json index 9f6104c4..c61f6db9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jsdoc", "version": "4.0.0-dev", - "revision": "1547932905034", + "revision": "1548096695580", "description": "An API documentation generator for JavaScript.", "keywords": [ "documentation", @@ -21,14 +21,14 @@ "escape-string-regexp": "~1.0.5", "js2xmlparser": "~3.0.0", "klaw": "~3.0.0", + "lodash": "^4.17.11", "markdown-it": "~8.4.2", "markdown-it-anchor": "~5.0.2", "marked": "~0.6.0", "mkdirp": "~0.5.1", "requizzle": "~0.2.1", "strip-json-comments": "~2.0.1", - "taffydb": "2.6.2", - "underscore": "~1.9.1" + "taffydb": "2.6.2" }, "devDependencies": { "ajv": "~6.7.0", diff --git a/plugins/eventDumper.js b/plugins/eventDumper.js index 45e59008..e8a8bee5 100644 --- a/plugins/eventDumper.js +++ b/plugins/eventDumper.js @@ -3,7 +3,7 @@ * * @module plugins/eventDumper */ -const _ = require('underscore'); +const _ = require('lodash'); const doop = require('jsdoc/util/doop'); const dump = require('jsdoc/util/dumper').dump; const env = require('jsdoc/env'); diff --git a/test/fixtures/eventorder.js b/test/fixtures/eventorder.js index 0c9e497b..bf25d561 100644 --- a/test/fixtures/eventorder.js +++ b/test/fixtures/eventorder.js @@ -1,6 +1,6 @@ 'use strict'; -var _ = require('underscore'); +var _ = require('lodash'); /** * Socket class. diff --git a/test/specs/jsdoc/doclet.js b/test/specs/jsdoc/doclet.js index 4aa885cc..12f44609 100644 --- a/test/specs/jsdoc/doclet.js +++ b/test/specs/jsdoc/doclet.js @@ -1,6 +1,6 @@ describe('jsdoc/doclet', () => { // TODO: more tests - const _ = require('underscore'); + const _ = require('lodash'); const jsdoc = { doclet: require('jsdoc/doclet') };