Skip to content

Commit

Permalink
Use local camelize function and migrate utility methods to separate m…
Browse files Browse the repository at this point in the history
…odules (#216)
  • Loading branch information
calvinf authored and robmadole committed Aug 25, 2019
1 parent 74ed98a commit 8329c58
Show file tree
Hide file tree
Showing 13 changed files with 404 additions and 364 deletions.
226 changes: 69 additions & 157 deletions index.es.js
Expand Up @@ -106,143 +106,62 @@ function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}

var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}

var humps = createCommonjsModule(function (module) {
(function(global) {

var _processKeys = function(convert, obj, options) {
if(!_isObject(obj) || _isDate(obj) || _isRegExp(obj) || _isBoolean(obj) || _isFunction(obj)) {
return obj;
}
// Get CSS class list from a props object
function classList(props) {
var _classes;

var output,
i = 0,
l = 0;
var spin = props.spin,
pulse = props.pulse,
fixedWidth = props.fixedWidth,
inverse = props.inverse,
border = props.border,
listItem = props.listItem,
flip = props.flip,
size = props.size,
rotation = props.rotation,
pull = props.pull; // map of CSS class names to properties

if(_isArray(obj)) {
output = [];
for(l=obj.length; i<l; i++) {
output.push(_processKeys(convert, obj[i], options));
}
}
else {
output = {};
for(var key in obj) {
if(Object.prototype.hasOwnProperty.call(obj, key)) {
output[convert(key, options)] = _processKeys(convert, obj[key], options);
}
}
}
return output;
};
var classes = (_classes = {
'fa-spin': spin,
'fa-pulse': pulse,
'fa-fw': fixedWidth,
'fa-inverse': inverse,
'fa-border': border,
'fa-li': listItem,
'fa-flip-horizontal': flip === 'horizontal' || flip === 'both',
'fa-flip-vertical': flip === 'vertical' || flip === 'both'
}, _defineProperty(_classes, "fa-".concat(size), typeof size !== 'undefined'), _defineProperty(_classes, "fa-rotate-".concat(rotation), typeof rotation !== 'undefined'), _defineProperty(_classes, "fa-pull-".concat(pull), typeof pull !== 'undefined'), _classes); // map over all the keys in the classes object
// return an array of the keys where the value for the key is not null

// String conversion methods
return Object.keys(classes).map(function (key) {
return classes[key] ? key : null;
}).filter(function (key) {
return key;
});
}

var separateWords = function(string, options) {
options = options || {};
var separator = options.separator || '_';
var split = options.split || /(?=[A-Z])/;
// Camelize taken from humps
// humps is copyright © 2012+ Dom Christie
// Released under the MIT license.
// Performant way to determine if object coerces to a number
function _isNumerical(obj) {
obj = obj - 0; // eslint-disable-next-line no-self-compare

return string.split(split).join(separator);
};
return obj === obj;
}

var camelize = function(string) {
if (_isNumerical(string)) {
return string;
}
string = string.replace(/[\-_\s]+(.)?/g, function(match, chr) {
return chr ? chr.toUpperCase() : '';
});
// Ensure 1st char is always lowercase
return string.substr(0, 1).toLowerCase() + string.substr(1);
};

var pascalize = function(string) {
var camelized = camelize(string);
// Ensure 1st char is always uppercase
return camelized.substr(0, 1).toUpperCase() + camelized.substr(1);
};

var decamelize = function(string, options) {
return separateWords(string, options).toLowerCase();
};

// Utilities
// Taken from Underscore.js

var toString = Object.prototype.toString;

var _isFunction = function(obj) {
return typeof(obj) === 'function';
};
var _isObject = function(obj) {
return obj === Object(obj);
};
var _isArray = function(obj) {
return toString.call(obj) == '[object Array]';
};
var _isDate = function(obj) {
return toString.call(obj) == '[object Date]';
};
var _isRegExp = function(obj) {
return toString.call(obj) == '[object RegExp]';
};
var _isBoolean = function(obj) {
return toString.call(obj) == '[object Boolean]';
};

// Performant way to determine if obj coerces to a number
var _isNumerical = function(obj) {
obj = obj - 0;
return obj === obj;
};

// Sets up function which handles processing keys
// allowing the convert function to be modified by a callback
var _processor = function(convert, options) {
var callback = options && 'process' in options ? options.process : options;

if(typeof(callback) !== 'function') {
return convert;
}
function camelize(string) {
if (_isNumerical(string)) {
return string;
} // eslint-disable-next-line no-useless-escape

return function(string, options) {
return callback(string, convert, options);
}
};

var humps = {
camelize: camelize,
decamelize: decamelize,
pascalize: pascalize,
depascalize: decamelize,
camelizeKeys: function(object, options) {
return _processKeys(_processor(camelize, options), object);
},
decamelizeKeys: function(object, options) {
return _processKeys(_processor(decamelize, options), object, options);
},
pascalizeKeys: function(object, options) {
return _processKeys(_processor(pascalize, options), object);
},
depascalizeKeys: function () {
return this.decamelizeKeys.apply(this, arguments);
}
};

if (module.exports) {
module.exports = humps;
} else {
global.humps = humps;
}
string = string.replace(/[\-_\s]+(.)?/g, function (match, chr) {
return chr ? chr.toUpperCase() : '';
}); // Ensure 1st char is always lowercase

})(commonjsGlobal);
});
return string.substr(0, 1).toLowerCase() + string.substr(1);
}

