blakeembrey / change-case Goto Github PK
View Code? Open in Web Editor NEWConvert strings between camelCase, PascalCase, Capital Case, snake_case and more
License: MIT License
Convert strings between camelCase, PascalCase, Capital Case, snake_case and more
License: MIT License
The documentation for paramCase disagrees with the code and tests.
Which is correct? Are you going to change the documentation or the implementation?
Thanks!
Hi Blake,
thank you for maintaining all these small, focused packages.
I wonder if you keep track of changes between releases somewhere? I've looked around but couldn't find them. I'm in particular interested in the breaking changes of `pascal-case@v3'
Hello.
I never write require(' ')
in my apps, so I'm not sure their support for tree-shaking.
But with the official ES import method:
import { camelCase } from 'change-case'
this would allow webpack and rollup to tree-shake the 'change-case' package to only include camelCase
for example.
Is this possible with your package as well?
If we were to follow a style guide like "The Chicago Manual of Style" then the tile case rules would be as follows:
The following rules, though occasionally arbitrary, are intended primarily to facilitate the consistent styling of titles mentioned or cited in text and notes:
- Capitalize the first and last words in titles and subtitles (but see rule 7), and capitalize all other major words (nouns, pronouns, verbs, adjectives, adverbs, and some conjunctions—but see rule 4).
- Lowercase the articles the, a, and an.
- Lowercase prepositions, regardless of length, except when they are used adverbially or adjectivally (up in Look Up, down in Turn Down, on in The On Button, to in Come To, etc.) or when they compose part of a Latin expression used adjectivally or adverbially (De Facto, In Vitro, etc.).
- Lowercase the common coordinating conjunctions and, but, for, or, and nor.
- Lowercase to not only as a preposition (rule 3) but also as part of an infinitive (to Run, to Hide, etc.), and lowercase as in any grammatical function.
- Lowercase the part of a proper name that would be lowercased in text, such as de or von.
- Lowercase the second part of a species name, such as fulvescens in Acipenser fulvescens, even if it is the last word in a title or subtitle.
http://www.chicagomanualofstyle.org/book/ed17/part2/ch08/psec159.html
Some examples at http://www.chicagomanualofstyle.org/book/ed17/part2/ch08/psec160.html
Mnemonics That Work Are Better Than Rules That Do Not Singing While You Work A Little Learning Is a Dangerous Thing (2) Four Theories concerning the Gospel according to Matthew (2, 3) Taking Down Names, Spelling Them Out, and Typing Them Up (3, 4) Tired but Happy (4)
I'd suggest, for ease, a subset of those rules be implemented. Perhaps algorithmically something like the following (corresponding roughly to the above rules):
Edit: Added "(not in a first or last position)" clause to suggested algorithm.
as per title, for example user key in "CCTV distributor", it should convert to "CCTV Distributor" instead of "Cctv Distributor"
At the moment, snakeCase doesn't insert an underscore before numbers. I would expect it to do that.
Current behaviour:
changeCase.snakeCase("pricePer100Km")
returns price_per100_km
.
Expected behaviour:
changeCase.snakeCase("pricePer100Km")
returns price_per_100_km
.
If this is not a bug, then I would suggest making it an option through a possible argument. Maybe like this:
changeCase.snakeCase("pricePer100Km", {handleNumbers: true})
returns price_per_100_km
.
I cant seem to get a working import declaration for Angular 5
Due to how Lerna works (and refuses to change), when a patch changes it publishes all dependents with patches also. This creates a lot of release noise. Need to investigate how this could either be eliminated, or bundled into a single release for simpler documenting of the change.
For now, the convention I'll follow is that undocumented releases were only patches and do not contain any note worthy changes.
When converting a string into a title, the initial letter of preposition and conjunction should not be capitalized, such as and, with, of.
It would be nice to have a lcFirst function.
This is needed for example to convert an object name to a variable in angular.
For example i want to convert SearchService object into searchService variable.
It is easy to craft a function of the type:
function firstCharLowercase(string) {
return string.charAt(0).toLowerCase() + string.slice(1);
}
but it would be nicer to have it here because already an ucfirst function exists :-)
Since v3, require('snake-case')
and others no longer return a function:
$ node
> require('snake-case')
{ snakeCase: [Function: snakeCase] }
Is that by design?
Add the ability to pass an object to a change-case
function to recurse the object and apply the change to object values.
After v4, lowerCase
and titleCase
are no longer exported but it used to be exported in older versions.
I have a string "amazon s3 data" that I have pushed through paramCase. The result is "amazon-s-3-data" , where I really wanted "amazon-s3-data"
is there any way of doing this, or will I have to do some manipulation myself ?
and couldn't find it. Five minutes later I realized that it is pascalCase
.
Funny cognitive dissonance.
Thanks for this library Blake!
Ge
Using the PascalCase conversion:
controller.js
becomes:
ControllerJs
not:
Controller.js or Controller.Js
Keeps saying it can't find module dot-case
, upon inspecting the code I believe it has to do with how you require each dependency in the loop. browserify is statically analyzing the module so it doesn't complete the dependency graph.
Could you publish a migration guide explaining how to upgrade change-case
from v3 to v4?
My tests passed after upgrading but I'd like to ensure.
In https://github.com/blakeembrey/change-case/releases I see tags for partial packages like title-case
or swap-case
but I see no tags for change-case
.
I.e:
changeCase.sentence('whaleShark') // -> 'Whale shark'
This isn't particularly significant for what I'm doing (generating a friendly name for a model type to use in an error message), but I was curious to know whether my suspicion is correct or not :)
This is more of a question rather than an issue. In version 3.x, we used the mergeNumbers
option when invoking camelCase
, example:
const camelCase('some_field_1', '', true); // -> someField1
Since upgrading to version 4, it looks like the options accepted by camelCase
have been centralised, and this feature has been lost, is this correct?
Is there a recommended way to achieve the above with version 4?
This module uses [email protected], which you also maintain. no-case <2.3.2 has been identified as having a high ranking vulnerability with a CVSS score of 7.5.
https://nodesecurity.io/advisories/529
Please update change-case to use [email protected] to avoid this vulnerability.
I want to use this lib in my frontend, using bower - do you have a build script that would create a single dist file, or will I have to roll my own ?
First off, thanks for the lib, it's fantastic! 😄
So, leading underscores are not preserved (even with snakeCase
):
changeCase.snakeCase('private'); //=> 'private'
changeCase.snakeCase('_private'); //=> 'private'
changeCase.snakeCase('private_key'); //=> 'private_key'
changeCase.snakeCase('_private_key'); //=> 'private_key'
changeCase.snakeCase('privateKey'); //=> 'private_key'
changeCase.snakeCase('_privateKey'); //=> 'private_key'
changeCase.camelCase('private_key'); //=> 'privateKey'
changeCase.camelCase('_private_key'); //=> 'privateKey'
There's a strong argument to be made that this is expected behavior for camelCase
specifically, but I think for snakeCase
it is arguably not expected behavior; leading underscores are pretty widely used as a convention to denote privacy, and the presence of a leading underscore doesn't conflict with the rules of "snake case", unless I'm mistaken.
Thoughts?
If this is intended behavior/"wontfix", would you consider an option parameter to preserve leading underscores?
E.g. "Ronny's brother" is transformed to "Ronny S Brother"
Did you deliberately remove the upperCaseFirst
functionality or is it hidden somewhere else now?
import { ucFirst } from 'change-case';
Updated from 3.1.0
to 4.0.0
.
Why removing function instead of deprecation?
Also it's not clear how to import upperCaseFirst
.
not sure this is the right term. i'm talking about this (kebab case).
it's very useful for some of the web programmers
Afternoon. Great module. I was wondering if there was any thought of adding these methods to the String prototype to enable str.titleCase()? etc?
Consider the following code:
require('change-case').camelCase()
Using change-case
version 3.x (3.1.0
), this code works and returns and empty string ''
.
Using change-case
version 4.x (4.0.0
), this code throws the following error:
TypeError: Cannot read property 'replace' of undefined
at Object.noCase (node_modules/no-case/dist/index.js:14:10)
at Object.pascalCase (node_modules/pascal-case/dist/index.js:15:22)
at Object.camelCase (node_modules/camel-case/dist/index.js:11:26)
Assuming this new behavior is intended: can we document the change in release notes please?
A good enhancement IMO would be to be able to do something like:
changeCase('someWord').chain()
.toSnakeCase()
.firstUpperCase()
...
.value()
If it's a good idea I can create a pull request to add that.
I would love to have camel case - or any other transformations from upper case to lower case - to take abbreviations into account. The list of abbreviations can be passed as a paramter.
For even greater modularisation, let's split every method out into their own repos to be included.
With PHP, variables start with the $ character. It would be great if this character was not stripped by change-case.
For instance:
$postID becomes post_id instead of $post_id
Is there a way to preserve punctuation, specifically .
dots?
For going from whatever-case to Title-Case-With-Hyphens for use in things like HTTP headers:
contentType -> Content-Type
ccRequestType -> CC-Request-Type
I just ran into a situation where I had a bunch of (lowercase) snake_case symbols and needed each word to be in title case. Sadly change-case does not handle this flavor. For example, I want to be able to transform some_thing
into Some_Thing
. I know this is a little uncommon but it would have been very helpful just now!
I am using change-case via the VSCode extension and it is tremendously useful. Thanks for the great library!
In ionic 4 while importing changeCase from change-case it is throwing this error Module '"/node_modules/change-case/change-case"' has no default export It working fine in ionic 3
Given this code
var cs = require('change-case')
cs.pascal('something2014other')
I would assume the result to be Something2014Other
, not Something2014other
.
Same goes for camel casing.
Ran into an issue trying to normalise some strings. Trying to camelCase a string that's camel cased and contains two words works as expected:
changeCase.camelCase("fooBar");
// outputs fooBar
More than three words seems to break it though:
changeCase.camelCase("fooBarBaz");
// outputs fooBarbaz
Perhaps a silly request, but is it possible to add AP style capitalization?
More info: http://titlecapitalization.com/
Error thrown in test:
TypeError {
message: 'Cannot destructure property `splitRegexp` of \'undefined\' or \'null\'.',
}
noCase (node_modules/no-case/src/index.ts:20:9)
maskString (src/index.js:199:25)
maskProps (src/index.js:253:18)
parseRequest (src/index.js:400:12)
test/basic.js:518:15
Would be nice to identify case of string, eg:
change-case.identifyCase("Love"); -> titleCase
change-case.identifyCase("LOVE"); -> All Uppercase
etc
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.