-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathstrip_bom.js
More file actions
32 lines (30 loc) · 770 Bytes
/
strip_bom.js
File metadata and controls
32 lines (30 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import coerceToString from 'helper/string/coerce_to_string';
const BYRE_ORDER_MARK = '\uFEFF';
/**
* Strips the byte order mark (BOM) from the beginning of `subject`.
*
* @function stripBom
* @static
* @since 1.2.0
* @memberOf Strip
* @param {string} [subject=''] The string to strip from.
* @return {string} Returns the stripped string.
* @example
*
* v.stripBom('\uFEFFsummertime sadness');
* // => 'summertime sadness'
*
* v.stripBom('summertime happiness');
* // => 'summertime happiness'
*
*/
export default function trim(subject) {
const subjectString = coerceToString(subject);
if (subjectString === '') {
return '';
}
if (subjectString[0] === BYRE_ORDER_MARK) {
return subjectString.substring(1);
}
return subjectString;
}