You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
642 B
25 lines
642 B
|
3 years ago
|
"use strict";
|
||
|
|
|
||
|
|
Object.defineProperty(exports, "__esModule", {
|
||
|
|
value: true
|
||
|
|
});
|
||
|
|
exports.default = toIdentifier;
|
||
|
|
|
||
|
|
var _isValidIdentifier = _interopRequireDefault(require("../validators/isValidIdentifier"));
|
||
|
|
|
||
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
|
||
|
|
function toIdentifier(name) {
|
||
|
|
name = name + "";
|
||
|
|
name = name.replace(/[^a-zA-Z0-9$_]/g, "-");
|
||
|
|
name = name.replace(/^[-0-9]+/, "");
|
||
|
|
name = name.replace(/[-\s]+(.)?/g, function (match, c) {
|
||
|
|
return c ? c.toUpperCase() : "";
|
||
|
|
});
|
||
|
|
|
||
|
|
if (!(0, _isValidIdentifier.default)(name)) {
|
||
|
|
name = `_${name}`;
|
||
|
|
}
|
||
|
|
|
||
|
|
return name || "_";
|
||
|
|
}
|