fus-ext
Version:
FutureScript Extension
126 lines (124 loc) • 5.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.bound = exports.toBytes = exports.ensureTrailingNewline = exports.stripTrailingNewline = exports.split = exports.capitalize = exports.matches = exports.remove = exports.insert = exports.format = undefined;
var _main = require("./main");
var ok_573300145710716007 = function (a) {
return a !== undefined && a !== null;
};var dotDotCalc_573300145710716007 = function (dotDot, a, b, c) {
return dotDot(a)[b](a, ...c);
};var format, insert, remove, matches, capitalize, split, stripTrailingNewline, ensureTrailingNewline, toBytes, bound;exports.format = format = function (str, ...args) {
return (() => {
var s, m, i;s = str.valueOf();m = [];i = 0;(0, _main.loop)(function () {
return (() => {
var cur, next;return i < s.length ? (() => {
cur = s[i];next = s[i + 1];cur === "{" && next === "{" ? (() => {
m.push("{", "");i = i + 1;
})() : (() => {
return cur === "}" && next === "}" ? (() => {
m.push("}", "");i = i + 1;
})() : (() => {
return cur === "{" && next >= "0" && next <= "9" && s[i + 2] === "}" ? (() => {
m.push(args[parseInt(next, 10)].toString(), "", "");i = i + 2;
})() : (() => {
return m.push(cur);
})();
})();
})();i = i + 1;
})() : (() => {
return _main.break;
})();
})();
});return m.join("");
})();
};exports.insert = insert = function (str, index, value) {
return (() => {
var s;s = str.valueOf();return s.substr(0, index) + value + s.substr(index);
})();
};exports.remove = remove = function (str, start, length) {
if (length === undefined) {
length = 1;
}return (() => {
var s;s = str.valueOf();return s.substr(0, start) + s.substr(start + length);
})();
};exports.matches = matches = function (str, regex) {
return (() => {
var adjustedRegex, result;adjustedRegex = new RegExp(regex.source, "g");result = [];(0, _main.loop)(function () {
return (() => {
var theMatch;theMatch = adjustedRegex.exec(str.valueOf());return ok_573300145710716007(theMatch) ? (() => {
return result.push(theMatch);
})() : (() => {
return _main.break;
})();
})();
});return result;
})();
};exports.capitalize = capitalize = function (str) {
return (() => {
return str.charAt(0).toUpperCase() + str.substr(1);
})();
};exports.split = split = function (str, ...args) {
return (() => {
var arr;args[0] instanceof Array ? (() => {
args = args[0];
})() : undefined;arr = str.split(args[0]);return args.length === 2 && typeof args[1] === "number" ? (() => {
return args[1] === 0 ? (() => {
return [arr.join(args[0])];
})() : (() => {
return args[1] <= arr.length - 2 ? (() => {
return dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, arr, "portion", [0, args[1] - 1]).concat([dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, arr, "portion", [args[1]]).join(args[0])]);
})() : (() => {
return arr;
})();
})();
})() : (() => {
return args.length <= 1 ? (() => {
return arr;
})() : (() => {
return arr.map(function (s) {
return (() => {
return dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, s, "split", [dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, args, "portion", [1])]);
})();
});
})();
})();
})();
};exports.stripTrailingNewline = stripTrailingNewline = function (str) {
return (() => {
return str[str.length - 2] === "\r" && str[str.length - 1] === "\n" ? (() => {
return str.substr(0, str.length - 2);
})() : (() => {
return str[str.length - 1] === "\n" ? (() => {
return str.substr(0, str.length - 1);
})() : (() => {
return str.valueOf();
})();
})();
})();
};exports.ensureTrailingNewline = ensureTrailingNewline = function (str) {
return (() => {
return str[str.length - 1] !== "\n" ? (() => {
return str.valueOf() + "\n";
})() : (() => {
return str.valueOf();
})();
})();
};exports.toBytes = toBytes = function (str) {
return (() => {
return dotDotCalc_573300145710716007(_main.dotDot_573300145710716007, Uint8Array, "fromString", [str]);
})();
};exports.bound = bound = function (str) {
return (() => {
return str.length - 1;
})();
};exports.format = format;
exports.insert = insert;
exports.remove = remove;
exports.matches = matches;
exports.capitalize = capitalize;
exports.split = split;
exports.stripTrailingNewline = stripTrailingNewline;
exports.ensureTrailingNewline = ensureTrailingNewline;
exports.toBytes = toBytes;
exports.bound = bound;