UNPKG

convert-cases

Version:

A minimal utility function library that converts camelCase to snake_case and snake_case to camelCase.

2 lines (1 loc) 1.24 kB
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).camelizeUtils={})}(this,(function(e){"use strict";var r=function(e){if("string"!=typeof e)return e;return e.replace(/[A-Z]/g,(function(e){return"_".concat(e.charAt(0).toLowerCase())}))},t=function(e){if("string"!=typeof e)return e;var r=e.replace(/^_(.*?)$/,"$1");return"".concat("_"===e.charAt(0)?"_":"").concat(r.replace(/_./g,(function(e){return e.charAt(1).toUpperCase()})))},n=function(e){if(!e||"object"!=typeof e)return e;if(e instanceof Date||e instanceof RegExp)return e;if(Array.isArray(e)){var r=[];return e.forEach((function(e){return r.push(n(e))})),r}var o={};return Object.keys(e).forEach((function(r){var a=t(r);o[a]=n(e[r])}),{}),o},o=function(e){if(!e||"object"!=typeof e)return e;if(e instanceof Date||e instanceof RegExp)return e;if(Array.isArray(e)){var t=[];return e.forEach((function(e){return t.push(o(e))})),t}var n={};return Object.keys(e).forEach((function(t){var a=r(t);n[a]=o(e[t])}),{}),n};e.camelToSnake=r,e.deeplyCamelize=n,e.deeplySnakize=o,e.snakeToCamel=t,Object.defineProperty(e,"__esModule",{value:!0})}));