What's the best NPM package for doing the followin...
# random
m
What's the best NPM package for doing the following string manipulations: • Capitalizing, • Convert to pascal/camel/snake/kebab case, • Convert numbers to roman numerals, • Pluralize words etc. Essentially I'm looking for the JS equivalent of .Net's Humanizer.
f
d
Lodash has the capitalize and case conversions btw
Don’t see either of these having roman and plural though
f
Also, I suggest to implement these functions locally instead of using a library as depending on your bundler config, you may end up increasing the bundle size considerably by including code that you don’t even use.
d
@flat-morning-91037 - wouldn’t tree shaking help? https://lodash.com/per-method-packages
f
Yes tree-shaking certainly helps, but like I mentioned, depends on your webpack config. For instance, at GitLab we have a common bundle that includes framework code, and that bundle is loaded on pretty much every page regardless of functions used (due to commonality of function usages), but we also have page-specific bundles too which load only app code for that specific page.
d
Ok sure but why suggest implementing locally than using libraries. If someone doesn't feel need for proper bundling support, they aren't affected by bundle size and vice versa. Having a bigger bundle is lesser of evil of implementing functions that you could just use off lodash etc.
f
I determine on using library vs. own implementation based on following criteria; • How many functions I’d use out of everything that library brings. • In case of Lodash function, I always go through the source of the function before using it, to see its dependency tree as more often than not, it brings along a lot of other helpers to make the function work (eg; see
flatten
https://github.com/lodash/lodash/blob/4.17.15/lodash.js#L7325 implementation), which I could easily implement in native JS otherwise (eg; lodash’s
flatten
can be replaced with
Array.prototype.flat
for most scenarios). Goal of libraries like lodash is to offer full compatibility for large array of browsers/versions, which may be not be what you need and can easily do away with using modern JS.
a
We use lodash and pluralize js