mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
replace jsdoc/util/stripbom with strip-bom package
This commit is contained in:
parent
b717edb267
commit
2a95dcaa43
4
cli.js
4
cli.js
@ -12,7 +12,7 @@
|
|||||||
module.exports = (() => {
|
module.exports = (() => {
|
||||||
const env = require('jsdoc/env');
|
const env = require('jsdoc/env');
|
||||||
const logger = require('@jsdoc/logger');
|
const logger = require('@jsdoc/logger');
|
||||||
const stripBom = require('jsdoc/util/stripbom');
|
const stripBom = require('strip-bom');
|
||||||
const stripJsonComments = require('strip-json-comments');
|
const stripJsonComments = require('strip-json-comments');
|
||||||
const Promise = require('bluebird');
|
const Promise = require('bluebird');
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ module.exports = (() => {
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
// allow this to throw--something is really wrong if we can't read our own package file
|
// 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'),
|
const info = JSON.parse(stripBom(fs.readFileSync(path.join(env.dirname, 'package.json'),
|
||||||
'utf8')));
|
'utf8')));
|
||||||
|
|
||||||
env.version = {
|
env.version = {
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
const logger = require('@jsdoc/logger');
|
const logger = require('@jsdoc/logger');
|
||||||
const stripBom = require('jsdoc/util/stripbom');
|
const stripBom = require('strip-bom');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to information about a JavaScript package.
|
* Provides access to information about a JavaScript package.
|
||||||
@ -79,7 +79,7 @@ class Package {
|
|||||||
this.kind = 'package';
|
this.kind = 'package';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
packageInfo = JSON.parse(stripBom.strip(json) || '{}');
|
packageInfo = JSON.parse(stripBom(json) || '{}');
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
logger.error('Unable to parse the package file: %s', e.message);
|
logger.error('Unable to parse the package file: %s', e.message);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ const env = require('jsdoc/env');
|
|||||||
const fs = require('jsdoc/fs');
|
const fs = require('jsdoc/fs');
|
||||||
const logger = require('@jsdoc/logger');
|
const logger = require('@jsdoc/logger');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const stripBom = require('jsdoc/util/stripbom');
|
const stripBom = require('strip-bom');
|
||||||
const tutorial = require('jsdoc/tutorial');
|
const tutorial = require('jsdoc/tutorial');
|
||||||
|
|
||||||
// TODO: make this an instance member of `RootTutorial`?
|
// TODO: make this an instance member of `RootTutorial`?
|
||||||
@ -128,7 +128,7 @@ exports.load = filepath => {
|
|||||||
|
|
||||||
// configuration file
|
// configuration file
|
||||||
case 'json':
|
case 'json':
|
||||||
addTutorialConf(name, JSON.parse(stripBom.strip(content)));
|
addTutorialConf(name, JSON.parse(stripBom(content)));
|
||||||
|
|
||||||
// don't add this as a tutorial
|
// don't add this as a tutorial
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -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/, '');
|
|
||||||
21
package-lock.json
generated
21
package-lock.json
generated
@ -6077,6 +6077,17 @@
|
|||||||
"pify": "^2.0.0",
|
"pify": "^2.0.0",
|
||||||
"pinkie-promise": "^2.0.0",
|
"pinkie-promise": "^2.0.0",
|
||||||
"strip-bom": "^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": {
|
"locate-path": {
|
||||||
@ -9680,13 +9691,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"strip-bom": {
|
"strip-bom": {
|
||||||
"version": "2.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz",
|
||||||
"integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=",
|
"integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM="
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"is-utf8": "^0.2.0"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"strip-eof": {
|
"strip-eof": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
|||||||
@ -31,6 +31,7 @@
|
|||||||
"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-bom": "^3.0.0",
|
||||||
"taffydb": "2.6.2"
|
"taffydb": "2.6.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@ -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('');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Loading…
x
Reference in New Issue
Block a user