Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 2x 2x 2x 2x 2x | import {toStr} from "../helpers/string/to_string";
import { REGEXP_TRIM_LEFT, REGEXP_TRIM_RIGHT } from "../helpers/regexp/regexp";
const reduce = Array.prototype.reduce;
const reduceRight = Array.prototype.reduceRight;
export const trim = (s, ws) => ltrim(rtrim(s, ws), ws)
export const ltrim = (s, ws) => {
let _s = toStr(s)
if (!ws) {return _s.replace(REGEXP_TRIM_LEFT, '')}
if (ws === '' || _s === '') {return _s}
if (typeof ws !== "string") {ws = ''}
let match = true
return reduce.call(
_s,
(trimmed, char) => {
if (match && ws.includes(char)) {
return trimmed;
}
match = false
return trimmed + char
},
''
);
}
export const rtrim = (s, ws) => {
let _s = toStr(s)
if (!ws) {return _s.replace(REGEXP_TRIM_RIGHT, '')}
if (ws === '' || _s === '') {return _s}
if (typeof ws !== "string") {ws = ''}
let match = true
return reduceRight.call(
_s,
(trimmed, char) => {
if (match && ws.includes(char)) {
return trimmed
}
match = false
return char + trimmed
},
''
);
} |