UNPKG

extra-path

Version:

Useful additions to inbuilt path module.

28 lines (24 loc) 935 B
import { basename, extname } from 'path'; export { basename, delimiter, dirname, extname, format, isAbsolute, join, normalize, parse, posix, relative, resolve, sep, toNamespacedPath, win32 } from 'path'; function IDENTITY(v) { return v; } function toKebabCase(x, re = null, sep = "-") { var words = x.split(re || /[^0-9A-Za-z]+/g).filter(IDENTITY); for (var i = 0, I = words.length; i < I; ++i) { words[i] = words[i].replace(/[A-Z]+/g, m => m.length === 1 ? sep + m : sep + m.slice(0, -1) + sep + m.slice(-1)); if (words[i].startsWith(sep)) words[i] = words[i].slice(sep.length); } return words.join(sep).toLowerCase(); } function filename(pth) { return basename(pth, extname(pth)); } function symbolname(pth) { return filename(pth).replace(/[^\w$]+/g, "_"); } function keywordname(pth) { return toKebabCase(filename(pth)); } export { filename, keywordname, symbolname };