UNPKG

@tinyfe/naming-transform

Version:

Converting to different kind of naming style

54 lines 2.2 kB
// LINK_TO: https://en.wikipedia.org/wiki/Naming_convention_(programming) import Camel from './style/camel'; import Capital from './style/capital'; import Constant from './style/constant'; import Kebab from './style/kebab'; import Pascal from './style/pascal'; import Snake from './style/snake'; import Sentence from './style/sentence'; import Underscore from './style/underscore'; import { baseCase } from './base-case'; export * from './base-case'; export * from './utils/lower-case'; export * from './utils/lower-case-first'; export * from './utils/upper-case'; export * from './utils/upper-case-first'; const instances = { camel: new Camel(), capital: new Capital(), constant: new Constant(), kebab: new Kebab(), pascal: new Pascal(), snake: new Snake(), sentence: new Sentence(), underscore: new Underscore(), }; export const style = (input) => { for (let [key, instance] of Object.entries(instances)) { if (instance.test(input)) { return key; } } return ''; }; function transform(target, input, options) { const instance = instances[target]; if (!target || !instance) { return ''; } return instance[target](input, options); } export const camel = (input, options = {}) => transform('camel', input, options); export const capital = (input, options = {}) => transform('capital', input, options); export const constant = (input, options = {}) => transform('constant', input, options); export const kebab = (input, options = {}) => transform('kebab', input, options); export const pascal = (input, options = {}) => transform('pascal', input, options); export const snake = (input, options = {}) => transform('snake', input, options); export const sentence = (input, options = {}) => transform('sentence', input, options); export const dot = (input, options = { delimiter: '.' }) => baseCase(input, options); export const path = (input, options = { delimiter: '/' }) => kebab(input, options); export const header = (input, options = { delimiter: '-' }) => capital(input, options); export const hyphen = kebab; export const param = kebab; export const underscore = snake; //# sourceMappingURL=index.js.map