diff --git a/cli.js b/cli.js index 6fa698c1..1c09eacb 100644 --- a/cli.js +++ b/cli.js @@ -12,7 +12,7 @@ module.exports = (() => { const env = require('jsdoc/env'); const logger = require('@jsdoc/logger'); - const stripBom = require('jsdoc/util/stripbom'); + const stripBom = require('strip-bom'); const stripJsonComments = require('strip-json-comments'); const Promise = require('bluebird'); @@ -33,8 +33,8 @@ module.exports = (() => { const path = require('path'); // allow this to throw--something is really wrong if we can't read our own package file - const info = JSON.parse( stripBom.strip(fs.readFileSync(path.join(env.dirname, 'package.json'), - 'utf8')) ); + const info = JSON.parse(stripBom(fs.readFileSync(path.join(env.dirname, 'package.json'), + 'utf8'))); env.version = { number: info.version, diff --git a/lib/jsdoc/package.js b/lib/jsdoc/package.js index 779f84f1..558c5154 100644 --- a/lib/jsdoc/package.js +++ b/lib/jsdoc/package.js @@ -1,5 +1,5 @@ const logger = require('@jsdoc/logger'); -const stripBom = require('jsdoc/util/stripbom'); +const stripBom = require('strip-bom'); /** * Provides access to information about a JavaScript package. @@ -79,7 +79,7 @@ class Package { this.kind = 'package'; try { - packageInfo = JSON.parse(stripBom.strip(json) || '{}'); + packageInfo = JSON.parse(stripBom(json) || '{}'); } catch (e) { logger.error('Unable to parse the package file: %s', e.message); diff --git a/lib/jsdoc/tutorial/resolver.js b/lib/jsdoc/tutorial/resolver.js index 9a06e74a..1f206d26 100644 --- a/lib/jsdoc/tutorial/resolver.js +++ b/lib/jsdoc/tutorial/resolver.js @@ -5,7 +5,7 @@ const env = require('jsdoc/env'); const fs = require('jsdoc/fs'); const logger = require('@jsdoc/logger'); const path = require('path'); -const stripBom = require('jsdoc/util/stripbom'); +const stripBom = require('strip-bom'); const tutorial = require('jsdoc/tutorial'); // TODO: make this an instance member of `RootTutorial`? @@ -128,7 +128,7 @@ exports.load = filepath => { // configuration file case 'json': - addTutorialConf(name, JSON.parse(stripBom.strip(content))); + addTutorialConf(name, JSON.parse(stripBom(content))); // don't add this as a tutorial return; diff --git a/lib/jsdoc/util/stripbom.js b/lib/jsdoc/util/stripbom.js deleted file mode 100644 index 3395f9c2..00000000 --- a/lib/jsdoc/util/stripbom.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Module to strip the leading BOM, if present, from UTF-8 files. - * @module - * @private - */ - -/** - * Strip the leading BOM, if present, from a string. - * - * @private - * @param {string} text - The string to strip. - * @return {string} The stripped string. - */ -exports.strip = (text = '') => text.replace(/^\uFEFF/, ''); diff --git a/package-lock.json b/package-lock.json index edf2eaea..2cc02e30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6077,6 +6077,17 @@ "pify": "^2.0.0", "pinkie-promise": "^2.0.0", "strip-bom": "^2.0.0" + }, + "dependencies": { + "strip-bom": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", + "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", + "dev": true, + "requires": { + "is-utf8": "^0.2.0" + } + } } }, "locate-path": { @@ -9680,13 +9691,9 @@ } }, "strip-bom": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz", - "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=", - "dev": true, - "requires": { - "is-utf8": "^0.2.0" - } + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=" }, "strip-eof": { "version": "1.0.0", diff --git a/package.json b/package.json index 6ff361b5..98ec174c 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "marked": "~0.6.0", "mkdirp": "~0.5.1", "requizzle": "~0.2.1", + "strip-bom": "^3.0.0", "taffydb": "2.6.2" }, "devDependencies": { diff --git a/test/specs/jsdoc/util/stripbom.js b/test/specs/jsdoc/util/stripbom.js deleted file mode 100644 index aa778f04..00000000 --- a/test/specs/jsdoc/util/stripbom.js +++ /dev/null @@ -1,29 +0,0 @@ -describe('jsdoc/util/stripbom', () => { - const stripBom = require('jsdoc/util/stripbom'); - - it('should exist', () => { - expect(typeof stripBom).toBe('object'); - }); - - it('should export a "strip" method', () => { - expect(typeof stripBom.strip).toBe('function'); - }); - - describe('strip', () => { - it('should strip the leading BOM when present', () => { - const result = stripBom.strip('\uFEFFHello there!'); - - expect(result).toBe('Hello there!'); - }); - - it('should not change the text when no leading BOM is present', () => { - const result = stripBom.strip('Hello there!'); - - expect(result).toBe('Hello there!'); - }); - - it('should return an empty string when the text is null or undefined', () => { - expect(stripBom.strip()).toBe(''); - }); - }); -});