Skip to content

Commit

Permalink
remove lodash, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed May 14, 2014
1 parent 45404df commit b963320
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 29 deletions.
16 changes: 7 additions & 9 deletions lib/utils.js
@@ -1,23 +1,21 @@
const _ = require('lodash');

/**
* Export utils
*/

var utils = module.exports = {};

utils.arrayify = function(arr) {
return !Array.isArray(arr) ? [arr] : _.compact(arr);
exports.arrayify = function(arr) {
return !Array.isArray(arr) ? [arr] : arr.filter(Boolean);
};

// Build RegExp patterns for delimiters
utils.buildRegexGroup = function (re, flags) {
exports.buildRegexGroup = function (re, flags) {
// If it's already regex, return.
if(_.isRegExp(re)) {
if(re instanceof RegExp) {
return re;
}

// If it's a string or array, continue
re = utils.arrayify(re);
re = exports.arrayify(re);

var len = re.length;
re = (len > 0) ? re.join('|') : re;

Expand Down
16 changes: 4 additions & 12 deletions test/example.js
@@ -1,19 +1,11 @@
const expect = require('chai').expect;
const frep = require('../');
const _str = require('underscore.string');
const _ = require('lodash');

/**
* This is the example from the README.
* Here it is setup as a Mocha test.
*/


// We'll use underscore string's slugify function for the first example
const frep = require('../');


/**
* Setup
* This is the example from the README
* setup as a mocha test
*/

// A custom slugification function for the second
Expand Down Expand Up @@ -41,7 +33,7 @@ var obj = {
var patterns = [
{
pattern: /:foo/g,
replacement: _str.slugify(obj.foo) // underscore.string
replacement: _str.slugify(obj.foo) // underscore string's slugify function
},
{
pattern: /:bar/g,
Expand Down
11 changes: 3 additions & 8 deletions test/test.js
@@ -1,8 +1,6 @@
const path = require('path');
const expect = require('chai').expect;
const frep = require('../');
const _str = require('underscore.string');
const _ = require('lodash');


// Setup
Expand Down Expand Up @@ -38,8 +36,7 @@ describe('when a string with multiple potential matches is passed in', function
];

var actual = frep.strWithArr(template, replacements);
var expected = 'somefile';
expect(actual).to.eql(expected);
expect(actual).to.eql('somefile');
});
});

Expand All @@ -62,17 +59,15 @@ describe('when a string with multiple potential matches is passed in', function
}
];
var actual = frep.strWithArr(template, replacements);
var expected = 'C:/foo/bar/baz/:dir';
expect(actual).to.eql(expected);
expect(actual).to.eql('C:/foo/bar/baz/:dir');
});
});

describe('frep', function () {
it('should replace "foo" with "SUCCESS".', function () {
var replacements = [{pattern: /:foo/g, replacement: 'SUCCESS'}];
var actual = frep.strWithArr(':foo/:bar/:baz', replacements);
var expected = 'SUCCESS/:bar/:baz';
expect(actual).to.eql(expected);
expect(actual).to.eql('SUCCESS/:bar/:baz');
});

it('should replace the given strings with the given replacements.', function () {
Expand Down

0 comments on commit b963320

Please sign in to comment.