版博士V2.0程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

readme.md 3.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # camelcase
  2. > Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`
  3. Correctly handles Unicode strings.
  4. If you use this on untrusted user input, don't forget to limit the length to something reasonable.
  5. ## Install
  6. ```
  7. $ npm install camelcase
  8. ```
  9. *If you need to support Firefox < 78, stay on version 5 as version 6 uses regex features not available in Firefox < 78.*
  10. ## Usage
  11. ```js
  12. const camelCase = require('camelcase');
  13. camelCase('foo-bar');
  14. //=> 'fooBar'
  15. camelCase('foo_bar');
  16. //=> 'fooBar'
  17. camelCase('Foo-Bar');
  18. //=> 'fooBar'
  19. camelCase('розовый_пушистый_единорог');
  20. //=> 'розовыйПушистыйЕдинорог'
  21. camelCase('Foo-Bar', {pascalCase: true});
  22. //=> 'FooBar'
  23. camelCase('--foo.bar', {pascalCase: false});
  24. //=> 'fooBar'
  25. camelCase('Foo-BAR', {preserveConsecutiveUppercase: true});
  26. //=> 'fooBAR'
  27. camelCase('fooBAR', {pascalCase: true, preserveConsecutiveUppercase: true}));
  28. //=> 'FooBAR'
  29. camelCase('foo bar');
  30. //=> 'fooBar'
  31. console.log(process.argv[3]);
  32. //=> '--foo-bar'
  33. camelCase(process.argv[3]);
  34. //=> 'fooBar'
  35. camelCase(['foo', 'bar']);
  36. //=> 'fooBar'
  37. camelCase(['__foo__', '--bar'], {pascalCase: true});
  38. //=> 'FooBar'
  39. camelCase(['foo', 'BAR'], {pascalCase: true, preserveConsecutiveUppercase: true})
  40. //=> 'FooBAR'
  41. camelCase('lorem-ipsum', {locale: 'en-US'});
  42. //=> 'loremIpsum'
  43. ```
  44. ## API
  45. ### camelCase(input, options?)
  46. #### input
  47. Type: `string | string[]`
  48. String to convert to camel case.
  49. #### options
  50. Type: `object`
  51. ##### pascalCase
  52. Type: `boolean`\
  53. Default: `false`
  54. Uppercase the first character: `foo-bar` → `FooBar`
  55. ##### preserveConsecutiveUppercase
  56. Type: `boolean`\
  57. Default: `false`
  58. Preserve the consecutive uppercase characters: `foo-BAR` → `FooBAR`.
  59. ##### locale
  60. Type: `false | string | string[]`\
  61. Default: The host environment’s current locale.
  62. The locale parameter indicates the locale to be used to convert to upper/lower case according to any locale-specific case mappings. If multiple locales are given in an array, the best available locale is used.
  63. ```js
  64. const camelCase = require('camelcase');
  65. camelCase('lorem-ipsum', {locale: 'en-US'});
  66. //=> 'loremIpsum'
  67. camelCase('lorem-ipsum', {locale: 'tr-TR'});
  68. //=> 'loremİpsum'
  69. camelCase('lorem-ipsum', {locale: ['en-US', 'en-GB']});
  70. //=> 'loremIpsum'
  71. camelCase('lorem-ipsum', {locale: ['tr', 'TR', 'tr-TR']});
  72. //=> 'loremİpsum'
  73. ```
  74. Setting `locale: false` ignores the platform locale and uses the [Unicode Default Case Conversion](https://unicode-org.github.io/icu/userguide/transforms/casemappings.html#simple-single-character-case-mapping) algorithm:
  75. ```js
  76. const camelCase = require('camelcase');
  77. // On a platform with 'tr-TR'
  78. camelCase('lorem-ipsum');
  79. //=> 'loremİpsum'
  80. camelCase('lorem-ipsum', {locale: false});
  81. //=> 'loremIpsum'
  82. ```
  83. ## camelcase for enterprise
  84. Available as part of the Tidelift Subscription.
  85. The maintainers of camelcase and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-camelcase?utm_source=npm-camelcase&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
  86. ## Related
  87. - [decamelize](https://github.com/sindresorhus/decamelize) - The inverse of this module
  88. - [uppercamelcase](https://github.com/SamVerschueren/uppercamelcase) - Like this module, but to PascalCase instead of camelCase
  89. - [titleize](https://github.com/sindresorhus/titleize) - Capitalize every word in string
  90. - [humanize-string](https://github.com/sindresorhus/humanize-string) - Convert a camelized/dasherized/underscored string into a humanized one
  91. - [camelcase-keys](https://github.com/sindresorhus/camelcase-keys) - Convert object keys to camel case