Skip to content

Commit

Permalink
Merge pull request #56 from jaredwray/adding-in-unit-tests-and-versio…
Browse files Browse the repository at this point in the history
…n-bump

adding in unit tests and version bump
  • Loading branch information
jaredwray committed Jul 5, 2024
2 parents cd81b31 + b177743 commit bf64c31
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 43 deletions.
46 changes: 46 additions & 0 deletions lib/utils/falsey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// utils.js
function falsey(val, keywords) {
if (!val) {
return true;
}

let words = keywords || [
"0",
"false",
"nada",
"nil",
"nay",
"nah",
"negative",
"no",
"none",
"nope",
"nul",
"null",
"nix",
"nyet",
"uh-uh",
"veto",
"zero",
];

if (!Array.isArray(words)) {
words = [words];
}

const lower = typeof val === "string" ? val.toLowerCase() : null;

for (const word of words) {
if (word === val) {
return true;
}
if (word === lower) {
return true;
}
}

return false;
}

module.exports = falsey;

44 changes: 2 additions & 42 deletions lib/utils/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var utils = require('lazy-cache')(require);
var falsey = require('./falsey');
var fn = require;
require = utils;

Expand All @@ -18,48 +19,7 @@ require('kind-of', 'typeOf');
// matching utils
require('is-glob');
require('micromatch', 'mm');
utils.falsey = function falsey(val, keywords) {
if (!val) {
return true;
}

let words = keywords || [
"0",
"false",
"nada",
"nil",
"nay",
"nah",
"negative",
"no",
"none",
"nope",
"nul",
"null",
"nix",
"nyet",
"uh-uh",
"veto",
"zero",
];

if (!Array.isArray(words)) {
words = [words];
}

const lower = typeof val === "string" ? val.toLowerCase() : null;

for (const word of words) {
if (word === val) {
return true;
}
if (word === lower) {
return true;
}
}

return false;
};
utils.falsey = falsey;

// Number utils
require('is-even');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@jaredwray/fumanchu",
"description": "Handlebars + Helpers = Fumanchu",
"version": "1.4.1",
"version": "1.5.0",
"homepage": "https://github.com/jaredwray/fumanchu",
"author": "Jared Wray (me@jaredwray.com)",
"keywords": [
Expand Down
34 changes: 34 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require('mocha');
var assert = require('assert');
var utils = require('../lib/utils');
var HTML = require('../lib/utils/html');
const { expect } = require('chai');

describe('utils', function() {
describe('chop', function() {
Expand Down Expand Up @@ -37,6 +38,39 @@ describe('utils', function() {
});
});

describe('falsey', function() {
it('should return true if the value is falsey', function() {
assert(utils.falsey(''));
assert(utils.falsey('0'));
assert(utils.falsey('false'));
assert(utils.falsey('nada'));
assert(utils.falsey('nil'));
assert(utils.falsey('nay'));
assert(utils.falsey('nah'));
assert(utils.falsey('negative'));
assert(utils.falsey('no'));
assert(utils.falsey('none'));
assert(utils.falsey('nope'));
assert(utils.falsey('nul'));
assert(utils.falsey('null'));
assert(utils.falsey('nix'));
assert(utils.falsey('nyet'));
assert(utils.falsey('uh-uh'));
assert(utils.falsey('veto'));
assert(utils.falsey('zero'));
});
it('should return values on an array of keywords', function() {
assert(utils.falsey('zero', ['zero']));
assert(utils.falsey('zero'));
assert(utils.falsey('Zero'));
expect(utils.falsey('zero', ['zero', 'one'])).to.be.true;
expect(utils.falsey('Zero', ['zero', 'one'])).to.be.true;
});
it('should be false if the keywords are not not set correctly', function() {
expect(utils.falsey('false', 1)).to.be.false;
});
});

describe('html', function() {
describe('condense', function() {
it('should condense multiple newlines into a single newline', function() {
Expand Down

0 comments on commit bf64c31

Please sign in to comment.