index.d.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. declare namespace camelcaseKeys {
  2. interface Options {
  3. /**
  4. Recurse nested objects and objects in arrays.
  5. @default false
  6. */
  7. readonly deep?: boolean;
  8. /**
  9. Exclude keys from being camel-cased.
  10. @default []
  11. */
  12. readonly exclude?: ReadonlyArray<string | RegExp>;
  13. /**
  14. Exclude children at the given object paths in dot-notation from being camel-cased. For example, with an object like `{a: {b: '🦄'}}`, the object path to reach the unicorn is `'a.b'`.
  15. @default []
  16. @example
  17. ```
  18. camelcaseKeys({
  19. a_b: 1,
  20. a_c: {
  21. c_d: 1,
  22. c_e: {
  23. e_f: 1
  24. }
  25. }
  26. }, {
  27. deep: true,
  28. stopPaths: [
  29. 'a_c.c_e'
  30. ]
  31. }),
  32. // {
  33. // aB: 1,
  34. // aC: {
  35. // cD: 1,
  36. // cE: {
  37. // e_f: 1
  38. // }
  39. // }
  40. // }
  41. ```
  42. */
  43. readonly stopPaths?: ReadonlyArray<string>;
  44. /**
  45. Uppercase the first character as in `bye-bye` → `ByeBye`.
  46. @default false
  47. */
  48. readonly pascalCase?: boolean;
  49. }
  50. }
  51. /**
  52. Convert object keys to camel case using [`camelcase`](https://github.com/sindresorhus/camelcase).
  53. @param input - Object or array of objects to camel-case.
  54. @example
  55. ```
  56. import camelcaseKeys = require('camelcase-keys');
  57. // Convert an object
  58. camelcaseKeys({'foo-bar': true});
  59. //=> {fooBar: true}
  60. // Convert an array of objects
  61. camelcaseKeys([{'foo-bar': true}, {'bar-foo': false}]);
  62. //=> [{fooBar: true}, {barFoo: false}]
  63. camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true});
  64. //=> {fooBar: true, nested: {unicornRainbow: true}}
  65. // Convert object keys to pascal case
  66. camelcaseKeys({'foo-bar': true, nested: {unicorn_rainbow: true}}, {deep: true, pascalCase: true});
  67. //=> {FooBar: true, Nested: {UnicornRainbow: true}}
  68. import minimist = require('minimist');
  69. const argv = minimist(process.argv.slice(2));
  70. //=> {_: [], 'foo-bar': true}
  71. camelcaseKeys(argv);
  72. //=> {_: [], fooBar: true}
  73. ```
  74. */
  75. declare function camelcaseKeys<T extends ReadonlyArray<{[key: string]: any}>>(
  76. input: T,
  77. options?: camelcaseKeys.Options,
  78. ): T;
  79. declare function camelcaseKeys<T extends {[key: string]: any}>(
  80. input: T,
  81. options?: camelcaseKeys.Options,
  82. ): T;
  83. export = camelcaseKeys;