📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP →

uncamelize

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uncamelize - npm Package Compare versions

Comparing version

to
1.1.0

// Generated by CoffeeScript 1.10.0
(function() {
module.exports = function(s) {
return ('' + s).replace(/((?=.)[^A-Z])([A-Z])(?=[^A-Z])/g, '$1 $2').trim();
var isPlainObject,
hasProp = {}.hasOwnProperty,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
isPlainObject = require('lodash.isplainobject');
module.exports = function(o) {
var arraysAsArrays, config, configArrayKeys, handleSpecialCases, key, uncamelize, value;
configArrayKeys = ['specialCases', 'merge'];
arraysAsArrays = function(o) {
var k, v;
for (k in o) {
if (!hasProp.call(o, k)) continue;
v = o[k];
if (indexOf.call(configArrayKeys, k) >= 0 && typeof v === 'string') {
o[k] = v.split(' ');
}
}
return o;
};
config = arraysAsArrays({
specialCases: 'URL URLs SSH CMS ID HTTP HTTPS HTML XML QA UAT GitLab GitHub'
});
handleSpecialCases = function(s) {
var abbrev, i, j, len, len1, ref, ref1, uncamelized;
if (!config.specialCases) {
return s;
}
ref = config.specialCases;
for (i = 0, len = ref.length; i < len; i++) {
abbrev = ref[i];
s = s.replace(new RegExp("\\b" + abbrev + "\\b", "ig"), abbrev);
}
ref1 = config.specialCases;
for (j = 0, len1 = ref1.length; j < len1; j++) {
abbrev = ref1[j];
uncamelized = uncamelize(abbrev, false);
if (uncamelized !== abbrev) {
s = s.replace(new RegExp("\\b" + uncamelized + "\\b", "ig"), abbrev);
}
}
return s;
};
uncamelize = function(s, specialCases) {
if (specialCases == null) {
specialCases = true;
}
s = ('' + s).replace(/((?=.)[^A-Z ])([A-Z])(?=[^A-Z])/g, '$1 $2').trim();
if (specialCases) {
s = handleSpecialCases(s);
}
return s;
};
if (typeof o === 'string') {
return uncamelize(o);
} else if (isPlainObject(o)) {
if (!o.merge) {
o.merge = [];
}
o = arraysAsArrays(o);
for (key in o) {
if (!hasProp.call(o, key)) continue;
value = o[key];
if (indexOf.call(o.merge, key) >= 0) {
value = config[key].concat(value);
}
config[key] = value;
}
return uncamelize;
} else {
throw new TypeError('Expected a string or plain object');
}
};
}).call(this);
{
"author": {
"name": "Matt Dolan",
"email": "matt@dolan.me"
},
"name": "uncamelize",
"version": "1.0.6",
"version": "1.1.0",
"description": "Converts a camelCase string into a space separated one",

@@ -14,3 +18,2 @@ "main": "lib/uncamelize.js",

},
"author": "Matt Dolan <matt@dolan.me>",
"license": "MIT",

@@ -38,3 +41,6 @@ "keywords": [

"mocha": "^2.4.5"
},
"dependencies": {
"lodash.isplainobject": "^4.0.4"
}
}

@@ -13,2 +13,38 @@ [![Build Status](https://travis-ci.org/mgduk/uncamelize.svg?branch=master)](https://travis-ci.org/mgduk/uncamelize)

`uncamelize` corrects the capitalization of special cases, such as initialisms and camelcased names:
```
uncamelize('httpGitHubUrls')
// => 'HTTP GitHub URLs'
// (whereas naturally this would become 'http Git Hub Urls')
```
You can pass special case words of your own.
```
// calling uncamelize directly with a string
uncamelize = require('uncamelize')
uncamelize('fooBarBaz')
// => 'foo Bar Baz'
// calling uncamelize with a hashmap of options to override the default
uncamelize = require('uncamelize')({specialCases: 'FOO WhyNot'})
uncamelize('fooBarWhyNotBaz')
// => 'FOO Bar WhyNot Baz'
// `specialCases` can be a space separated string or an array:
uncamelize = require('uncamelize')({specialCases: ['FOO', 'WhyNot']})
uncamelize('fooBarWhyNotBaz')
// => 'FOO Bar WhyNot Baz'
```
By default `specialCases` you provide override the default. You can alternatively merge them:
```
uncamelize = require('uncamelize')({specialCases: 'NASA'})
uncamelize('nasaGitHubUrl')
// => 'NASA Git Hub Url'
uncamelize = require('uncamelize')({specialCases: 'NASA', merge: 'specialCases'})
uncamelize('nasaGitHubUrl')
// => 'NASA GitHub URL'
```
Tests

@@ -15,0 +51,0 @@ -----