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

react-classlist-helper

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-classlist-helper - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

src/assertions.js

225

dist/react-classlist-helper.js

@@ -1,38 +0,109 @@

'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 _assertions = __webpack_require__(1);
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 }; }
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 '';

@@ -43,31 +114,55 @@ }

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)));

@@ -81,1 +176,65 @@ }

}
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

dist/react-classlist-helper.min.js

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

'use strict';var _typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a};Object.defineProperty(exports,'__esModule',{value:!0});exports.default=classList,exports.toggleClass=toggleClass;var _lodash=require('lodash.isboolean'),_lodash2=_interopRequireDefault(_lodash),_lodash3=require('lodash.isobjectlike'),_lodash4=_interopRequireDefault(_lodash3),_lodash5=require('lodash.isstring'),_lodash6=_interopRequireDefault(_lodash5),_lodash7=require('lodash.isundefined'),_lodash8=_interopRequireDefault(_lodash7);function _interopRequireDefault(a){return a&&a.__esModule?a:{default:a}}function _toConsumableArray(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}return Array.from(a)}function classList(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];if(0===b.length)return'';var d=[];return b.forEach(function(a){if(Array.isArray(a))d=[].concat(_toConsumableArray(d),[a.reduce(function(a,b){return a+' '+b})]);else if((0,_lodash6.default)(a))d=[].concat(_toConsumableArray(d),[a]);else if((0,_lodash4.default)(a)){var b=Object.keys(a);b.forEach(function(b){!0===a[b]&&(d=[].concat(_toConsumableArray(d),[b]))})}else throw new Error('Expected className to be a string but instead got '+('undefined'==typeof a?'undefined':_typeof(a)))}),d.join(' ')}function toggleClass(a,b){if((0,_lodash8.default)(a)||!(0,_lodash6.default)(a))throw new Error('Expected className to be a string but instead got '+('undefined'==typeof a?'undefined':_typeof(a)));if((0,_lodash8.default)(b)||!(0,_lodash2.default)(b))throw new Error('Expected condition to be a boolean value but instead got '+('undefined'==typeof b?'undefined':_typeof(b)));var c={};return c[a]=b,classList(c)}
(function(a,b){'object'==typeof exports&&'object'==typeof module?module.exports=b():'function'==typeof define&&define.amd?define([],b):'object'==typeof exports?exports.reactClasslistHelper=b():a.reactClasslistHelper=b()})('undefined'==typeof self?this:self,function(){return function(a){function b(d){if(c[d])return c[d].exports;var e=c[d]={i:d,l:!1,exports:{}};return a[d].call(e.exports,e,e.exports,b),e.l=!0,e.exports}var c={};return b.m=a,b.c=c,b.d=function(a,c,d){b.o(a,c)||Object.defineProperty(a,c,{configurable:!1,enumerable:!0,get:d})},b.n=function(a){var c=a&&a.__esModule?function(){return a['default']}:function(){return a};return b.d(c,'a',c),c},b.o=function(a,b){return Object.prototype.hasOwnProperty.call(a,b)},b.p='',b(b.s=0)}([function(a,b,c){'use strict';function d(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}return Array.from(a)}function e(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];if(0===b.length)return'';for(var e=[],f=b,i=function(a){if(Array.isArray(a))e=[].concat(d(e),[a.reduce(function(a,b){return a+' '+b})]);else if((0,h.isString)(a))e=[].concat(d(e),[a]);else if((0,h.isObject)(a)){for(var b=Object.keys(a),c=b,f=function(b){!0===a[b]&&(e=[].concat(d(e),[b]))},i=0;i<c.length;i++)f(c[i],i,c)}else throw new Error('Expected className to be a string but instead got '+('undefined'==typeof a?'undefined':g(a)))},j=0;j<f.length;j++)i(f[j],j,f);return e.join(' ').trim()}function f(a,b){if((0,h.isUndefined)(a)||!(0,h.isString)(a))throw new Error('Expected className to be a string but instead got '+('undefined'==typeof a?'undefined':g(a)));if((0,h.isUndefined)(b)||!(0,h.isBoolean)(b))throw new Error('Expected condition to be a boolean value but instead got '+('undefined'==typeof b?'undefined':g(b)));var c={};return c[a]=b,e(c)}Object.defineProperty(b,'__esModule',{value:!0}),b.tC=b.cL=void 0;var g='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a};b.classList=e,b.toggleClass=f;var h=c(1),i=b.cL=e,j=b.tC=f;b.default=e},function(a,b){'use strict';Object.defineProperty(b,'__esModule',{value:!0});var c='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a};b.isBoolean=function(a){return'boolean'==typeof a||'object'===('undefined'==typeof a?'undefined':c(a))&&null!==a&&'boolean'==typeof a.valueOf()},b.isObject=function(a){return null!==a&&'object'===('undefined'==typeof a?'undefined':c(a))},b.isString=function(a){return'string'==typeof a||a instanceof String},b.isUndefined=function(a){return'undefined'==typeof a}}])});
{
"name": "react-classlist-helper",
"version": "1.3.1",
"version": "1.4.0",
"description": "Helper to defining multiple classes on a react component.",
"main": "./src/index.js",
"main": "./dist/react-classlist-helper.min.js",
"scripts": {
"test": "nyc -x ./src/index.spec.js mocha ./src/index.spec.js --compilers js:babel-core/register ",
"cover": "npm test && nyc report -x ./src/index.spec.js --reporter=text-lcov | coveralls",
"test": "cross-env NODE_ENV=test nyc -x src/**/*.spec.js mocha src/**/*.spec.js --require babel-core/register",
"cover": "nyc report -x ./src/**/*.spec.js --reporter=text-lcov | coveralls",
"lint": "eslint ./src/index.js",
"prebuild": "npm run lint && npm test",
"build:minified": "babel --presets babili ./src/index.js -o ./dist/react-classlist-helper.min.js --sourcemaps inline",
"build": "babel ./src/index.js -o ./dist/react-classlist-helper.js --sourcemaps inline && npm run build:minified"
"build": "cross-env NODE_ENV=production webpack --progress --colors"
},

@@ -27,8 +26,11 @@ "repository": {

"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.25.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-babili": "^0.1.4",
"babel-loader": "^7.1.2",
"babel-minify-webpack-plugin": "^0.2.0",
"babel-plugin-loop-optimizer": "^1.4.1",
"babel-preset-env": "^1.6.0",
"chai": "^4.0.2",
"coveralls": "^2.13.1",
"cross-env": "^5.1.3",
"eslint": "^3.19.0",

@@ -39,10 +41,7 @@ "eslint-config-airbnb-base": "^11.2.0",

"mocha": "^3.4.2",
"nyc": "^11.0.3"
"nyc": "^11.0.3",
"webpack": "^3.10.0",
"webpack-merge": "^4.1.1"
},
"dependencies": {
"lodash.isboolean": "^3.0.3",
"lodash.isobjectlike": "^4.0.0",
"lodash.isstring": "^4.0.1",
"lodash.isundefined": "^3.0.1"
},
"dependencies": {},
"nyc": {

@@ -49,0 +48,0 @@ "include": [

@@ -0,0 +0,0 @@ # React classList Helper

@@ -1,7 +0,8 @@

import isBoolean from 'lodash.isboolean';
import isObject from 'lodash.isobjectlike';
import isString from 'lodash.isstring';
import isUndefined from 'lodash.isundefined';
import {
isBoolean,
isObject,
isString,
isUndefined,
} from './assertions';
/**

@@ -8,0 +9,0 @@ * Spred css class names provided as input

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

/* eslint-env node,mocha */
import { expect } from 'chai';

@@ -7,5 +8,5 @@

describe('React classList Function', () => {
it('should be defined without any erros', () => {
expect(classList).to.be.a('function');
// eslint-disable-next-line no-unused-expressions
expect(classList).to.be.ok;

@@ -85,3 +86,3 @@ });

const output = classList();
expect(output).to.equal(expectedOutput);

@@ -95,5 +96,5 @@ expect(output).to.be.a('string');

describe('React toggleClass Function', () => {
it('should be defined without any erros', () => {
expect(classList).to.be.a('function');
// eslint-disable-next-line no-unused-expressions
expect(classList).to.be.ok;

@@ -128,7 +129,5 @@ });

});
});
describe('React classList alias', () => {
it('should be defined and be the classList function', () => {

@@ -138,7 +137,5 @@ expect(cL).to.equal(classList);

});
});
describe('React toggleClass alias', () => {
it('should be defined and be the toggleClass function', () => {

@@ -148,3 +145,2 @@ expect(tC).to.equal(toggleClass);

});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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