Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fixes #1

Merged
merged 14 commits into from Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 30 additions & 2 deletions .babelrc
@@ -1,4 +1,32 @@
{
"presets": ["env"],
"plugins": ["transform-object-rest-spread"]
"env": {
"test": {
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
]
},

"production": {
"presets": [
[
"env",
{
"targets": {
"browsers": "> 1%, last 2 versions, ie 8"
}
}
]
],
"plugins": [
"babel-plugin-loop-optimizer"
]
}
}
}
10 changes: 6 additions & 4 deletions .travis.yml
@@ -1,12 +1,14 @@
language: node_js

node_js:
- 7
- 6
- 5
- 8
- 9

install:
- npm install

script:
- npm test
- npm run build

after_success:
- npm run cover
225 changes: 192 additions & 33 deletions dist/react-classlist-helper.js
@@ -1,74 +1,169 @@
'use strict';
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["reactClasslistHelper"] = factory();
else
root["reactClasslistHelper"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {

"use strict";


Object.defineProperty(exports, "__esModule", {
value: true
});
exports.tC = exports.cL = undefined;

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

exports.default = classList;
exports.classList = classList;
exports.toggleClass = toggleClass;

var _lodash = require('lodash.isboolean');

var _lodash2 = _interopRequireDefault(_lodash);

var _lodash3 = require('lodash.isobjectlike');

var _lodash4 = _interopRequireDefault(_lodash3);

var _lodash5 = require('lodash.isstring');

var _lodash6 = _interopRequireDefault(_lodash5);

var _lodash7 = require('lodash.isundefined');

var _lodash8 = _interopRequireDefault(_lodash7);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _assertions = __webpack_require__(1);

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

/**
* Spred css class names provided as input
*
* @param {Array} args The classe's names.
* @return {string} final className
*/
function classList() {
for (var _len = arguments.length, classes = Array(_len), _key = 0; _key < _len; _key++) {
classes[_key] = arguments[_key];
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}

if (classes.length === 0) {
if (args.length === 0) {
return '';
}

var classBuffer = [];

classes.forEach(function (className) {
var _a = args;

var _f = function _f(className) {
if (Array.isArray(className)) {
classBuffer = [].concat(_toConsumableArray(classBuffer), [className.reduce(function (total, classItem) {
return total + ' ' + classItem;
classBuffer = [].concat(_toConsumableArray(classBuffer), [className.reduce(function (total, curItem) {
return total + ' ' + curItem;
})]);
} else if ((0, _lodash6.default)(className)) {
} else if ((0, _assertions.isString)(className)) {
classBuffer = [].concat(_toConsumableArray(classBuffer), [className]);
} else if ((0, _lodash4.default)(className)) {
} else if ((0, _assertions.isObject)(className)) {
var keys = Object.keys(className);

keys.forEach(function (key) {
var _a2 = keys;

var _f2 = function _f2(key) {
if (className[key] === true) {
classBuffer = [].concat(_toConsumableArray(classBuffer), [key]);
}
});
};

for (var _i2 = 0; _i2 < _a2.length; _i2++) {
_f2(_a2[_i2], _i2, _a2);
}

undefined;
} else {
throw new Error('Expected className to be a string but instead got ' + (typeof className === 'undefined' ? 'undefined' : _typeof(className)));
}
});
};

return classBuffer.join(' ');
for (var _i = 0; _i < _a.length; _i++) {
_f(_a[_i], _i, _a);
}

undefined;

return classBuffer.join(' ').trim();
}

/**
* Toggle a class based on a condition.
*
* @param {string} className The class name
* @param {boolean} condition The condition
* @return {string} if condition is true, returns the string, if false,
* returns empty string
*/
function toggleClass(className, condition) {
if ((0, _lodash8.default)(className) || !(0, _lodash6.default)(className)) {
if ((0, _assertions.isUndefined)(className) || !(0, _assertions.isString)(className)) {
throw new Error('Expected className to be a string but instead got ' + (typeof className === 'undefined' ? 'undefined' : _typeof(className)));
}

if ((0, _lodash8.default)(condition) || !(0, _lodash2.default)(condition)) {
if ((0, _assertions.isUndefined)(condition) || !(0, _assertions.isBoolean)(condition)) {
throw new Error('Expected condition to be a boolean value but instead got ' + (typeof condition === 'undefined' ? 'undefined' : _typeof(condition)));
}

Expand All @@ -77,3 +172,67 @@ function toggleClass(className, condition) {

return classList(ClassMap);
}

var cL = exports.cL = classList;
var tC = exports.tC = toggleClass;

var defaultFunc = classList;

exports.default = defaultFunc;

/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {

"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 && obj !== Symbol.prototype ? "symbol" : typeof obj; };

exports.isBoolean = isBoolean;
exports.isObject = isObject;
exports.isString = isString;
exports.isUndefined = isUndefined;
/**
*
* @param {*} value Any value
* @return {boolean} assertion
*/
function isBoolean(value) {
return typeof value === 'boolean' || (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value !== null && typeof value.valueOf() === 'boolean';
}

/**
*
* @param {*} value Any value
* @return {boolean} assertion
*/
function isObject(value) {
return value !== null && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object';
}

/**
*
* @param {*} value Any value
* @return {boolean} assertion
*/
function isString(value) {
return typeof value === 'string' || value instanceof String;
}

/**
*
* @param {*} value Any value
* @return {boolean} assertion
*/
function isUndefined(value) {
return typeof value === 'undefined';
}

/***/ })
/******/ ]);
});
2 changes: 1 addition & 1 deletion dist/react-classlist-helper.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.