diff options
author | Minteck <contact@minteck.org> | 2022-10-18 08:59:09 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-10-18 08:59:09 +0200 |
commit | 2c4ae43e688a9873e86211ea0e7aeb9ba770dd77 (patch) | |
tree | 17848d95522dab25d3cdeb9c4a6450e2a234861f /alarm/node_modules/string-trim-spaces-only/dist/string-trim-spaces-only.esm.js | |
parent | 108525534c28013cfe1897c30e4565f9893f3766 (diff) | |
download | pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.gz pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.tar.bz2 pluralconnect-2c4ae43e688a9873e86211ea0e7aeb9ba770dd77.zip |
Update
Diffstat (limited to 'alarm/node_modules/string-trim-spaces-only/dist/string-trim-spaces-only.esm.js')
-rw-r--r-- | alarm/node_modules/string-trim-spaces-only/dist/string-trim-spaces-only.esm.js | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/alarm/node_modules/string-trim-spaces-only/dist/string-trim-spaces-only.esm.js b/alarm/node_modules/string-trim-spaces-only/dist/string-trim-spaces-only.esm.js new file mode 100644 index 0000000..d241b54 --- /dev/null +++ b/alarm/node_modules/string-trim-spaces-only/dist/string-trim-spaces-only.esm.js @@ -0,0 +1,85 @@ +/** + * @name string-trim-spaces-only + * @fileoverview Like String.trim() but you can choose granularly what to trim + * @version 3.1.0 + * @author Roy Revelt, Codsen Ltd + * @license MIT + * {@link https://codsen.com/os/string-trim-spaces-only/} + */ + +var version$1 = "3.1.0"; + +const version = version$1; +const defaults = { + classicTrim: false, + cr: false, + lf: false, + tab: false, + space: true, + nbsp: false +}; +function trimSpaces(str, originalOpts) { + if (typeof str !== "string") { + throw new Error(`string-trim-spaces-only: [THROW_ID_01] input must be string! It was given as ${typeof str}, equal to:\n${JSON.stringify(str, null, 4)}`); + } + const opts = { ...defaults, + ...originalOpts + }; + function check(char) { + return opts.classicTrim && !char.trim() || !opts.classicTrim && (opts.space && char === " " || opts.cr && char === "\r" || opts.lf && char === "\n" || opts.tab && char === "\t" || opts.nbsp && char === "\u00a0"); + } + let newStart; + let newEnd; + if (str.length) { + if (check(str[0])) { + for (let i = 0, len = str.length; i < len; i++) { + if (!check(str[i])) { + newStart = i; + break; + } + if (i === str.length - 1) { + return { + res: "", + ranges: [[0, str.length]] + }; + } + } + } + if (check(str[str.length - 1])) { + for (let i = str.length; i--;) { + if (!check(str[i])) { + newEnd = i + 1; + break; + } + } + } + if (newStart) { + if (newEnd) { + return { + res: str.slice(newStart, newEnd), + ranges: [[0, newStart], [newEnd, str.length]] + }; + } + return { + res: str.slice(newStart), + ranges: [[0, newStart]] + }; + } + if (newEnd) { + return { + res: str.slice(0, newEnd), + ranges: [[newEnd, str.length]] + }; + } + return { + res: str, + ranges: [] + }; + } + return { + res: "", + ranges: [] + }; +} + +export { defaults, trimSpaces, version }; |