Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

xcase

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xcase - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

algorithms.js

194

dist/xcase.js
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.xcase = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({"/es5/index.js":[function(require,module,exports){
'use strict';
var algorithms = {};
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
function isLower(char) {

@@ -33,3 +37,3 @@ return char >= 0x61 /* 'a' */ && char <= 0x7a /* 'z' */;

algorithms.camelize = function (str, separator) {
function camelize$1(str, separator) {
var firstChar = str.charCodeAt(0);

@@ -63,5 +67,5 @@ if (isDigit(firstChar) || isUpper(firstChar) || firstChar == separator) {

return changed ? String.fromCharCode.apply(undefined, out) : str;
};
}
algorithms.decamelize = function (str, separator) {
function decamelize$1(str, separator) {
var firstChar = str.charCodeAt(0);

@@ -85,5 +89,5 @@ if (!isLower(firstChar)) {

return changed ? String.fromCharCode.apply(undefined, out) : str;
};
}
algorithms.pascalize = function (str, separator) {
function pascalize$1(str, separator) {
var firstChar = str.charCodeAt(0);

@@ -113,5 +117,5 @@ if (isDigit(firstChar) || firstChar == separator) {

return changed ? String.fromCharCode.apply(undefined, out) : str;
};
}
algorithms.depascalize = function (str, separator) {
function depascalize$1(str, separator) {
var firstChar = str.charCodeAt(0);

@@ -137,97 +141,103 @@ if (!isUpper(firstChar)) {

return changed ? String.fromCharCode.apply(undefined, out) : str;
};
}
module.exports = require('./main')(algorithms);
},{"./main":1}],1:[function(require,module,exports){
'use strict';
function shouldProcessValue(value) {
return value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) == 'object' && !(value instanceof Date) && !(value instanceof Function);
}
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
module.exports = function (algorithms) {
function shouldProcessValue(value) {
return value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) == 'object' && !(value instanceof Date) && !(value instanceof Function);
function processKeys(obj, fun, opts) {
var obj2 = void 0;
if (obj instanceof Array) {
obj2 = [];
} else {
if (typeof obj.prototype !== 'undefined') {
// return non-plain object unchanged
return obj;
}
obj2 = {};
}
function processKeys(obj, fun, opts) {
var obj2 = void 0;
if (obj instanceof Array) {
obj2 = [];
for (var key in obj) {
var value = obj[key];
if (typeof key === 'string') key = fun(key, opts && opts.separator);
if (shouldProcessValue(value)) {
obj2[key] = processKeys(value, fun, opts);
} else {
if (typeof obj.prototype !== 'undefined') {
// return non-plain object unchanged
return obj;
}
obj2 = {};
obj2[key] = value;
}
for (var key in obj) {
var value = obj[key];
if (typeof key === 'string') key = fun(key, opts && opts.separator);
if (shouldProcessValue(value)) {
obj2[key] = processKeys(value, fun, opts);
} else {
obj2[key] = value;
}
}
return obj2;
}
return obj2;
}
function processKeysInPlace(obj, fun, opts) {
var keys = Object.keys(obj);
for (var idx = 0; idx < keys.length; ++idx) {
var key = keys[idx];
var value = obj[key];
var newKey = fun(key, opts && opts.separator);
if (newKey !== key) {
delete obj[key];
}
if (shouldProcessValue(value)) {
obj[newKey] = processKeys(value, fun, opts);
} else {
obj[newKey] = value;
}
function processKeysInPlace(obj, fun, opts) {
var keys = Object.keys(obj);
for (var idx = 0; idx < keys.length; ++idx) {
var key = keys[idx];
var value = obj[key];
var newKey = fun(key, opts && opts.separator);
if (newKey !== key) {
delete obj[key];
}
return obj;
if (shouldProcessValue(value)) {
obj[newKey] = processKeys(value, fun, opts);
} else {
obj[newKey] = value;
}
}
return obj;
}
var iface = {
camelize: function camelize(str, separator) {
return algorithms.camelize(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
},
decamelize: function decamelize(str, separator) {
return algorithms.decamelize(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
},
pascalize: function pascalize(str, separator) {
return algorithms.pascalize(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
},
depascalize: function depascalize(str, separator) {
return algorithms.depascalize(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
},
camelizeKeys: function camelizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, iface.camelize, opts);
return processKeys(obj, iface.camelize, opts);
},
decamelizeKeys: function decamelizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, iface.decamelize, opts);
return processKeys(obj, iface.decamelize, opts);
},
pascalizeKeys: function pascalizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, iface.pascalize, opts);
return processKeys(obj, iface.pascalize, opts);
},
depascalizeKeys: function depascalizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, iface.depascalize, opts);
return processKeys(obj, iface.depascalize, opts);
}
};
return iface;
};
function camelize$$1(str, separator) {
return camelize$1(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
}
function decamelize$$1(str, separator) {
return decamelize$1(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
}
function pascalize$$1(str, separator) {
return pascalize$1(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
}
function depascalize$$1(str, separator) {
return depascalize$1(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
}
function camelizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, camelize$$1, opts);
return processKeys(obj, camelize$$1, opts);
}
function decamelizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, decamelize$$1, opts);
return processKeys(obj, decamelize$$1, opts);
}
function pascalizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, pascalize$$1, opts);
return processKeys(obj, pascalize$$1, opts);
}
function depascalizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, depascalize$$1, opts);
return processKeys(obj, depascalize$$1, opts);
}
exports.camelize = camelize$$1;
exports.decamelize = decamelize$$1;
exports.pascalize = pascalize$$1;
exports.depascalize = depascalize$$1;
exports.camelizeKeys = camelizeKeys;
exports.decamelizeKeys = decamelizeKeys;
exports.pascalizeKeys = pascalizeKeys;
exports.depascalizeKeys = depascalizeKeys;
},{}]},{},[])("/es5/index.js")
});

