UNPKG

@jeswr/prefixcc

Version:

A utility library to lookup prefixes and uris on prefixcc

38 lines (37 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fragment = void 0; function getFragment(inputStr) { let str = inputStr; if (str.endsWith('/') || str.endsWith('#')) { str = str.slice(0, str.length - 1); } const args = []; if (str.lastIndexOf('/') > 0) { args.push(str.lastIndexOf('/')); } if (str.lastIndexOf('#') > 0) { args.push(str.lastIndexOf('#')); } const i = Math.max(...args); return str.slice(i + 1); } function camelize(str) { var _a; const res = (_a = str .split(/[^a-z0-9]+/ig) .filter((s) => s !== '') .map((s) => s[0].toUpperCase() + s.slice(1)) .join('') // Make sure the prefix does not start with a number .match(/[a-z][a-z0-9]+/ig)) === null || _a === void 0 ? void 0 : _a[0]; // Include 'v' so we always return something matching the pattern // [a-z][a-z0-9]+ return typeof res === 'undefined' ? undefined : res[0].toLowerCase() + res.slice(1); } function fragment(str) { let value = getFragment(str); value = value ? camelize(value) : undefined; return value || 'v'; } exports.fragment = fragment;