deep-case-crafter 3.5.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +5 -4
- package/readme.md +8 -8
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=/^[^.]+(?:\.[^.]+)*$/;function t(e){if("string"==typeof e)return JSON.stringify(e);if("bigint"==typeof e)return`${e}n`;if(null===e)return"null";if("object"==typeof e||"function"==typeof e)try{return Object.prototype.toString.call(e)}catch(e){return"an object"}return String(e)}function n(e){const t=e.indexOf(".");return-1===t?[e]:[e.slice(0,t),e.slice(t+1)]}const r=[];function o(e){let t,n=!1;for(const r of e)void 0===r?n=!0:(null!=t?t:t=[]).push(r);return{keepKey:n,pathsBelow:t?s(t):r,scope:void 0}}function s(e){return 1===e.length?e:[...new Set(e)].sort()}function
|
|
1
|
+
"use strict";const e=/^[^.]+(?:\.[^.]+)*$/;function t(e){if("string"==typeof e)return JSON.stringify(e);if("bigint"==typeof e)return`${e}n`;if(null===e)return"null";if("object"==typeof e||"function"==typeof e)try{return Object.prototype.toString.call(e)}catch(e){return"an object"}return String(e)}function n(e){const t=e.indexOf(".");return-1===t?[e]:[e.slice(0,t),e.slice(t+1)]}const r=[];function o(e){let t,n=!1;for(const r of e)void 0===r?n=!0:(null!=t?t:t=[]).push(r);return{keepKey:n,pathsBelow:t?s(t):r,scope:void 0}}function s(e){return 1===e.length?e:[...new Set(e)].sort()}function u(e,t){const r=[];let s;for(const t of e){const[e,o]=n(t);if("*"===e)r.push(o);else{null!=s||(s=new Map);const t=s.get(e);t?t.push(o):s.set(e,[o])}}const u=new Map;for(const[e,t]of null!=s?s:[])u.set(e,o(r.length?[...t,...r]:t));const{targetCase:c,depth:i,keepReferences:a}=t.plain.options,l={targetCase:c,depth:i,keepReferences:a,exclude:null,layouts:null},f={options:l,visitedRefs:[],named:u,other:o(r),root:t};return l.exclude=f,f}function c(e,t){const n=JSON.stringify(e);let r=t.states.get(n);return r||(r=u(e,t),t.states.set(n,r)),r}function i(n,r){if(null==n)return null;if(!Array.isArray(n))throw new TypeError(`Unsupported exclude ${t(n)}. Use an array of paths, such as ["metadata.*"].`);for(const r of n)if("string"!=typeof r||!e.test(r))throw new TypeError(`Unsupported exclude path ${t(r)}. Use non-empty keys joined with dots, such as "metadata.*".`);if(0===n.length)return null;const o={plain:{options:r,visitedRefs:[]},states:new Map};return u(s(n),o)}function a(e,t){const n="string"==typeof t?e.named.get(t):void 0;return null!=n?n:e.other}function l(e,t){var n;return null!==(n=t.scope)&&void 0!==n?n:t.scope=0===t.pathsBelow.length?e.root.plain:c(t.pathsBelow,e.root)}const f="[object Object]";function p(e){try{return Object.prototype.toString.call(e)}catch(e){return f}}function d(e,t){if(!(e instanceof Map)&&"[object Map]"!==t)return!1;try{return Map.prototype.has.call(e,void 0),!0}catch(e){return!1}}function h(e,t){if(!(e instanceof Set)&&"[object Set]"!==t)return!1;try{return Set.prototype.has.call(e,void 0),!0}catch(e){return!1}}function y(e,t,n){"__proto__"===t?Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0}):e[t]=n}function g(e,t){let n=0;for(const r of Object.getOwnPropertySymbols(e))Object.prototype.propertyIsEnumerable.call(e,r)&&(t[r]=e[r],n++);return n}function w(e,t){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++)if(n[e]!==r[e])return!1;return!0}function b(e,t,n,r){var o;if(n>200)return;const s=null!==(o=e.layouts)&&void 0!==o?o:e.layouts={done:!1,seenWidths:[],seenKeys:[],seenResults:[],nextSeen:0,fastWidths:[],fastKeys:[],fastObjects:[]};if(s.done)return;const{fastWidths:u,fastKeys:c}=s;for(let e=0;e<u.length;e++)if(u[e]===n&&c[e]===r)return;const{seenWidths:i,seenKeys:a,seenResults:l}=s;for(let e=0;e<i.length;e++)if(i[e]===n&&a[e]===r)return void(w(l[e],t)?(u.push(n),c.push(r),s.fastObjects.push({...t}),s.done=16===u.length):s.done=!0);i[s.nextSeen]=n,a[s.nextSeen]=r,l[s.nextSeen]=t,s.nextSeen=(s.nextSeen+1)%16}const v={};let C=!1;function j(e,t){const n=e.get(t);if(void 0!==n||!C)return n;let r=e.get(v);for(;void 0!==r;){const e=r.get(t);if(void 0!==e)return e;r=r.get(v)}}function k(e,t,n,r){let o=e[t];o.size>=16e6&&(C=!0,o=e[t]=new Map([[v,o]])),o.set(n,r)}function U(e){return e>=48&&e<=57}function m(e){return e>=97&&e<=122}function x(e){return e>=65&&e<=90}function O(e){if(36!==e.length)return!1;for(let t=0;t<36;t++){const n=e.charCodeAt(t);if(8===t||13===t||18===t||23===t){if(45!==n)return!1}else if(!(U(n)||n>=97&&n<=102||n>=65&&n<=70))return!1}return!0}const S="s".charCodeAt(0);function M(e,t){if(!x(e.charCodeAt(t)))return!1;const n=e.charCodeAt(t-1);if(m(n)||U(n))return!0;const r=e.charCodeAt(t+1);return!(!x(n)||!m(r))&&(r!==S||m(e.charCodeAt(t+2)))}function R(e){let t=1;for(;t<e.length&&!M(e,t);)t++;return e.slice(0,t).toLowerCase()+e.slice(t)}function A(e,t,n){return e.split(t).join(n)}function _(e,t,n){let r=n?e[0].toUpperCase():e[0],o=1,s=e.indexOf(t,1);for(;-1!==s;)r+=e.slice(o,s)+e[s+1].toUpperCase(),o=s+2,s=e.indexOf(t,o);return r+e.slice(o)}function $(e,t){const n=x(e.charCodeAt(0));switch(t){case"pascal":return n?e:e[0].toUpperCase()+e.slice(1);case"camel":return n?e[0].toLowerCase()+e.slice(1):e;case"constant":return e.toUpperCase();default:return n?e.toLowerCase():e}}function E(e,t,n){let r="",o=0;for(let n=1;n<e.length;n++)M(e,n)&&(r+=e.slice(o,n)+t,o=n);return r+=e.slice(o),n?r.toUpperCase():r.toLowerCase()}function K(e,t){const n=e.length;if(0===n)return e;let r=e.charCodeAt(0);const o=x(r);if(!o&&!m(r))return e;let s=o?1:0,u=!o,c=0,i=0,a=!1,l=r;for(let t=1;t<n;t++){if(r=e.charCodeAt(t),m(r))u=!0;else if(x(r))s++;else if(95===r)c++,95===l&&(a=!0);else if(45===r)i++,45===l&&(a=!0);else if(!U(r))return e;l=r}if(95===l||45===l)return e;if(0===c&&0===i){if(0===s||1===s&&o)return $(e,t);if(!o)switch(t){case"snake":return E(e,"_",!1);case"kebab":return E(e,"-",!1);case"pascal":return e[0].toUpperCase()+e.slice(1);case"constant":return E(e,"_",!0);default:return e}if(!u)return e;switch(t){case"snake":return E(e,"_",!1);case"kebab":return E(e,"-",!1);case"camel":return R(e);case"constant":return E(e,"_",!0);default:return e}}if(s>0||a||c>0&&i>0)return e;if(c>0)switch(t){case"camel":return _(e,"_",!1);case"pascal":return _(e,"_",!0);case"kebab":return A(e,"_","-");case"constant":return e.toUpperCase();default:return e}if(O(e))return e;switch(t){case"camel":return _(e,"-",!1);case"pascal":return _(e,"-",!0);case"snake":return A(e,"-","_");case"constant":return A(e,"-","_").toUpperCase();default:return e}}const T=new Map;let N,L={current:new Map,previous:new Map},P=0;function W(e,t){if(e.length>100)return K(e,t);if(t!==N){let e=T.get(t);e||(e={current:new Map,previous:new Map},T.set(t,e)),N=t,L=e}const n=L;let r=n.current.get(e);if(void 0!==r)return P=0,r;if(r=n.previous.get(e),void 0===r){if(r=K(e,t),++P>256&&P%8!=0)return r}else P=0;return n.current.size>=1e3&&(n.previous=n.current,n.current=new Map),n.current.set(e,r),r}const B={reason:"nesting limit reached"};function z(e,t,n=[],r=0,o=0){var s;if(null===e||"object"!=typeof e)return e;if(r>=t.depth)return e;const u=t.depth===1/0?0:r,c=t.keepReferences;if(c){const t=j(null!==(s=n[u])&&void 0!==s?s:n[u]=new Map,e);if(void 0!==t)return t}else if(o>=256)throw B;if(Array.isArray(e)){const s=[];return c&&k(n,u,e,s),J(e,s,t,n,r,o),s}const i=r+1,a=p(e);if(d(e,a)){const r=new Map;return c&&k(n,u,e,r),null===t.exclude?I(e,r,t,n,i,o):F(e,r,t.exclude,i,o),r}if(h(e,a)){const r=new Set;return c&&k(n,u,e,r),q(e,r,t,n,i,o),r}if(a===f){const r=e,s={};if(c&&k(n,u,e,s),null!==t.exclude)return D(r,s,t.exclude,i,o),s;let a=0,l="";for(const e in r)if(Object.prototype.hasOwnProperty.call(r,e)){l=W(e,t.targetCase),a++;const u=r[e];if("object"!=typeof u||null===u){y(s,l,u);continue}y(s,l,z(u,t,n,i,o+1))}return a+=g(r,s),a>=20&&(null===t.layouts||!t.layouts.done)&&b(t,s,a,l),s}return e}function J(e,t,n,r,o,s){for(const u of e)"object"==typeof u&&null!==u?t.push(z(u,n,r,o,s+1)):t.push(u)}function I(e,t,n,r,o,s){for(const[u,c]of e)t.set("string"==typeof u?K(u,n.targetCase):u,z(c,n,r,o,s+1))}function q(e,t,n,r,o,s){for(const u of e)t.add(z(u,n,r,o,s+1))}function D(e,t,n,r,o){let s=0,u="";for(const c in e)if(Object.prototype.hasOwnProperty.call(e,c)){const i=a(n,c),f=l(n,i);u=i.keepKey?c:W(c,n.options.targetCase),s++,y(t,u,z(e[c],f.options,f.visitedRefs,r,o+1))}s+=g(e,t),s>=20&&b(n.options,t,s,u)}function F(e,t,n,r,o){for(const[s,u]of e){const e=a(n,s),c=l(n,e);t.set("string"!=typeof s||e.keepKey?s:K(s,n.options.targetCase),z(u,c.options,c.visitedRefs,r,o+1))}}const G=["camel","snake","pascal","kebab","constant"];function H(e){return G.includes(e)}function Q(e){if("string"!=typeof e)return;const n=t(e);throw new TypeError(H(e)?`Unsupported options ${n}. Use an options object: { targetCase: ${n} }.`:`Unsupported options ${n}. Use an options object, such as { targetCase: "snake" }. To pass the function as a callback, wrap it so that it gets only its first argument.`)}function V(e){const n=e||"camel";if(!H(n))throw new TypeError(`Unsupported targetCase ${t(n)}. Use one of: ${G.join(", ")}.`);return n}function X(e,t,n){const r=void 0===n?null:i(n,t);return null===r?z(e,t):z(e,r.options,r.visitedRefs)}exports.transform=function(e,n){var r,o;Q(n);const s=null==n?void 0:n.targetCase,u=null!==(r=null==n?void 0:n.depth)&&void 0!==r?r:1/0,c=V(s);if("number"!=typeof u||Number.isNaN(u))throw new TypeError(`Unsupported depth ${t(u)}. Use a number, or omit depth to transform every level.`);const i=null==n?void 0:n.exclude,a=null===(o=null==n?void 0:n.keepReferences)||void 0===o||o;if("boolean"!=typeof a)throw new TypeError(`Unsupported keepReferences ${t(a)}. Use true or false.`);if(!a)try{return X(e,{targetCase:c,depth:u,keepReferences:a,exclude:null,layouts:null},i)}catch(e){if(e!==B)throw e}return X(e,{targetCase:c,depth:u,keepReferences:!0,exclude:null,layouts:null},i)},exports.transformKey=function(e,n){if("string"!=typeof e)throw new TypeError(`Unsupported key ${t(e)}. Use a string.`);return Q(n),K(e,V(null==n?void 0:n.targetCase))};
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=/^[^.]+(?:\.[^.]+)*$/;function t(e){if("string"==typeof e)return JSON.stringify(e);if("bigint"==typeof e)return`${e}n`;if(null===e)return"null";if("object"==typeof e||"function"==typeof e)try{return Object.prototype.toString.call(e)}catch(e){return"an object"}return String(e)}function n(e){const t=e.indexOf(".");return-1===t?[e]:[e.slice(0,t),e.slice(t+1)]}const r=[];function o(e){let t,n=!1;for(const r of e)void 0===r?n=!0:(null!=t?t:t=[]).push(r);return{keepKey:n,pathsBelow:t?s(t):r,scope:void 0}}function s(e){return 1===e.length?e:[...new Set(e)].sort()}function
|
|
1
|
+
const e=/^[^.]+(?:\.[^.]+)*$/;function t(e){if("string"==typeof e)return JSON.stringify(e);if("bigint"==typeof e)return`${e}n`;if(null===e)return"null";if("object"==typeof e||"function"==typeof e)try{return Object.prototype.toString.call(e)}catch(e){return"an object"}return String(e)}function n(e){const t=e.indexOf(".");return-1===t?[e]:[e.slice(0,t),e.slice(t+1)]}const r=[];function o(e){let t,n=!1;for(const r of e)void 0===r?n=!0:(null!=t?t:t=[]).push(r);return{keepKey:n,pathsBelow:t?s(t):r,scope:void 0}}function s(e){return 1===e.length?e:[...new Set(e)].sort()}function u(e,t){const r=[];let s;for(const t of e){const[e,o]=n(t);if("*"===e)r.push(o);else{null!=s||(s=new Map);const t=s.get(e);t?t.push(o):s.set(e,[o])}}const u=new Map;for(const[e,t]of null!=s?s:[])u.set(e,o(r.length?[...t,...r]:t));const{targetCase:c,depth:i,keepReferences:a}=t.plain.options,l={targetCase:c,depth:i,keepReferences:a,exclude:null,layouts:null},f={options:l,visitedRefs:[],named:u,other:o(r),root:t};return l.exclude=f,f}function c(e,t){const n=JSON.stringify(e);let r=t.states.get(n);return r||(r=u(e,t),t.states.set(n,r)),r}function i(n,r){if(null==n)return null;if(!Array.isArray(n))throw new TypeError(`Unsupported exclude ${t(n)}. Use an array of paths, such as ["metadata.*"].`);for(const r of n)if("string"!=typeof r||!e.test(r))throw new TypeError(`Unsupported exclude path ${t(r)}. Use non-empty keys joined with dots, such as "metadata.*".`);if(0===n.length)return null;const o={plain:{options:r,visitedRefs:[]},states:new Map};return u(s(n),o)}function a(e,t){const n="string"==typeof t?e.named.get(t):void 0;return null!=n?n:e.other}function l(e,t){var n;return null!==(n=t.scope)&&void 0!==n?n:t.scope=0===t.pathsBelow.length?e.root.plain:c(t.pathsBelow,e.root)}const f="[object Object]";function p(e){try{return Object.prototype.toString.call(e)}catch(e){return f}}function d(e,t){if(!(e instanceof Map)&&"[object Map]"!==t)return!1;try{return Map.prototype.has.call(e,void 0),!0}catch(e){return!1}}function h(e,t){if(!(e instanceof Set)&&"[object Set]"!==t)return!1;try{return Set.prototype.has.call(e,void 0),!0}catch(e){return!1}}function y(e,t,n){"__proto__"===t?Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0}):e[t]=n}function g(e,t){let n=0;for(const r of Object.getOwnPropertySymbols(e))Object.prototype.propertyIsEnumerable.call(e,r)&&(t[r]=e[r],n++);return n}function w(e,t){const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++)if(n[e]!==r[e])return!1;return!0}function b(e,t,n,r){var o;if(n>200)return;const s=null!==(o=e.layouts)&&void 0!==o?o:e.layouts={done:!1,seenWidths:[],seenKeys:[],seenResults:[],nextSeen:0,fastWidths:[],fastKeys:[],fastObjects:[]};if(s.done)return;const{fastWidths:u,fastKeys:c}=s;for(let e=0;e<u.length;e++)if(u[e]===n&&c[e]===r)return;const{seenWidths:i,seenKeys:a,seenResults:l}=s;for(let e=0;e<i.length;e++)if(i[e]===n&&a[e]===r)return void(w(l[e],t)?(u.push(n),c.push(r),s.fastObjects.push({...t}),s.done=16===u.length):s.done=!0);i[s.nextSeen]=n,a[s.nextSeen]=r,l[s.nextSeen]=t,s.nextSeen=(s.nextSeen+1)%16}const v={};let C=!1;function j(e,t){const n=e.get(t);if(void 0!==n||!C)return n;let r=e.get(v);for(;void 0!==r;){const e=r.get(t);if(void 0!==e)return e;r=r.get(v)}}function k(e,t,n,r){let o=e[t];o.size>=16e6&&(C=!0,o=e[t]=new Map([[v,o]])),o.set(n,r)}function U(e){return e>=48&&e<=57}function m(e){return e>=97&&e<=122}function x(e){return e>=65&&e<=90}function O(e){if(36!==e.length)return!1;for(let t=0;t<36;t++){const n=e.charCodeAt(t);if(8===t||13===t||18===t||23===t){if(45!==n)return!1}else if(!(U(n)||n>=97&&n<=102||n>=65&&n<=70))return!1}return!0}const S="s".charCodeAt(0);function M(e,t){if(!x(e.charCodeAt(t)))return!1;const n=e.charCodeAt(t-1);if(m(n)||U(n))return!0;const r=e.charCodeAt(t+1);return!(!x(n)||!m(r))&&(r!==S||m(e.charCodeAt(t+2)))}function R(e){let t=1;for(;t<e.length&&!M(e,t);)t++;return e.slice(0,t).toLowerCase()+e.slice(t)}function A(e,t,n){return e.split(t).join(n)}function _(e,t,n){let r=n?e[0].toUpperCase():e[0],o=1,s=e.indexOf(t,1);for(;-1!==s;)r+=e.slice(o,s)+e[s+1].toUpperCase(),o=s+2,s=e.indexOf(t,o);return r+e.slice(o)}function $(e,t){const n=x(e.charCodeAt(0));switch(t){case"pascal":return n?e:e[0].toUpperCase()+e.slice(1);case"camel":return n?e[0].toLowerCase()+e.slice(1):e;case"constant":return e.toUpperCase();default:return n?e.toLowerCase():e}}function E(e,t,n){let r="",o=0;for(let n=1;n<e.length;n++)M(e,n)&&(r+=e.slice(o,n)+t,o=n);return r+=e.slice(o),n?r.toUpperCase():r.toLowerCase()}function T(e,t){const n=e.length;if(0===n)return e;let r=e.charCodeAt(0);const o=x(r);if(!o&&!m(r))return e;let s=o?1:0,u=!o,c=0,i=0,a=!1,l=r;for(let t=1;t<n;t++){if(r=e.charCodeAt(t),m(r))u=!0;else if(x(r))s++;else if(95===r)c++,95===l&&(a=!0);else if(45===r)i++,45===l&&(a=!0);else if(!U(r))return e;l=r}if(95===l||45===l)return e;if(0===c&&0===i){if(0===s||1===s&&o)return $(e,t);if(!o)switch(t){case"snake":return E(e,"_",!1);case"kebab":return E(e,"-",!1);case"pascal":return e[0].toUpperCase()+e.slice(1);case"constant":return E(e,"_",!0);default:return e}if(!u)return e;switch(t){case"snake":return E(e,"_",!1);case"kebab":return E(e,"-",!1);case"camel":return R(e);case"constant":return E(e,"_",!0);default:return e}}if(s>0||a||c>0&&i>0)return e;if(c>0)switch(t){case"camel":return _(e,"_",!1);case"pascal":return _(e,"_",!0);case"kebab":return A(e,"_","-");case"constant":return e.toUpperCase();default:return e}if(O(e))return e;switch(t){case"camel":return _(e,"-",!1);case"pascal":return _(e,"-",!0);case"snake":return A(e,"-","_");case"constant":return A(e,"-","_").toUpperCase();default:return e}}const K=new Map;let N,L={current:new Map,previous:new Map},P=0;function W(e,t){if(e.length>100)return T(e,t);if(t!==N){let e=K.get(t);e||(e={current:new Map,previous:new Map},K.set(t,e)),N=t,L=e}const n=L;let r=n.current.get(e);if(void 0!==r)return P=0,r;if(r=n.previous.get(e),void 0===r){if(r=T(e,t),++P>256&&P%8!=0)return r}else P=0;return n.current.size>=1e3&&(n.previous=n.current,n.current=new Map),n.current.set(e,r),r}const B={reason:"nesting limit reached"};function z(e,t,n=[],r=0,o=0){var s;if(null===e||"object"!=typeof e)return e;if(r>=t.depth)return e;const u=t.depth===1/0?0:r,c=t.keepReferences;if(c){const t=j(null!==(s=n[u])&&void 0!==s?s:n[u]=new Map,e);if(void 0!==t)return t}else if(o>=256)throw B;if(Array.isArray(e)){const s=[];return c&&k(n,u,e,s),J(e,s,t,n,r,o),s}const i=r+1,a=p(e);if(d(e,a)){const r=new Map;return c&&k(n,u,e,r),null===t.exclude?I(e,r,t,n,i,o):F(e,r,t.exclude,i,o),r}if(h(e,a)){const r=new Set;return c&&k(n,u,e,r),q(e,r,t,n,i,o),r}if(a===f){const r=e,s={};if(c&&k(n,u,e,s),null!==t.exclude)return D(r,s,t.exclude,i,o),s;let a=0,l="";for(const e in r)if(Object.prototype.hasOwnProperty.call(r,e)){l=W(e,t.targetCase),a++;const u=r[e];if("object"!=typeof u||null===u){y(s,l,u);continue}y(s,l,z(u,t,n,i,o+1))}return a+=g(r,s),a>=20&&(null===t.layouts||!t.layouts.done)&&b(t,s,a,l),s}return e}function J(e,t,n,r,o,s){for(const u of e)"object"==typeof u&&null!==u?t.push(z(u,n,r,o,s+1)):t.push(u)}function I(e,t,n,r,o,s){for(const[u,c]of e)t.set("string"==typeof u?T(u,n.targetCase):u,z(c,n,r,o,s+1))}function q(e,t,n,r,o,s){for(const u of e)t.add(z(u,n,r,o,s+1))}function D(e,t,n,r,o){let s=0,u="";for(const c in e)if(Object.prototype.hasOwnProperty.call(e,c)){const i=a(n,c),f=l(n,i);u=i.keepKey?c:W(c,n.options.targetCase),s++,y(t,u,z(e[c],f.options,f.visitedRefs,r,o+1))}s+=g(e,t),s>=20&&b(n.options,t,s,u)}function F(e,t,n,r,o){for(const[s,u]of e){const e=a(n,s),c=l(n,e);t.set("string"!=typeof s||e.keepKey?s:T(s,n.options.targetCase),z(u,c.options,c.visitedRefs,r,o+1))}}const G=["camel","snake","pascal","kebab","constant"];function H(e){return G.includes(e)}function Q(e){if("string"!=typeof e)return;const n=t(e);throw new TypeError(H(e)?`Unsupported options ${n}. Use an options object: { targetCase: ${n} }.`:`Unsupported options ${n}. Use an options object, such as { targetCase: "snake" }. To pass the function as a callback, wrap it so that it gets only its first argument.`)}function V(e){const n=e||"camel";if(!H(n))throw new TypeError(`Unsupported targetCase ${t(n)}. Use one of: ${G.join(", ")}.`);return n}function X(e,n){var r,o;Q(n);const s=null==n?void 0:n.targetCase,u=null!==(r=null==n?void 0:n.depth)&&void 0!==r?r:1/0,c=V(s);if("number"!=typeof u||Number.isNaN(u))throw new TypeError(`Unsupported depth ${t(u)}. Use a number, or omit depth to transform every level.`);const i=null==n?void 0:n.exclude,a=null===(o=null==n?void 0:n.keepReferences)||void 0===o||o;if("boolean"!=typeof a)throw new TypeError(`Unsupported keepReferences ${t(a)}. Use true or false.`);if(!a)try{return Y(e,{targetCase:c,depth:u,keepReferences:a,exclude:null,layouts:null},i)}catch(e){if(e!==B)throw e}return Y(e,{targetCase:c,depth:u,keepReferences:!0,exclude:null,layouts:null},i)}function Y(e,t,n){const r=void 0===n?null:i(n,t);return null===r?z(e,t):z(e,r.options,r.visitedRefs)}function Z(e,n){if("string"!=typeof e)throw new TypeError(`Unsupported key ${t(e)}. Use a string.`);return Q(n),T(e,V(null==n?void 0:n.targetCase))}export{X as transform,Z as transformKey};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deep-case-crafter",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "Convert object keys between camelCase and snake_case, deeply, with exact TypeScript types",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -66,13 +66,14 @@
|
|
|
66
66
|
"test-coverage": "npm test -- --coverage",
|
|
67
67
|
"test:types": "tsc --noEmit",
|
|
68
68
|
"tsc": "tsc --noEmit",
|
|
69
|
+
"test:dist-objects": "node --allow-natives-syntax dist-tests/fastObjects.mjs",
|
|
69
70
|
"test:dist-types": "tsc -p dist-type-tests && tsc -p dist-type-tests/tsconfig.declarations.json && node dist-type-tests/checkDeclarations.mjs && tsc -p dist-type-tests/tsconfig.consumer.json && tsc -p dist-type-tests/tsconfig.loose.json && tsc -p dist-type-tests/tsconfig.exact.json",
|
|
70
71
|
"lint": "eslint --ext .js,.jsx,.ts,.tsx src/ --max-warnings=0 --no-cache",
|
|
71
72
|
"lint:fix": "eslint --ext .js,.jsx,.ts,.tsx src/ --fix --max-warnings=0 --no-cache",
|
|
72
|
-
"format": "prettier --write src dist-type-tests benchmark .github readme.md CHANGELOG.md SECURITY.md",
|
|
73
|
-
"format:check": "prettier --check src dist-type-tests benchmark .github readme.md CHANGELOG.md SECURITY.md",
|
|
73
|
+
"format": "prettier --write src dist-type-tests dist-tests benchmark .github readme.md CHANGELOG.md SECURITY.md",
|
|
74
|
+
"format:check": "prettier --check src dist-type-tests dist-tests benchmark .github readme.md CHANGELOG.md SECURITY.md",
|
|
74
75
|
"benchmark": "tsx benchmark/*.benchmark.ts",
|
|
75
|
-
"check": "npm run lint && npm run format:check && npm run test:types && npm run test-coverage && npm run build && npm run test:dist-types"
|
|
76
|
+
"check": "npm run lint && npm run format:check && npm run test:types && npm run test-coverage && npm run build && npm run test:dist-types && npm run test:dist-objects"
|
|
76
77
|
},
|
|
77
78
|
"devDependencies": {
|
|
78
79
|
"@eslint/js": "10.0.1",
|
package/readme.md
CHANGED
|
@@ -230,7 +230,7 @@ Where the others are better or different:
|
|
|
230
230
|
|
|
231
231
|
- **Bundle size**: bundled and minified with esbuild, ts-case-convert's `objectToCamel`
|
|
232
232
|
and `objectToSnake` take about 1.1 KB gzipped, deep-case-crafter's `transform` about
|
|
233
|
-
2
|
|
233
|
+
3.2 KB.
|
|
234
234
|
- **CONSTANT_CASE input**: camelcase-keys, snakecase-keys and es-toolkit also read
|
|
235
235
|
SCREAMING_SNAKE_CASE keys, so `USER_ID` becomes `userId` or `user_id`.
|
|
236
236
|
deep-case-crafter converts to CONSTANT_CASE, but leaves keys such as `USER_ID` and
|
|
@@ -530,16 +530,16 @@ Worth knowing:
|
|
|
530
530
|
Measured with Node 24 on an Apple M4 Pro, with Node's default stack and memory sizes:
|
|
531
531
|
|
|
532
532
|
- **Nesting depth.** The conversion is recursive. Depending on the shape, the first call
|
|
533
|
-
in a process converts 1,300 to 2,
|
|
533
|
+
in a process converts 1,300 to 2,400 levels of nesting (nested Maps the fewest, nested
|
|
534
534
|
objects the most); deeper data throws a `RangeError`. Later calls can go deeper, up to
|
|
535
|
-
about
|
|
535
|
+
about 4,800 levels, depending on the data converted before. API data nests far less,
|
|
536
536
|
but untrusted input can nest deeper (`JSON.parse` accepts millions of levels), so catch
|
|
537
537
|
the error where such input is converted.
|
|
538
538
|
- **Size.** There is no fixed limit on keys, objects or array items. The result is a full
|
|
539
539
|
copy, so the input and the result must both fit in memory: converting 1 million records
|
|
540
|
-
|
|
541
|
-
`keepReferences: false`. When memory runs out,
|
|
542
|
-
caught.
|
|
540
|
+
of 30 keys (260 MB in memory, as `JSON.parse` returns them) took 0.7 seconds and needed
|
|
541
|
+
420 MB more at its peak, and 370 MB with `keepReferences: false`. When memory runs out,
|
|
542
|
+
Node ends the process, which cannot be caught.
|
|
543
543
|
- **Long keys.** Conversion time grows linearly with a key's length: about 20 ms for a key
|
|
544
544
|
of a million characters.
|
|
545
545
|
|
|
@@ -570,8 +570,8 @@ in the changelog.
|
|
|
570
570
|
1. Fork the repository.
|
|
571
571
|
2. Create a new branch (`feature/my-feature`).
|
|
572
572
|
3. Commit your changes.
|
|
573
|
-
4. Run `npm run check` (lint, formatting, types, tests with coverage, build
|
|
574
|
-
published types).
|
|
573
|
+
4. Run `npm run check` (lint, formatting, types, tests with coverage, build, the
|
|
574
|
+
published types and the fast objects of the build).
|
|
575
575
|
5. Submit a pull request.
|
|
576
576
|
|
|
577
577
|
---
|