function capitalize(val) {
return val.charAt(0).toUpperCase() + val.slice(1);
Expand All @@ -255,7 +174,7 @@ function styleToObject(style) {
return s;
}).reduce(function (acc, pair) {
var i = pair.indexOf(':');
var prop = humps.camelize(pair.slice(0, i));
var prop = camelize(pair.slice(0, i));
var value = pair.slice(i + 1).trim();
prop.startsWith('webkit') ? acc[capitalize(prop)] = value : acc[prop] = value;
return acc;
Expand Down Expand Up @@ -289,7 +208,7 @@ function convert(createElement, element) {
if (key.indexOf('aria-') === 0 || key.indexOf('data-') === 0) {
acc.attrs[key.toLowerCase()] = val;
} else {
acc.attrs[humps.camelize(key)] = val;
acc.attrs[camelize(key)] = val;
}

}
Expand Down Expand Up @@ -321,45 +240,27 @@ function log () {
}
}

function objectWithKey(key, value) {
return Array.isArray(value) && value.length > 0 || !Array.isArray(value) && value ? _defineProperty({}, key, value) : {};
}

function classList(props) {
var _classes;

var classes = (_classes = {
'fa-spin': props.spin,
'fa-pulse': props.pulse,
'fa-fw': props.fixedWidth,
'fa-inverse': props.inverse,
'fa-border': props.border,
'fa-li': props.listItem,
'fa-flip-horizontal': props.flip === 'horizontal' || props.flip === 'both',
'fa-flip-vertical': props.flip === 'vertical' || props.flip === 'both'
}, _defineProperty(_classes, "fa-".concat(props.size), props.size !== null), _defineProperty(_classes, "fa-rotate-".concat(props.rotation), props.rotation !== null), _defineProperty(_classes, "fa-pull-".concat(props.pull), props.pull !== null), _classes);
return Object.keys(classes).map(function (key) {
return classes[key] ? key : null;
}).filter(function (key) {
return key;
});
}

// Normalize icon arguments
function normalizeIconArgs(icon$$1) {
// if the icon is null, there's nothing to do
if (icon$$1 === null) {
return null;
}
} // if the icon is an object and has a prefix and an icon name, return it


if (_typeof(icon$$1) === 'object' && icon$$1.prefix && icon$$1.iconName) {
return icon$$1;
}
} // if it's an array with length of two


if (Array.isArray(icon$$1) && icon$$1.length === 2) {
// use the first item as prefix, second as icon name
return {
prefix: icon$$1[0],
iconName: icon$$1[1]
};
}
} // if it's a string, use it as the icon name


if (typeof icon$$1 === 'string') {
return {
Expand All @@ -369,6 +270,17 @@ function normalizeIconArgs(icon$$1) {
}
}

// creates an object with a key of key
// and a value of value
// if certain conditions are met
function objectWithKey(key, value) {
// if the value is a non-empty array
// or it's not an array but it is truthy
// then create the object with the key and the value
// if not, return an empty array
return Array.isArray(value) && value.length > 0 || !Array.isArray(value) && value ? _defineProperty({}, key, value) : {};
}

function FontAwesomeIcon(props) {
var iconArgs = props.icon,
maskArgs = props.mask,
Expand Down

0 comments on commit 8329c58

Please sign in to comment.