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 1.0.6 to 1.0.7

2

benchmark.js
'use strict';
let Benchmark = require('benchmark');
let humps = require('humps');
let xcase = require('./');
let xcase = require('./es5');
let camelCase = require('lodash').camelCase;

@@ -6,0 +6,0 @@ let reduce = require('lodash').reduce;

@@ -172,36 +172,17 @@ (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){

function processKeysInPlace(obj, fun, opts) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = Object.keys(obj)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var key = _step.value;
var value = obj[key];
var newKey = fun(key, opts);
if (newKey !== key) {
delete obj[key];
}
if (shouldProcessValue(value)) {
obj[newKey] = processKeys(value, fun, opts);
} else {
obj[newKey] = value;
}
var keys = Object.keys(obj);
for (var idx = 0; idx < keys.length; ++idx) {
var key = keys[idx];
var value = obj[key];
var newKey = key;
fun(key, opts);
if (newKey !== key) {
delete obj[key];
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
if (shouldProcessValue(value)) {
obj[newKey] = processKeys(value, fun, opts);
} else {
obj[newKey] = value;
}
}
return obj;

@@ -208,0 +189,0 @@ }

@@ -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){var firstChar=str.charCodeAt(0);if(isDigit(firstChar)||firstChar==45){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===95||c===32||c==45){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);var separatorChar=(separator||"_").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(separatorChar);out.push(toLower(c));changed=true}else{out.push(c)}}return changed?String.fromCharCode.apply(undefined,out):str};algorithms.pascalize=function(str){var firstChar=str.charCodeAt(0);if(isDigit(firstChar)||firstChar==45){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===95||c===32||c==45){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);var separatorChar=(separator||"_").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(separatorChar)}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);if(shouldProcessValue(value)){obj2[key]=processKeys(value,fun,opts)}else{obj2[key]=value}}return obj2}function processKeysInPlace(obj,fun,opts){var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=Object.keys(obj)[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var key=_step.value;var value=obj[key];var newKey=fun(key,opts);if(newKey!==key){delete obj[key]}if(shouldProcessValue(value)){obj[newKey]=processKeys(value,fun,opts)}else{obj[newKey]=value}}}catch(err){_didIteratorError=true;_iteratorError=err}finally{try{if(!_iteratorNormalCompletion&&_iterator.return){_iterator.return()}}finally{if(_didIteratorError){throw _iteratorError}}}return obj}var iface={camelize:algorithms.camelize,decamelize:function decamelize(str,opts){return algorithms.decamelize(str,opts&&opts.separator||"")},pascalize:algorithms.pascalize,depascalize:function depascalize(str,opts){return algorithms.depascalize(str,opts&&opts.separator||"")},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";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){var firstChar=str.charCodeAt(0);if(isDigit(firstChar)||firstChar==45){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===95||c===32||c==45){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);var separatorChar=(separator||"_").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(separatorChar);out.push(toLower(c));changed=true}else{out.push(c)}}return changed?String.fromCharCode.apply(undefined,out):str};algorithms.pascalize=function(str){var firstChar=str.charCodeAt(0);if(isDigit(firstChar)||firstChar==45){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===95||c===32||c==45){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);var separatorChar=(separator||"_").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(separatorChar)}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);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=key;fun(key,opts);if(newKey!==key){delete obj[key]}if(shouldProcessValue(value)){obj[newKey]=processKeys(value,fun,opts)}else{obj[newKey]=value}}return obj}var iface={camelize:algorithms.camelize,decamelize:function decamelize(str,opts){return algorithms.decamelize(str,opts&&opts.separator||"")},pascalize:algorithms.pascalize,depascalize:function depascalize(str,opts){return algorithms.depascalize(str,opts&&opts.separator||"")},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")});

@@ -34,36 +34,17 @@ 'use strict';

function processKeysInPlace(obj, fun, opts) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = Object.keys(obj)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var key = _step.value;
var value = obj[key];
var newKey = fun(key, opts);
if (newKey !== key) {
delete obj[key];
}
if (shouldProcessValue(value)) {
obj[newKey] = processKeys(value, fun, opts);
} else {
obj[newKey] = value;
}
var keys = Object.keys(obj);
for (var idx = 0; idx < keys.length; ++idx) {
var key = keys[idx];
var value = obj[key];
var newKey = key;
fun(key, opts);
if (newKey !== key) {
delete obj[key];
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
if (shouldProcessValue(value)) {
obj[newKey] = processKeys(value, fun, opts);
} else {
obj[newKey] = value;
}
}
return obj;

@@ -70,0 +51,0 @@ }

