JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 119277
  • Score
    100M100P100Q166981F
  • License Apache-2.0

Typescript type-preserving conversion of objects between camelCase and snake_case

Package Exports

  • ts-case-convert

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ts-case-convert) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ts-case-convert

Version Documentation Maintenance License: Apache--2.0

ts-case-convert converts objects between camelCase and snake_case while preserving Typescript type information, code completion, and type validation. See tests for detailed conversion tests, including

Usage

const camel = objectToCamel({
  hello_world: 'helloWorld',
  a_number: 5,
  an_array: [1, 2, 4],
  null_object: null,
  undef_object: undefined,
  an_array_of_objects: [{ a_b: 'ab', a_c: 'ac' }],
  an_object: {
    a_1: 'a1',
    a_2: 'a2',
  },
});

type CheckCamel = typeof camel.anArrayOfObjects[0]['aB']; // -> 'string'
const ab: CheckCamel = camel.anArrayOfObjects[0]['aB']; // -> valid
console.log(camel.anArrayOfObjects.aB); // -> 'ab'

const snake = objectToSnake({
  helloWorld: 'helloWorld',
  aNumber: 5,
  anArray: [1, 2, 4],
  nullObject: null,
  undefObject: undefined,
  anArrayOfObjects: [{ aB: 'ab', aC: 'ac' }],
  anObject: {
    A1: 'a_1',
    A2: 'a_2',
  },
});

type CheckSnake = typeof snake.anArrayOfObjects[0]['a_b']; // -> 'string'
const ab: CheckSnake = snake.anArrayOfObjects[0]['a_b']; // -> valid
console.log(snake.anArrayOfObjects.a_b); // -> 'ab'

Run tests

yarn run test

Documentation

See tests.

📝 License

Copyright © 2021 Ross Williams.
This project is Apache--2.0 licensed.