mesqueeb / case-anything Goto Github PK
View Code? Open in Web Editor NEWcamelCase, kebab-case, PascalCase... a simple integration with nano package size. (SMALL footprint!)
Home Page: https://github.com/sponsors/mesqueeb
License: MIT License
camelCase, kebab-case, PascalCase... a simple integration with nano package size. (SMALL footprint!)
Home Page: https://github.com/sponsors/mesqueeb
License: MIT License
The request "header" keys are typically set as kebab-case but with the first letters as in capital.
See the Postman screenshot:
The normal "kebab-case" transforms the full string to lowercase.
To facilitate the automatic casing of header keys, it want to get your input if you would be open for a PR to introduce an additional casing: Capital-Kebab-Case
?
/**
* converts strings to Capital-Kebab-Case
*
* @export
* @param {string} string
* @returns {string} in Kebab-Case
*/
function capitalKebabCase(string) {
return getParts(string, noSpecialChars)
.map(part => capitaliseWord(part))
.join('-')
}
Example:
capitalKebabCase('ponytaVaporeonPOLIWRATH_ButterfreeA')
=> Ponyta-Vaporeon-Poliwrath-Butterfree-A
Any feedback on the idea is welcome.
Hi @mesqueeb,
Sorry to come back to the "special characters" item, when implementating the v2 of case-anything, the special characters results felt a unlogical when it comes to the "-" & "_" characters, that are kept.
When using for example a PascalCase conversion:
const valueAsString = "$sample-example-reports"
const result1 = pascalCase(valueAsString,{keepSpecialCharacters: false}) // result = SampleExampleReports
const result2 = pascalCase(valueAsString,{keepSpecialCharacters: true}) // result = $Sample-Example-Reports
result1 is logical but for result2 I would have expected: $SampleExampleReports
My first thought would be that the "-" & "_" would be replace since they are linked to the various casing conversion (kebab-case, snake_case, ...) and the special characters would be all the other characters lik "@", "$", ...
Crashes:
pascalCase('a b');
Hello, thank you for this wonderful utility library! I was curious if you'd be willing to add a sentenceCase
utility? I saw it was briefly considered in #10. I think this would be great for design systems that want to enforce this in UI elements like buttons. Happy to submit a PR if it sounds good π
Hi @mesqueeb,
Thanks for the creation of such a powerful, yet easy to use package + the footprint is nice & small.
I noticed that when transforming a string with an @ or $ character, the @ & $ gets removed.
Example:
Is there a way to prevent this?
Hi,
I like 'case-anything'. However, I met an edge case today that you should examine.
The following two conversion differ
lowerCase('MSkS') // 'm sk s'
'MSkS'.toLowerCase() // 'msks'
So far, it is the only time I have seen where lowerCase() fails, and I have been using it extensively. I hope you can find out the issue - it did cost be the better part of a day to track the erroneous conversion.
I tried 2.1.3 in my package and I ran into this error:
} = require("case-anything");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/Sites/asyncapi-format/node_modules/case-anything/dist/index.umd.js from /Users/Sites/asyncapi-format/asyncapi-format.js not supported.
index.umd.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename index.umd.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /Users/Sites/asyncapi-format/node_modules/case-anything/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).
at Object.<anonymous> (/Users/Sites/asyncapi-format/asyncapi-format.js:21:5)
at Object.<anonymous> (/Users/Sites/asyncapi-format/bin/cli.js:5:24) {
code: 'ERR_REQUIRE_ESM'
Version 2.1.2 works without a problem.
Originally posted by @thim81 in #20 (comment)
It works for camelCase
For Example
spaceCase('$catDog') // Output: $cat Dog
But doesn't for snake_case
spaceCase('$cat_dog') // Output: $cat_dog
// but Expected output: $cat dog
I think recent update of "better touch tool" now allows to run JS/node scripts...?
I'm thinking a cool shortcut for executing those could be:
ββC
+ ββP
for pascal case ([C]ase [P]ascal)ββC
+ ββC
for camel caseββC
+ ββK
for kebab caseOr if it's easier to implement the scripts that use the "clipboard" information, we can even do this:
βC
+ ββP
for pascal case ([C]ase [P]ascal)βC
+ ββC
for camel caseβC
+ ββK
for kebab caseThen the first [C] still stands for [C]ase, but as a side effect we're also putting it onto our clipboards.
example
const caseAnything = require('case-anything')
cascaseAnything.camelCase('δ½ ε₯½')
cascaseAnything.kebabCase('γγγ«γ‘γ―')
this code will throw error
/sandbox/node_modules/case-anything/dist/index.cjs.js:29
return noSpecialChars ? parts.map(function (part) { return part.normalize('NFD').replace(/[^a-zA-ZΓΓΓΈ0-9]/g, ''); }) : parts;
^
TypeError: Cannot read property 'map' of null
at getParts (/sandbox/node_modules/case-anything/dist/index.cjs.js:29:35)
at Object.camelCase (/sandbox/node_modules/case-anything/dist/index.cjs.js:51:12)
at Server.<anonymous> (/sandbox/src/index.js:7:28)
at Server.emit (events.js:198:13)
at parserOnIncoming (_http_server.js:695:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:111:17)
I'm trying to make some case conversions for certain types of sensors (e.g. pH sensor, TSS sensor etc).
I haven't covered all the different case types here but I think this is sufficient to indicate there is a fundamental problem with single-letter abbreviated words. For example, in the following code:
import { capitalCase, kebabCase, camelCase, pascalCase } from 'case-anything';
// From Camel Case
console.log(pascalCase('tSS'));
console.log(camelCase('tSS'));
console.log(capitalCase('tSS'));
console.log(kebabCase('tSS'));
// From Pascal Case
console.log(pascalCase('TSS'));
console.log(camelCase('TSS'));
console.log(capitalCase('TSS'));
console.log(kebabCase('TSS'));
Gives the following wrong results:
TSs
tSs
T Ss
t-ss
Tss
tss
Tss
tss
Which is different from the expected result which SHOULD be:
TSS
tSS
T S S
t-s-s
TSS
tSS
T S S
t-s-s
By the way the abbreviation "TSS" used here stands for "Total Suspended Solids". I am using "TSS" to shorten strings.
All that being said, this is a magnificent project and I hope this bug report will help improve it even further. Thanks in advance.
I tried to update the version of case-anything I'm using in PopClip to 2.x but ran into a small problem. It crashes when I run it on High Sierra (and possibly other older macOS) because the JavaScriptCore runtime on those systems is too old to support String.matchAll()
, which is used in the utils module.
If it were possible to use String.match()
instead I think it would work. It's not a showstopper because I can easily carry on using 1.x which actually works really well anyway.
I noticed that during automated testing using Github actions, after implementation of the case-anything package, that Node 12/14 throws this error:
(node:2012) UnhandledPromiseRejectionWarning: TypeError: foundPrefix.replaceAll is not a function
at /home/runner/work/openapi-format/openapi-format/node_modules/case-anything/dist/index.umd.js:54:41
at Array.map (<anonymous>)
at splitAndPrefix (/home/runner/work/openapi-format/openapi-format/node_modules/case-anything/dist/index.umd.js:41:36)
at snakeCase (/home/runner/work/openapi-format/openapi-format/node_modules/case-anything/dist/index.umd.js:158:14)
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.