a44c5b48dc8afce5738ccaee9efbbac9cfecde20ca08a0a60fd68d6a34dc311fa54afab53b81ae8b6f449348fde44b98da41febdab4657cea1761ca3251d49 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # 🧵 Scule
  2. [![npm version][npm-version-src]][npm-version-href]
  3. [![npm downloads][npm-downloads-src]][npm-downloads-href]
  4. [![bundle][bundle-src]][bundle-href]
  5. [![Codecov][codecov-src]][codecov-href]
  6. <!-- ![](.github/banner.svg) -->
  7. ## Install
  8. Install using npm or yarn:
  9. ```bash
  10. npm i scule
  11. ```
  12. Import:
  13. ```js
  14. // CommonJS
  15. const { pascalCase } = require("scule");
  16. // ESM
  17. import { pascalCase } from "scule";
  18. ```
  19. **Notice:** You may need to transpile package for legacy environments.
  20. ## Utils
  21. ### `pascalCase(str, opts?: { normalize })`
  22. Splits string and joins by PascalCase convention:
  23. ```ts
  24. pascalCase("foo-bar_baz");
  25. // FooBarBaz
  26. ```
  27. **Notice:** If an uppercase letter is followed by other uppercase letters (like `FooBAR`), they are preserved. You can use `{ normalize: true }` for strictly following pascalCase convention.
  28. ### `camelCase(str, opts?: { normalize })`
  29. Splits string and joins by camelCase convention:
  30. ```ts
  31. camelCase("foo-bar_baz");
  32. // fooBarBaz
  33. ```
  34. ### `kebabCase(str)`
  35. Splits string and joins by kebab-case convention:
  36. ```ts
  37. kebabCase("fooBar_Baz");
  38. // foo-bar-baz
  39. ```
  40. **Notice:** It does **not** preserve case.
  41. ### `snakeCase`
  42. Splits string and joins by snake_case convention:
  43. ```ts
  44. snakeCase("foo-barBaz");
  45. // foo_bar_baz
  46. ```
  47. ### `flatCase`
  48. Splits string and joins by flatcase convention:
  49. ```ts
  50. flatCase("foo-barBaz");
  51. // foobarbaz
  52. ```
  53. ### `trainCase(str, opts?: { normalize })`
  54. Split string and joins by Train-Case (a.k.a. HTTP-Header-Case) convention:
  55. ```ts
  56. trainCase("FooBARb");
  57. // Foo-Ba-Rb
  58. ```
  59. **Notice:** If an uppercase letter is followed by other uppercase letters (like `WWWAuthenticate`), they are preserved (=> `WWW-Authenticate`). You can use `{ normalize: true }` for strictly only having the first letter uppercased.
  60. ### `titleCase(str, opts?: { normalize })`
  61. With Title Case all words are capitalized, except for minor words.
  62. A compact regex of common minor words (such as `a`, `for`, `to`) is used to automatically keep them lower case.
  63. ```ts
  64. titleCase("this-IS-aTitle");
  65. // This is a Title
  66. ```
  67. ### `upperFirst(str)`
  68. Converts first character to upper case:
  69. ```ts
  70. upperFirst("hello world!");
  71. // Hello world!
  72. ```
  73. ### `lowerFirst(str)`
  74. Converts first character to lower case:
  75. ```ts
  76. lowerFirst("Hello world!");
  77. // hello world!
  78. ```
  79. ### `splitByCase(str, splitters?)`
  80. - Splits string by the splitters provided (default: `['-', '_', '/', '.']`)
  81. - Splits when case changes from lower to upper or upper to lower
  82. - Ignores numbers for case changes
  83. - Case is preserved in returned value
  84. - Is an irreversible function since splitters are omitted
  85. ## Development
  86. - Clone this repository
  87. - Install latest LTS version of [Node.js](https://nodejs.org/en/)
  88. - Enable [Corepack](https://github.com/nodejs/corepack) using corepack enable
  89. - Install dependencies using pnpm install
  90. - Run interactive tests using pnpm dev
  91. ## License
  92. [MIT](./LICENSE)
  93. <!-- Badges -->
  94. [npm-version-src]: https://img.shields.io/npm/v/scule?style=flat&colorA=18181B&colorB=F0DB4F
  95. [npm-version-href]: https://npmjs.com/package/scule
  96. [npm-downloads-src]: https://img.shields.io/npm/dm/scule?style=flat&colorA=18181B&colorB=F0DB4F
  97. [npm-downloads-href]: https://npmjs.com/package/scule
  98. [codecov-src]: https://img.shields.io/codecov/c/gh/unjs/scule/main?style=flat&colorA=18181B&colorB=F0DB4F
  99. [codecov-href]: https://codecov.io/gh/unjs/scule
  100. [bundle-src]: https://img.shields.io/bundlephobia/minzip/scule?style=flat&colorA=18181B&colorB=F0DB4F
  101. [bundle-href]: https://bundlephobia.com/result?p=scule