craydent-cli
Version:
Node module to manage command line execution and arguments
51 lines (50 loc) • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = _generalTrim;
/*/---------------------------------------------------------/*/
/*/ Craydent LLC node-v0.9.0 /*/
/*/ Copyright 2011 (http://craydent.com/about) /*/
/*/ Dual licensed under the MIT or GPL Version 2 licenses. /*/
/*/ (http://craydent.com/license) /*/
/*/---------------------------------------------------------/*/
/*/---------------------------------------------------------/*/
const craydent_error_1 = require("craydent.error");
const __convertRegexSafe_1 = require("../private/__convertRegexSafe");
const craydent_isarray_1 = require("craydent.isarray");
const craydent_isstring_1 = require("craydent.isstring");
function _generalTrim(str, side, characters) {
try {
let temp = str, trimChars = {
" ": 1,
"\t": 1,
"\n": 1
};
if (characters) {
if ((0, craydent_isarray_1.default)(characters)) {
let ch, i = 0;
trimChars = {};
while (ch = characters[i++]) {
trimChars[ch] = 1;
}
}
else if ((0, craydent_isstring_1.default)(characters)) {
trimChars = eval('({"' + (0, __convertRegexSafe_1.default)(characters) + '":1})');
}
}
if (!side || side == 'l') {
while (temp.charAt(0) in trimChars) {
temp = temp.substring(1);
}
}
if (!side || side == 'r') {
while (temp.charAt(temp.length - 1) in trimChars) {
temp = temp.substring(0, temp.length - 1);
}
}
return temp.toString();
}
catch (e) /* istanbul ignore next */ {
craydent_error_1.default && (0, craydent_error_1.default)("_generalTrim", e);
return str;
}
}