function parseNpmName()

in packages/build-plugin-lowcode/src/utils/index.js [30:57]


function parseNpmName(npmName) {
  if (typeof npmName !== 'string') {
    throw new TypeError('Expected a string');
  }
  const matched =
    npmName.charAt(0) === '@' ? /(@[^\/]+)\/(.+)/g.exec(npmName) : [npmName, '', npmName];
  if (!matched) {
    throw new Error(`[parse-package-name] "${npmName}" is not a valid string`);
  }
  const scope = matched[1];
  const name = (matched[2] || '').replace(/\s+/g, '').replace(/[\-_]+([^\-_])/g, ($0, $1) => {
    return $1.toUpperCase();
  });
  const uniqueName =
    (matched[1]
      ? matched[1].charAt(1).toUpperCase() +
        matched[1].slice(2).replace(/[\-_]+([^\-_])/g, ($0, $1) => {
          return $1.toUpperCase();
        })
      : '') +
    name.charAt(0).toUpperCase() +
    name.slice(1);
  return {
    scope,
    name,
    uniqueName,
  };
}