Comments (10)
@LukeAskew Not at the moment, but if it was to be added, what's the proposed behaviour? I assume it's straightforward and we keep it as usual, but this should be a standard preservation flag so what would happen if the user, say, preserves whitespace? Maybe we just present it doesn't matter? Does this compliment or allow replacements to the current replacement group? What if the next feature request is to omit something?
Sorry, just laying out some thoughts to start thinking about this. Let me know what you think too. It's definitely possible to add, just need to think about the use cases that might arrise. What methods do you expect to preserve characters?
from change-case.
A "replace" option is interesting. I could see how preserve
method could be an abstraction of replace
.
Maybe something like this:
changeCase.titleCase('3.0 a simple test')
//=> "3 0 A Simple Test"
changeCase.titleCase('3.0 a simple test', {
preserve: ['.']
})
//=> "3.0 A Simple Test"
changeCase.titleCase('3.0 a simple test', {
replace: [
['.', '.'],
[' ', '-']
]
})
//=> "3.0-A-Simple-Test"
Where preserve
leverages the internal replace
method, but with replaces with the same character.
from change-case.
Awesome thinking! So along those lines, I provide a "replace" argument at the moment on the base class but what we could do is make it a function. So you would do:
changeCase.titleCase('3.0 a simple test', function (char) {
return char === '.' ? '.' : ' '
})
My other question is still around the current preserve behaviour. Right now I have a few "complex" regexps that support different characters and apply transformations. Should they be allowed to be overridden or should this be purely a addition instead of a subtraction feature?
from change-case.
The function example is interesting. Could it handle multiple characters? Like if I wanted to replace/preserve both .
and -
?
I always lean toward more configurable, but the trade-off is potential for more edge case bugs.
Can you provide an example of what the transformation override might look like?
from change-case.
Yes, it could. You'd just pass function (char) { return /\.\-/.test(char) ? char : ' ' }
. I'm not sure on the transformation override, I can't actually work out what that was a reference to. Mostly I was thinking about characters you might want to omit that are currently included. Right now the code is simply https://github.com/blakeembrey/sentence-case/blob/master/sentence-case.js#L30-L36, and replacement could become a function instead of a string. However, I was thinking about what if you want to replace things I consider word characters? Maybe this can be more general and both parts can be overridden/extended? Things get a lot more complicated though since the more that's added the more potential it deviates a lot with what people want. Anyway, the function I think is easy and perfectly doable and doesn't break backward compatibility. What do you think?
from change-case.
Anything ever happen with this?
from change-case.
No, but welcome to a having a completed PR.
from change-case.
I donnot think it is not a good idea to make common styles more complicated to deal with small probability events. It is more rational to create a customised case style. E.g.
const leca = require('leca');
const mycase = new leca.Case({
splitter: /[\s_\-]/,
jointer: '-',
wordFormatter: word => word.toLowerCase(),
});
mycase.reformat('3.0 a simple test');
// RETURN "3.0-a-simple-test"
See README of leca for details.
from change-case.
For anyone looking for a work around or looking to take a crack at a PR here is some code I use to get it working when normally my brackets get taken out when doing snakecase.
let charName = argv.char;
let charTag = changeCase.snakeCase(charName);
let preserve = ['(', ')'];
for (punc of preserve) {
while (charTag.indexOf(punc) != charName.lastIndexOf(punc)) {
let index = charName.indexOf(punc);
charTag = charTag.substr(0, index) + punc + charTag.substr(index);
}
}
from change-case.
Just for reference charName is the string var before changecase applied, and charTag is the string var after chage case applied.
from change-case.
Related Issues (20)
- `title-case` capitalizes "from" (to "From") HOT 3
- title-case: a quoted word with a period in it doesn't get capitalized
- capitalCase when single number HOT 1
- Consider a new release
- param case with numbers as strings resulting in snake case? HOT 1
- Title Case not working with a camelCase string HOT 3
- sentenceCase function replaces non-English alphabets with whitespace HOT 1
- Why are tslib and typescript dependencies of these libraries? HOT 2
- Provide a custom array of additions to the lowercase words? HOT 1
- Sentence case HOT 1
- More lightweight solution
- VSCode extension alternatives
- Convert string to lowercase prior to processing HOT 3
- Could noCase package support Chinese word HOT 1
- Invalid or Unexpected Token on SUPPORTED LOCALES for change-case HOT 6
- Characater problem HOT 2
- brackets are removed from tite HOT 1
- Apostrophe not supported HOT 1
- TypeScript template literal support (`const camel: "fooBar" = camelCase("foo_bar")`) HOT 1
- Any interest in shipping ESM? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from change-case.