tslint-immutable
Version:
TSLint rules to disable mutation in TypeScript.
52 lines • 1.65 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Converts ruleArguments in format
* ["foo-bar", {do-it: "foo"}, "do-not-do-it"]
* to options in format
* {fooBar: true, doIt: "foo", doNotDoIt: true}
*/
// tslint:disable-next-line:no-any
function parseOptions(ruleArguments) {
var options = {};
for (var _i = 0, ruleArguments_1 = ruleArguments; _i < ruleArguments_1.length; _i++) {
var o = ruleArguments_1[_i];
if (typeof o === "string") {
options[camelize(o)] = true;
}
else if (typeof o === "object") {
var o2 = {};
for (var _a = 0, _b = Object.keys(o); _a < _b.length; _a++) {
var key = _b[_a];
o2[camelize(key)] = o[key];
}
options = __assign({}, options, o2);
}
}
// tslint:disable-next-line:no-any
return options;
}
exports.parseOptions = parseOptions;
function upFirst(word) {
return word[0].toUpperCase() + word.toLowerCase().slice(1);
}
function camelize(text) {
var words = text.split(/[-_]/g);
return (words[0].toLowerCase() +
words
.slice(1)
.map(upFirst)
.join(""));
}
//# sourceMappingURL=options.js.map
;