Sha256: 4904612738528287b538e29e53a1fdaa3dedc21ef87fc7ecfcafa36027b1a0af

Contents?: true

Size: 698 Bytes

Versions: 7

Compression:

Stored size: 698 Bytes

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = toIdentifier;

var _isValidIdentifier = require("../validators/isValidIdentifier");

var _helperValidatorIdentifier = require("@babel/helper-validator-identifier");

function toIdentifier(input) {
  input = input + "";
  let name = "";

  for (const c of input) {
    name += (0, _helperValidatorIdentifier.isIdentifierChar)(c.codePointAt(0)) ? c : "-";
  }

  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 || "_";
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
disco_app-0.16.1 test/dummy/node_modules/@babel/types/lib/converters/toIdentifier.js
disco_app-0.15.2 test/dummy/node_modules/@babel/types/lib/converters/toIdentifier.js
disco_app-0.18.4 test/dummy/node_modules/@babel/types/lib/converters/toIdentifier.js
disco_app-0.18.1 test/dummy/node_modules/@babel/types/lib/converters/toIdentifier.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@babel/types/lib/converters/toIdentifier.js
disco_app-0.14.0 test/dummy/node_modules/@babel/types/lib/converters/toIdentifier.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@babel/types/lib/converters/toIdentifier.js