切换到卡梅尔Case
简单的 JavaScript 脚本, 添加一个全面的 toCamelCase 函数改为 String.prototype。 。 。 . toCamelCase()
包括一个可选的布尔参数,用于输出PascalCase,而不是CamelCase.
这"污染" String 原型可能或不会是你的问题。 但是,它不会覆盖
String.prototype.toCamelCase 如果它已经定义.
如果性能是个问题 而你正在运行 超过数百万个字符串, 可能还有更快的模块出来 在这里。 此一取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取出取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取取出取取取取取取取取取取取取取取取取出取取取取取取取取取取取取取取取取取取出 然而,在大多数情况下,这不是一个问题.
安装
就国家预防机制而言:
npm install @dfoverdx/tocamelcase
没有国家预防机制:
-
下载
/dist/index.min.js从此寄存器中取出类似的名称tocamelcase.min.js -
将其放置在您网页可以访问的地方(例如.
/scripts/(中文(简体) ) -
添加到您的 HTML 文件
<body> <!-- ... --> <script src="/scripts/tocamelcase.min.js" type="text/javascript"></script> <!-- scripts that use .toCamelCase() --> </body>
使用量
ES5号机车
require('@dfoverdx/tocamelcase');
console.log('This is camel-case'.toCamelCase()); // outputs: 'thisIsCamelCase'
console.log('This is pascal-case'.toCamelCase(true)); // outputs 'ThisIsPascalCase'
ES6 标准
import '@dfoverdx/tocamelcase';
console.log('This is camel-case'.toCamelCase()); // outputs: 'thisIsCamelCase'
console.log('This is pascal-case'.toCamelCase(true)); // outputs 'ThisIsPascalCase'