@@ -33,5 +33,8 @@ 'use strict';

function processKeysInPlace(obj, fun, opts) {
for(let key of Object.keys(obj)) {
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);
let newKey = key;
fun(key, opts);
if(newKey !== key) {

@@ -38,0 +41,0 @@ delete obj[key];

{
"name": "xcase",
"version": "1.0.6",
"version": "1.0.7",
"description": "Blazingly fast recursive convertion to and from camelCase or PascalCase for Objects and Arrays",
"main": "index",
"main": "es5/index",
"scripts": {

@@ -41,6 +41,3 @@ "test": "mocha",

"uglify-js": "^2.7.3"
},
"jspm": {
"main": "es5/index"
}
}

@@ -10,24 +10,24 @@ # xcase

> node benchmark.js
xcase#camelize x 5,399,331 ops/sec ±1.36% (90 runs sampled)
humps#camelize x 690,996 ops/sec ±1.48% (87 runs sampled)
lodash#camelCase x 597,486 ops/sec ±0.96% (87 runs sampled)
xcase#camelize x 7,521,530 ops/sec ±0.18% (96 runs sampled)
humps#camelize x 870,637 ops/sec ±0.67% (95 runs sampled)
lodash#camelCase x 784,445 ops/sec ±1.18% (92 runs sampled)
Fastest is xcase#camelize
xcase#decamelize x 4,662,606 ops/sec ±0.72% (92 runs sampled)
humps#decamelize x 1,293,234 ops/sec ±1.50% (85 runs sampled)
lodash#snakeCase x 503,567 ops/sec ±1.69% (91 runs sampled)
xcase#decamelize x 6,517,893 ops/sec ±0.43% (94 runs sampled)
humps#decamelize x 1,576,663 ops/sec ±0.65% (95 runs sampled)
lodash#snakeCase x 659,930 ops/sec ±1.50% (95 runs sampled)
Fastest is xcase#decamelize
xcase#camelizeKeys x 415,509 ops/sec ±1.41% (90 runs sampled)
humps#camelizeKeys x 108,174 ops/sec ±0.89% (89 runs sampled)
lodash#reduce + camelCase x 91,300 ops/sec ±0.59% (93 runs sampled)
xcase#camelizeKeys x 642,111 ops/sec ±1.16% (92 runs sampled)
humps#camelizeKeys x 126,551 ops/sec ±0.64% (91 runs sampled)
lodash#reduce + camelCase x 120,886 ops/sec ±1.11% (92 runs sampled)
Fastest is xcase#camelizeKeys
xcase#decamelizeKeys x 427,660 ops/sec ±1.05% (93 runs sampled)
humps#decamelizeKeys x 161,917 ops/sec ±1.03% (91 runs sampled)
xcase#decamelizeKeys x 613,896 ops/sec ±1.13% (86 runs sampled)
humps#decamelizeKeys x 194,091 ops/sec ±0.61% (92 runs sampled)
lodash#reduce + snakeCase:
Fastest is xcase#decamelizeKeys
xcase#camelizeKeys (large object) x 518 ops/sec ±1.77% (87 runs sampled)
xcase#camelizeKeys {inPlace: true} (large object) x 447 ops/sec ±1.50% (77 runs sampled)
humps#camelizeKeys (large object) x 134 ops/sec ±2.16% (75 runs sampled)
xcase#camelizeKeys (large object) x 678 ops/sec ±0.35% (94 runs sampled)
xcase#camelizeKeys {inPlace: true} (large object) x 570 ops/sec ±1.41% (86 runs sampled)
humps#camelizeKeys (large object) x 163 ops/sec ±0.22% (82 runs sampled)
Fastest is xcase#camelizeKeys (large object)
xcase#decamelizeKeys (large object) x 508 ops/sec ±1.10% (86 runs sampled)
humps#decamelizeKeys (large object) x 135 ops/sec ±19.79% (63 runs sampled)
xcase#decamelizeKeys (large object) x 665 ops/sec ±0.68% (92 runs sampled)
humps#decamelizeKeys (large object) x 238 ops/sec ±0.63% (85 runs sampled)
Fastest is xcase#decamelizeKeys (large object)

@@ -39,4 +39,9 @@ ```

Node: `npm install --save xcase`
Browser: `jspm install npm:xcase`
Browser (JSPM): `jspm install npm:xcase`
Browser (Bower): `jspm install xcase`
Browser (Manual): Load https://raw.githubusercontent.com/encharm/xcase/master/dist/xcase.min.js and use global `xcase` object
## Usage:

@@ -43,0 +48,0 @@

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