1 | ;
|
2 | /**
|
3 | * Removes trailing and leading spaces from a String.
|
4 | *
|
5 | * @param {String} str
|
6 | * @return {String}
|
7 | *
|
8 | * @example
|
9 | * trimString(' something here ')
|
10 | * // => 'something here'
|
11 | */
|
12 |
|
13 | exports.trimString = function trimString(str) {
|
14 | return str.replace(/(^\s*)|(\s*$)/g, '');
|
15 | };
|
16 |
|
17 | // Copied from node.js' built-in `lib/module.js` module
|
18 | exports.stripBOM = function stripBOM(content) {
|
19 | // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
|
20 | // because the buffer-to-string conversion in `fs.readFileSync()`
|
21 | // translates it to FEFF, the UTF-16 BOM.
|
22 | if (content.charCodeAt(0) === 0xFEFF) {
|
23 | content = content.slice(1);
|
24 | }
|
25 | return content;
|
26 | };
|