@@ -1,1 +0,1 @@

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.xcase=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({"/es5/index.js":[function(require,module,exports){"use strict";var algorithms={};function isLower(char){return char>=97&&char<=122}function isUpper(char){return char>=65&&char<=90}function isDigit(char){return char>=48&&char<=57}function toUpper(char){return char-32}function toUpperSafe(char){if(isLower(char)){return char-32}return char}function toLower(char){return char+32}algorithms.camelize=function(str,separator){var firstChar=str.charCodeAt(0);if(isDigit(firstChar)||isUpper(firstChar)||firstChar==separator){return str}var out=[];var changed=false;if(isUpper(firstChar)){changed=true;out.push(toLower(firstChar))}else{out.push(firstChar)}var length=str.length;for(var i=1;i<length;++i){var c=str.charCodeAt(i);if(c===separator){changed=true;c=str.charCodeAt(++i);if(isNaN(c)){return str}out.push(toUpperSafe(c))}else{out.push(c)}}return changed?String.fromCharCode.apply(undefined,out):str};algorithms.decamelize=function(str,separator){var firstChar=str.charCodeAt(0);if(!isLower(firstChar)){return str}var length=str.length;var changed=false;var out=[];for(var i=0;i<length;++i){var c=str.charCodeAt(i);if(isUpper(c)){out.push(separator);out.push(toLower(c));changed=true}else{out.push(c)}}return changed?String.fromCharCode.apply(undefined,out):str};algorithms.pascalize=function(str,separator){var firstChar=str.charCodeAt(0);if(isDigit(firstChar)||firstChar==separator){return str}var length=str.length;var changed=false;var out=[];for(var i=0;i<length;++i){var c=str.charCodeAt(i);if(c===separator){changed=true;c=str.charCodeAt(++i);if(isNaN(c)){return str}out.push(toUpperSafe(c))}else if(i===0&&isLower(c)){changed=true;out.push(toUpper(c))}else{out.push(c)}}return changed?String.fromCharCode.apply(undefined,out):str};algorithms.depascalize=function(str,separator){var firstChar=str.charCodeAt(0);if(!isUpper(firstChar)){return str}var length=str.length;var changed=false;var out=[];for(var i=0;i<length;++i){var c=str.charCodeAt(i);if(isUpper(c)){if(i>0){out.push(separator)}out.push(toLower(c));changed=true}else{out.push(c)}}return changed?String.fromCharCode.apply(undefined,out):str};module.exports=require("./main")(algorithms)},{"./main":1}],1:[function(require,module,exports){"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};module.exports=function(algorithms){function shouldProcessValue(value){return value&&(typeof value==="undefined"?"undefined":_typeof(value))=="object"&&!(value instanceof Date)&&!(value instanceof Function)}function processKeys(obj,fun,opts){var obj2=void 0;if(obj instanceof Array){obj2=[]}else{if(typeof obj.prototype!=="undefined"){return obj}obj2={}}for(var key in obj){var value=obj[key];if(typeof key==="string")key=fun(key,opts&&opts.separator);if(shouldProcessValue(value)){obj2[key]=processKeys(value,fun,opts)}else{obj2[key]=value}}return obj2}function processKeysInPlace(obj,fun,opts){var keys=Object.keys(obj);for(var idx=0;idx<keys.length;++idx){var key=keys[idx];var value=obj[key];var newKey=fun(key,opts&&opts.separator);if(newKey!==key){delete obj[key]}if(shouldProcessValue(value)){obj[newKey]=processKeys(value,fun,opts)}else{obj[newKey]=value}}return obj}var iface={camelize:function camelize(str,separator){return algorithms.camelize(str,separator&&separator.charCodeAt(0)||95)},decamelize:function decamelize(str,separator){return algorithms.decamelize(str,separator&&separator.charCodeAt(0)||95)},pascalize:function pascalize(str,separator){return algorithms.pascalize(str,separator&&separator.charCodeAt(0)||95)},depascalize:function depascalize(str,separator){return algorithms.depascalize(str,separator&&separator.charCodeAt(0)||95)},camelizeKeys:function camelizeKeys(obj,opts){opts=opts||{};if(!shouldProcessValue(obj))return obj;if(opts.inPlace)return processKeysInPlace(obj,iface.camelize,opts);return processKeys(obj,iface.camelize,opts)},decamelizeKeys:function decamelizeKeys(obj,opts){opts=opts||{};if(!shouldProcessValue(obj))return obj;if(opts.inPlace)return processKeysInPlace(obj,iface.decamelize,opts);return processKeys(obj,iface.decamelize,opts)},pascalizeKeys:function pascalizeKeys(obj,opts){opts=opts||{};if(!shouldProcessValue(obj))return obj;if(opts.inPlace)return processKeysInPlace(obj,iface.pascalize,opts);return processKeys(obj,iface.pascalize,opts)},depascalizeKeys:function depascalizeKeys(obj,opts){opts=opts||{};if(!shouldProcessValue(obj))return obj;if(opts.inPlace)return processKeysInPlace(obj,iface.depascalize,opts);return processKeys(obj,iface.depascalize,opts)}};return iface}},{}]},{},[])("/es5/index.js")});
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.xcase=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({"/es5/index.js":[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};function isLower(char){return char>=97&&char<=122}function isUpper(char){return char>=65&&char<=90}function isDigit(char){return char>=48&&char<=57}function toUpper(char){return char-32}function toUpperSafe(char){if(isLower(char)){return char-32}return char}function toLower(char){return char+32}function camelize$1(str,separator){var firstChar=str.charCodeAt(0);if(isDigit(firstChar)||isUpper(firstChar)||firstChar==separator){return str}var out=[];var changed=false;if(isUpper(firstChar)){changed=true;out.push(toLower(firstChar))}else{out.push(firstChar)}var length=str.length;for(var i=1;i<length;++i){var c=str.charCodeAt(i);if(c===separator){changed=true;c=str.charCodeAt(++i);if(isNaN(c)){return str}out.push(toUpperSafe(c))}else{out.push(c)}}return changed?String.fromCharCode.apply(undefined,out):str}function decamelize$1(str,separator){var firstChar=str.charCodeAt(0);if(!isLower(firstChar)){return str}var length=str.length;var changed=false;var out=[];for(var i=0;i<length;++i){var c=str.charCodeAt(i);if(isUpper(c)){out.push(separator);out.push(toLower(c));changed=true}else{out.push(c)}}return changed?String.fromCharCode.apply(undefined,out):str}function pascalize$1(str,separator){var firstChar=str.charCodeAt(0);if(isDigit(firstChar)||firstChar==separator){return str}var length=str.length;var changed=false;var out=[];for(var i=0;i<length;++i){var c=str.charCodeAt(i);if(c===separator){changed=true;c=str.charCodeAt(++i);if(isNaN(c)){return str}out.push(toUpperSafe(c))}else if(i===0&&isLower(c)){changed=true;out.push(toUpper(c))}else{out.push(c)}}return changed?String.fromCharCode.apply(undefined,out):str}function depascalize$1(str,separator){var firstChar=str.charCodeAt(0);if(!isUpper(firstChar)){return str}var length=str.length;var changed=false;var out=[];for(var i=0;i<length;++i){var c=str.charCodeAt(i);if(isUpper(c)){if(i>0){out.push(separator)}out.push(toLower(c));changed=true}else{out.push(c)}}return changed?String.fromCharCode.apply(undefined,out):str}function shouldProcessValue(value){return value&&(typeof value==="undefined"?"undefined":_typeof(value))=="object"&&!(value instanceof Date)&&!(value instanceof Function)}function processKeys(obj,fun,opts){var obj2=void 0;if(obj instanceof Array){obj2=[]}else{if(typeof obj.prototype!=="undefined"){return obj}obj2={}}for(var key in obj){var value=obj[key];if(typeof key==="string")key=fun(key,opts&&opts.separator);if(shouldProcessValue(value)){obj2[key]=processKeys(value,fun,opts)}else{obj2[key]=value}}return obj2}function processKeysInPlace(obj,fun,opts){var keys=Object.keys(obj);for(var idx=0;idx<keys.length;++idx){var key=keys[idx];var value=obj[key];var newKey=fun(key,opts&&opts.separator);if(newKey!==key){delete obj[key]}if(shouldProcessValue(value)){obj[newKey]=processKeys(value,fun,opts)}else{obj[newKey]=value}}return obj}function camelize$$1(str,separator){return camelize$1(str,separator&&separator.charCodeAt(0)||95)}function decamelize$$1(str,separator){return decamelize$1(str,separator&&separator.charCodeAt(0)||95)}function pascalize$$1(str,separator){return pascalize$1(str,separator&&separator.charCodeAt(0)||95)}function depascalize$$1(str,separator){return depascalize$1(str,separator&&separator.charCodeAt(0)||95)}function camelizeKeys(obj,opts){opts=opts||{};if(!shouldProcessValue(obj))return obj;if(opts.inPlace)return processKeysInPlace(obj,camelize$$1,opts);return processKeys(obj,camelize$$1,opts)}function decamelizeKeys(obj,opts){opts=opts||{};if(!shouldProcessValue(obj))return obj;if(opts.inPlace)return processKeysInPlace(obj,decamelize$$1,opts);return processKeys(obj,decamelize$$1,opts)}function pascalizeKeys(obj,opts){opts=opts||{};if(!shouldProcessValue(obj))return obj;if(opts.inPlace)return processKeysInPlace(obj,pascalize$$1,opts);return processKeys(obj,pascalize$$1,opts)}function depascalizeKeys(obj,opts){opts=opts||{};if(!shouldProcessValue(obj))return obj;if(opts.inPlace)return processKeysInPlace(obj,depascalize$$1,opts);return processKeys(obj,depascalize$$1,opts)}exports.camelize=camelize$$1;exports.decamelize=decamelize$$1;exports.pascalize=pascalize$$1;exports.depascalize=depascalize$$1;exports.camelizeKeys=camelizeKeys;exports.decamelizeKeys=decamelizeKeys;exports.pascalizeKeys=pascalizeKeys;exports.depascalizeKeys=depascalizeKeys},{}]},{},[])("/es5/index.js")});
'use strict';
var algorithms = {};
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
function isLower(char) {

@@ -32,3 +36,3 @@ return char >= 0x61 /* 'a' */ && char <= 0x7a /* 'z' */;

algorithms.camelize = function (str, separator) {
function camelize$1(str, separator) {
var firstChar = str.charCodeAt(0);

@@ -62,5 +66,5 @@ if (isDigit(firstChar) || isUpper(firstChar) || firstChar == separator) {

return changed ? String.fromCharCode.apply(undefined, out) : str;
};
}
algorithms.decamelize = function (str, separator) {
function decamelize$1(str, separator) {
var firstChar = str.charCodeAt(0);

@@ -84,5 +88,5 @@ if (!isLower(firstChar)) {

return changed ? String.fromCharCode.apply(undefined, out) : str;
};
}
algorithms.pascalize = function (str, separator) {
function pascalize$1(str, separator) {
var firstChar = str.charCodeAt(0);

@@ -112,5 +116,5 @@ if (isDigit(firstChar) || firstChar == separator) {

return changed ? String.fromCharCode.apply(undefined, out) : str;
};
}
algorithms.depascalize = function (str, separator) {
function depascalize$1(str, separator) {
var firstChar = str.charCodeAt(0);

@@ -136,4 +140,100 @@ if (!isUpper(firstChar)) {

return changed ? String.fromCharCode.apply(undefined, out) : str;
};
}
module.exports = require('./main')(algorithms);
function shouldProcessValue(value) {
return value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) == 'object' && !(value instanceof Date) && !(value instanceof Function);
}
function processKeys(obj, fun, opts) {
var obj2 = void 0;
if (obj instanceof Array) {
obj2 = [];
} else {
if (typeof obj.prototype !== 'undefined') {
// return non-plain object unchanged
return obj;
}
obj2 = {};
}
for (var key in obj) {
var value = obj[key];
if (typeof key === 'string') key = fun(key, opts && opts.separator);
if (shouldProcessValue(value)) {
obj2[key] = processKeys(value, fun, opts);
} else {
obj2[key] = value;
}
}
return obj2;
}
function processKeysInPlace(obj, fun, opts) {
var keys = Object.keys(obj);
for (var idx = 0; idx < keys.length; ++idx) {
var key = keys[idx];
var value = obj[key];
var newKey = fun(key, opts && opts.separator);
if (newKey !== key) {
delete obj[key];
}
if (shouldProcessValue(value)) {
obj[newKey] = processKeys(value, fun, opts);
} else {
obj[newKey] = value;
}
}
return obj;
}
function camelize$$1(str, separator) {
return camelize$1(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
}
function decamelize$$1(str, separator) {
return decamelize$1(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
}
function pascalize$$1(str, separator) {
return pascalize$1(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
}
function depascalize$$1(str, separator) {
return depascalize$1(str, separator && separator.charCodeAt(0) || 0x5f /* _ */);
}
function camelizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, camelize$$1, opts);
return processKeys(obj, camelize$$1, opts);
}
function decamelizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, decamelize$$1, opts);
return processKeys(obj, decamelize$$1, opts);
}
function pascalizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, pascalize$$1, opts);
return processKeys(obj, pascalize$$1, opts);
}
function depascalizeKeys(obj, opts) {
opts = opts || {};
if (!shouldProcessValue(obj)) return obj;
if (opts.inPlace) return processKeysInPlace(obj, depascalize$$1, opts);
return processKeys(obj, depascalize$$1, opts);
}
exports.camelize = camelize$$1;
exports.decamelize = decamelize$$1;
exports.pascalize = pascalize$$1;
exports.depascalize = depascalize$$1;
exports.camelizeKeys = camelizeKeys;
exports.decamelizeKeys = decamelizeKeys;
exports.pascalizeKeys = pascalizeKeys;
exports.depascalizeKeys = depascalizeKeys;

@@ -1,133 +0,94 @@

'use strict';
let algorithms = {};
function isLower(char) {
return char >= 0x61 /* 'a' */ && char <= 0x7a /* 'z' */;
function shouldProcessValue(value) {
return value && typeof value == 'object' &&
!(value instanceof Date) && !(value instanceof Function);
}
function isUpper(char) {
return char >= 0x41 /* 'A' */ && char <= 0x5a /* 'Z' */;
function processKeys(obj, fun, opts) {
let obj2;
if(obj instanceof Array) {
obj2 = [];
} else {
if(typeof obj.prototype !== 'undefined') {
// return non-plain object unchanged
return obj;
}
obj2 = {};
}
for(let key in obj) {
let value = obj[key];
if(typeof key === 'string')
key = fun(key, opts && opts.separator);
if(shouldProcessValue(value)) {
obj2[key] = processKeys(value, fun, opts);
} else {
obj2[key] = value;
}
}
return obj2;
}
function isDigit(char) {
return char >= 0x30 /* '0' */ && char <= 0x39 /* '9' */;
function processKeysInPlace(obj, fun, opts) {
let keys = Object.keys(obj);
for(let idx = 0;idx < keys.length;++idx) {
let key = keys[idx];
let value = obj[key];
let newKey = fun(key, opts && opts.separator);
if(newKey !== key) {
delete obj[key];
}
if(shouldProcessValue(value)) {
obj[newKey] = processKeys(value, fun, opts);
} else {
obj[newKey] = value;
}
}
return obj;
}
function toUpper(char) {
return char - 0x20;
import * as algorithms from './algorithms';
export function camelize(str, separator) {
return algorithms.camelize(str, (separator && separator.charCodeAt(0)) || 0x5f /* _ */);
}
function toUpperSafe(char) {
if(isLower((char))) {
return char - 0x20;
}
return char;
export function decamelize(str, separator) {
return algorithms.decamelize(str, (separator && separator.charCodeAt(0)) || 0x5f /* _ */);
}
function toLower(char) {
return char + 0x20;
export function pascalize(str, separator) {
return algorithms.pascalize(str, (separator && separator.charCodeAt(0)) || 0x5f /* _ */);
}
algorithms.camelize = function(str, separator) {
let firstChar = str.charCodeAt(0);
if(isDigit(firstChar) || isUpper(firstChar) || firstChar == separator) {
return str;
}
let out = [];
let changed = false;
if(isUpper(firstChar)) {
changed = true;
out.push(toLower(firstChar));
} else {
out.push(firstChar);
}
let length = str.length;
for(let i = 1; i < length; ++i) {
let c = str.charCodeAt(i);
if(c === separator) {
changed = true;
c = str.charCodeAt(++i);
if(isNaN(c)) {
return str;
}
out.push(toUpperSafe(c))
} else {
out.push(c);
}
}
return changed ? String.fromCharCode.apply(undefined, out) : str;
};
export function depascalize(str, separator) {
return algorithms.depascalize(str, (separator && separator.charCodeAt(0)) || 0x5f /* _ */);
}
algorithms.decamelize = function(str, separator) {
let firstChar = str.charCodeAt(0);
if(!isLower(firstChar)) {
return str;
}
let length = str.length;
let changed = false;
let out = [];
for(let i = 0; i < length; ++i) {
let c = str.charCodeAt(i);
if(isUpper(c)) {
out.push(separator);
out.push(toLower(c));
changed = true;
} else {
out.push(c);
}
}
return changed ? String.fromCharCode.apply(undefined, out) : str;
export function camelizeKeys(obj, opts) {
opts = opts || {};
if(!shouldProcessValue(obj)) return obj;
if(opts.inPlace) return processKeysInPlace(obj, camelize, opts);
return processKeys(obj, camelize, opts);
}
algorithms.pascalize = function(str, separator) {
let firstChar = str.charCodeAt(0);
if(isDigit(firstChar) || firstChar == separator) {
return str;
}
let length = str.length;
let changed = false;
let out = [];
for(let i = 0; i < length; ++i) {
let c = str.charCodeAt(i);
if(c === separator) {
changed = true;
c = str.charCodeAt(++i);
if(isNaN(c)) {
return str;
}
out.push(toUpperSafe(c))
} else if(i === 0 && isLower(c)) {
changed = true;
out.push(toUpper(c));
} else {
out.push(c);
}
}
return changed ? String.fromCharCode.apply(undefined, out) : str;
};
export function decamelizeKeys(obj, opts) {
opts = opts || {};
if(!shouldProcessValue(obj)) return obj;
if(opts.inPlace) return processKeysInPlace(obj, decamelize, opts);
return processKeys(obj, decamelize, opts);
}
algorithms.depascalize = function(str, separator) {
let firstChar = str.charCodeAt(0);
if(!isUpper(firstChar)) {
return str;
}
let length = str.length;
let changed = false;
let out = [];
for(let i = 0; i < length; ++i) {
let c = str.charCodeAt(i);
if(isUpper(c)) {
if(i > 0) {
out.push(separator);
}
out.push(toLower(c));
changed = true;
} else {
out.push(c);
}
}
return changed ? String.fromCharCode.apply(undefined, out) : str;
export function pascalizeKeys(obj, opts) {
opts = opts || {};
if(!shouldProcessValue(obj)) return obj;
if(opts.inPlace) return processKeysInPlace(obj, pascalize, opts);
return processKeys(obj, pascalize, opts);
}
module.exports = require('./main')(algorithms);
export function depascalizeKeys(obj, opts) {
opts = opts || {};
if(!shouldProcessValue(obj)) return obj;
if(opts.inPlace) return processKeysInPlace(obj, depascalize, opts);
return processKeys(obj, depascalize, opts);
}
{
"name": "xcase",
"version": "2.0.0",
"version": "2.0.1",
"description": "Blazingly fast recursive convertion to and from camelCase or PascalCase for Objects and Arrays",
"main": "es5/index",
"scripts": {
"test": "mocha",
"build": "babel index.js main.js -d es5 && browserify -s xcase -r ./es5/index.js -o dist/xcase.js && uglifyjs dist/xcase.js > dist/xcase.min.js",
"test": "npm run build && mocha",
"build": "rollup index.js -f es | babel --presets es2015 -o es5/index.js && browserify -s xcase -r ./es5/index.js -o dist/xcase.js && uglifyjs dist/xcase.js > dist/xcase.min.js",
"prepublish": "npm run build"

@@ -40,4 +40,5 @@ },

"mocha": "^3.0.2",
"rollup": "^0.41.4",
"uglify-js": "^2.7.3"
}
}
'use strict';
let assert = require('assert');
let xcase = require('./');
let xcaseJs = require('./index');
let humps = require('humps');
makeTests('xcase', xcase);
makeTests('xcaseJs', xcaseJs);
makeTests('xcase {inPlace: true}', Object.assign({}, xcase, {

@@ -10,0 +8,0 @@ camelizeKeys: (obj, opts) => xcase.camelizeKeys(obj, Object.assign({inPlace: true}, opts)),

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc