UNPKG

froebel

Version:
13 lines (11 loc) 539 B
import { capitalize } from "./case.mjs"; /** * Returns `str` prefixed with `prefix`. Optionally, allows prefxing in camel * case, i.e. `prefix('foo', 'bar', 'camel') => 'fooBar'`, or snake case, i.e. * `prefix('foo', 'bar', 'snake') => 'foo_bar'`. * * The result is strictly typed, so `prefix('foo', 'bar')` will return the type * `'foobar'`, not just a generic `string`. */ const prefix = (prefix, str, caseMod) => `${prefix}${caseMod === "snake" ? "_" : ""}${caseMod === "camel" ? capitalize(str) : str}`; export default prefix;