String Manipulation Functions
Ramda already has:
Under discussion:
1. Case
- [ ] capitalize
2. Formatting
- [ ] pad() Ref: lodash.pad
- [ ] padLeftStart()
- [ ] padEnd()
Proposed:
1. Case
- [ ] toSnakecase
alpha_beta - [ ] toKebabCase / dasherize
alpha-beta - [ ] toCamelCase
alphaBeta - [ ] to PascalCase / alias: toUpperCamelCase
AlphaBeta - [ ] toTitleCase
Alpha Beta/ alias: toStartCase Ref: lodash.startCase - [ ] toDotCase
alpha.beta - [ ] toMacroCase / alias: toScreamingSnakeCase
ALPHA_BETA
2. Formatting
- [ ] wrap()
wrap("'")('alpha')->'alpha'/wrap('[', ']')('alpha')->[alpha]
3. Whitespace
- [ ] compressWhitespace Reduce all whitespace to a single space per section of whitespace
- [ ] stripWhitespace Remove all whitespace
- [ ] stripLinebreaks Remove linebreaks
- [ ] dedent Ref: npm(https://www.npmjs.com/package/dedent)
- [ ] wordWrap Ref: Rails Wrap lines to x chars
4. Inflection Ref: lodash-inflection, Ref node-inflection
- [ ] deburr Ref: lodash.deburr Remove accented chars
Love wrap for creating pipelines ;-)
But is it a good idea to name it wrap ? maybe wrapString ?
for the others, names looks good to me.
Ref: Some of my own formatting utils for reference. Some are project-specific, but some are general.
Ref: Rails string utils
@Undistraction dedent is a nice one too https://www.npmjs.com/package/dedent
Let's update only your first comment so that it contains all the information for taking actions
Regarding toUpperCamelCase / toPascalCase
toPascalCase should be primary name and tuUpperCamelCase @alias.
toStartCase Ref: lodash.pad -> toStartCase Ref: lodash.startCase
toTitleCase with capitalize @alias
dedent is a nice one too https://www.npmjs.com/package/dedent
Added
Regarding toUpperCamelCase / toPascalCase
How about toMacroCase / toScreamingSnakeCase?
oStartCase Ref: lodash.pad -> oStartCase Ref: lodash.startCase
Done
toTitleCase with capitalize @alias
These are two different functions - capitalise capitalises only the first letter of the first word toTitleCase capitalises the first letter of every word.
How about toMacroCase / toScreamingSnakeCase?
Would go for toMacroCase as primary and toScreamingSnakeCase as @alias
These are two different functions - capitalise capitalises only the first letter of the first word toTitleCase capitalises the first letter of every word.
Ok does toCapitalCase and toTitleCase make sense ?
Ok does toCapitalCase and toTitleCase make sense ?
I think they have different intents - the to...Case are transforming across the whole string, but capitalize will only ever change the first char.
We could go with: firstToUpper or uppercaseFirst or similar, but capitalize is consistent with lodash.
Yeah agree capitalize is for sure better.
For kebab case and other cases we will need these utils to sanitize the input string (should be part of src/internal):
// canonicalDecompose :: String -> String
export const canonicalDecompose = invoker(1, 'normalize')('NFD');
// removes combining characters from decomposed form
// removeAccents :: String -> String
export const removeAccents = replace(/[\u0300-\u036f]/g, '');
@char0n Lodash exposes removal of accents as deburr so probably worth adding.
Cool so we'll combine these two into deburr
This is lodash deburr implementation. As it seems my utils solve only part of the problem. There are other problems to solve. But we should refrain from copying the from lodash to avoid licensing issues and do our own research. deburr is priority now because it's the base for lot of other string utility functions.
Question: what input are we accepting for all the to...Case functions. Should they only work on a spaced string - alpha beta or should they work on each other - for example should toCamelCase work on alpha-beta and alpha.beta?
I would expect them to work on each other. Lodash seems to agree.
stripLinebreaks -- trim is often used for that, it strips all whitespace from beggining and end of the string.
What stripWhitespace would be supposed to do?
wrap should have fixed arity of 3. And it wouldn't have to be limited to strings :)
@char0n You might be interested in a little lib I just published: https://github.com/Undistraction/dedent-preserving-indents. It works much like dedent, but preserves all indentation past the line with the least whitespace. Might be nice to expose as a utility through RA.
@Undistraction yeah why not, but it will have to reintegrated and not used as dependency.
@gingerplusplus I think you've failed to understand the purpose of this function.
but it will have to reintegrated and not used as dependency
@char0n Yep. I'll open an issue for it and we can look at it somewhere down the line.
Also upperFirst, truncate would be useful