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

class-name-builder

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

class-name-builder - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

17

package.json
{
"name": "class-name-builder",
"version": "0.1.1",
"version": "0.1.2",
"description": "A small, chainable, immutable utility for building up class name strings in application logic",
"main": "dist/class-name-builder.js",
"scripts": {},
"scripts": {
"build": "./node_modules/browserify/bin/cmd.js -e ./src/class-name-builder.js -s class-name-builder -t babelify -o ./dist/class-name-builder.js",
"test": "./node_modules/babel/bin/babel-node.js ./node_modules/tape/bin/tape ./test/**/*"
},
"author": {

@@ -20,13 +23,7 @@ "name": "Luke William Westby",

"devDependencies": {
"babel": "5.8.23",
"babelify": "6.2.0",
"browserify": "11.0.1",
"chai": "3.2.0",
"gulp": "3.9.0",
"karma-browserify": "4.3.0",
"karma-chai": "0.1.0",
"karma-mocha": "0.2.0",
"karma-phantomjs-launcher": "0.2.1",
"phantomjs": "1.9.18",
"vinyl-source-stream": "1.1.0"
"tape": "4.2.0"
}
}

@@ -0,112 +1,131 @@

import test from 'tape';
import ClassNameBuilder from '../src/class-name-builder.js';
describe('ClassNameBuilder', () => {
test('create()', (t) => {
t.plan(1);
describe('create()', () => {
const className = ClassNameBuilder
.create()
.toString();
it('should return an empty string from a fresh instance', () => {
ClassNameBuilder
.create()
.toString()
.should.equal('');
});
});
t.equal(className, '', 'it should return an empty string from a fresh instance');
});
describe('always()', () => {
test('always()', (t) => {
it('should return the given class names when called with always', () => {
ClassNameBuilder
.create()
.always('blue')
.toString()
.should.equal('blue');
});
t.test('basic usage', (t) => {
t.plan(1);
it('should accept an array of class names', () => {
ClassNameBuilder
.create()
.always(['blue', 'green'])
.toString()
.should.equal('blue green');
});
const className = ClassNameBuilder
.create()
.always('blue')
.toString();
it('should split strings on spaces', () => {
ClassNameBuilder
.create()
.always('blue green')
.toString()
.should.equal('blue green')
});
t.equal(className, 'blue', 'it should return the given class names when called with always');
});
it('should remove duplicates', () => {
ClassNameBuilder
.create()
.always('blue green blue')
.toString()
.should.equal('blue green');
});
});
t.test('array input', (t) => {
t.plan(1);
describe('if()', () => {
const className = ClassNameBuilder
.create()
.always(['blue', 'green'])
.toString();
it('should return a class name under an if statement only if the condition is true', () => {
t.equal(className, 'blue green', 'it should accept an array of class names');
});
ClassNameBuilder
.create()
.if(true, 'true')
.if(false, 'false')
.toString()
.should.equal('true');
});
});
t.test('string splitting', (t) => {
t.plan(1);
describe('else()', () => {
const className = ClassNameBuilder
.create()
.always('blue green')
.toString();
it('should return a class name under the else branch of an if statement if the condition is false', () => {
ClassNameBuilder
.create()
.if(false, 'false').else('true')
.toString()
.should.equal('true');
});
t.equal(className, 'blue green', 'it should split strings on spaces');
});
it('should not return a class name under an else branch if the condition is true', () => {
ClassNameBuilder
.create()
.if(true, 'true').else('false')
.toString()
.should.equal('true');
});
t.test('deduping', (t) => {
t.plan(1);
it('should throw an error if else is called before if', () => {
(() => {
ClassNameBuilder
.create()
.else('not gonna work');
}).should.throw;
});
});
const className = ClassNameBuilder
.create()
.always('blue green blue')
.toString();
describe('merge()', () => {
t.equal(className, 'blue green', 'it should remove duplicates');
});
});
it('should include class names from one builder into another', () => {
test('if()', (t) => {
t.plan(1);
const firstBuilder = ClassNameBuilder.create().always('first');
const secondBuilder = ClassNameBuilder.create().always('second');
const mergedBuilder = firstBuilder.merge(secondBuilder);
const className = ClassNameBuilder
.create()
.if(true, 'true')
.if(false, 'false')
.toString();
mergedBuilder
.toString()
.should.equal('first second');
});
t.equal(className, 'true', 'it should return a class name under an if statement only if the condition is true');
});
it('should throw if something other than a ClassNameBuilder is passed', () => {
test('else()', (t) => {
const builder = ClassNameBuilder.create();
t.test('false if() value', (t) => {
t.plan(1);
(() => {
builder.merge(1);
}).should.throw;
});
});
const className = ClassNameBuilder
.create()
.if(false, 'false').else('true')
.toString();
t.equal(className, 'true', 'it should return a class name under the else branch of an if statement if the condition is false');
});
t.test('true if() value', (t) => {
t.plan(1);
const className = ClassNameBuilder
.create()
.if(true, 'true').else('false')
.toString();
t.equal(className, 'true', 'it should not return a class name under an else branch if the condition is true');
});
t.test('incorrect usage', (t) => {
t.plan(1);
const badUsage = () => {
ClassNameBuilder
.create()
.else('not gonna work');
};
t.throws(badUsage, 'it should throw an error if else is called before if');
});
});
test('merge()', (t) => {
t.test('basic usage', (t) => {
t.plan(1);
const firstBuilder = ClassNameBuilder.create().always('first');
const secondBuilder = ClassNameBuilder.create().always('second');
const mergedBuilder = firstBuilder.merge(secondBuilder);
const className = mergedBuilder.toString();
t.equal(className, 'first second', 'it should include class names from one builder into another');
});
t.test('incorrect usage', (t) => {
t.plan(1);
const builder = ClassNameBuilder.create();
const badUsage = () => builder.merge(1);
t.throws(badUsage, 'it should throw if something other than a ClassNameBuilder is passed')
})
});

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