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

strings

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

strings - npm Package Compare versions

Comparing version 0.1.4 to 0.2.0

bower.json

62

index.js
/**
* Sellside
* Strings <https://github.com/sellside/strings>
*
* Sellside <http://www.sellside.com>
* Created and maintained by Jon Schlinkert and Brian Woodward
*
* Copyright (c) 2013 Sellside.
* Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward
* Licensed under the MIT License (MIT).
*/
module.exports = require('./lib');
'use strict';
var _ = require('lodash');
var Strings = require('./lib/strings');
var _instance = null;
var strings = module.exports = function(structure, data) {
_instance = null;
strings.instance();
if (data) {
_instance.use(data);
}
return _instance.run(structure);
};
strings.instance = function (structure) {
if (_instance === null ) {
return _instance = new Strings({
structure: structure
});
}
return _instance;
};
strings.use = function (middleware) {
return strings.instance().use(middleware);
};
strings.exclude = function (middleware) {
return strings.instance().exclude(middleware);
};
strings.context = function () {
return strings.instance().context();
};
strings.patterns = function () {
return strings.instance().patterns();
};
strings.run = function (structure, options) {
return strings.instance().run(structure, options);
};
strings.Pattern = require('./lib/pattern');
// middleware
var middleware = require('./lib/middleware');
_.map(middleware, function(value, key) {
strings[key] = value;
});

100

lib/middleware/dates.js
/**
* Sellside
* Strings <https://github.com/sellside/strings>
*
* Sellside <http://www.sellside.com>
* Created and maintained by Jon Schlinkert and Brian Woodward
*
* Copyright (c) 2013 Sellside.
* Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward
* Licensed under the MIT License (MIT).

@@ -37,54 +34,69 @@ */

/**
* Date patterns
*/
var datePatterns = {
// Full date
'date': new Pattern(/:\bdate\b/, slugified(formatter("YYYY/MM/DD"), slugify)),
'date': new Pattern(/:\bdate\b/, slugified(formatter("YYYY/MM/DD"), slugify)),
// Long date formats
'L': new Pattern(/:\bL\b/, slugified(formatter("MM/DD/YYYY"), slugify)),
'1': new Pattern(/:\b1\b/, slugified(formatter("M/D/YYYY"), slugify)),
'L': new Pattern(/:\bL\b/, slugified(formatter("MM/DD/YYYY"), slugify)),
'1': new Pattern(/:\b1\b/, slugified(formatter("M/D/YYYY"), slugify)),
// Year (2013, 13)
'year': new Pattern(/:\byear\b/, slugified(formatter("YYYY"), slugify)),
'YYYY': new Pattern(/:\bYYYY\b/, slugified(formatter("YYYY"), slugify)),
'YY': new Pattern(/:\bYY\b/, slugified(formatter("YY"), slugify)),
'year': new Pattern(/:\byear\b/, slugified(formatter("YYYY"), slugify)),
'YYYY': new Pattern(/:\bYYYY\b/, slugified(formatter("YYYY"), slugify)),
'YY': new Pattern(/:\bYY\b/, slugified(formatter("YY"), slugify)),
// Month name (January, Jan)
'monthname': new Pattern(/:\bmonthname\b/,slugified(formatter("MMMM"), slugify)),
'MMMM': new Pattern(/:\bMMMM\b/, slugified(formatter("MMMM"), slugify)),
'MMM': new Pattern(/:\bMMM\b/, slugified(formatter("MMM"), slugify)),
'monthname': new Pattern(/:\bmonthname\b/, slugified(formatter("MMMM"), slugify)),
'MMMM': new Pattern(/:\bMMMM\b/, slugified(formatter("MMMM"), slugify)),
'MMM': new Pattern(/:\bMMM\b/, slugified(formatter("MMM"), slugify)),
// Month number (1, 01)
'month': new Pattern(/:\bmonth\b/, slugified(formatter("MM"), slugify)),
'MM': new Pattern(/:\bMM\b/, slugified(formatter("MM"), slugify)),
'mo': new Pattern(/:\bmo\b/, slugified(formatter("MM"), slugify)),
'M': new Pattern(/:\bM\b/, slugified(formatter("M"), slugify)),
'month': new Pattern(/:\bmonth\b/, slugified(formatter("MM"), slugify)),
'MM': new Pattern(/:\bMM\b/, slugified(formatter("MM"), slugify)),
'mo': new Pattern(/:\bmo\b/, slugified(formatter("MM"), slugify)),
'M': new Pattern(/:\bM\b/, slugified(formatter("M"), slugify)),
// Day of the year
'DDDD': new Pattern(/:\bDDDD\b/, slugified(formatter("DDDD"), slugify)),
'DDD': new Pattern(/:\bDDD\b/, slugified(formatter("DDD"), slugify)),
'DDDD': new Pattern(/:\bDDDD\b/, slugified(formatter("DDDD"), slugify)),
'DDD': new Pattern(/:\bDDD\b/, slugified(formatter("DDD"), slugify)),
// Day of the month
'day': new Pattern(/:\bday\b/, slugified(formatter("DD"), slugify)),
'DD': new Pattern(/:\bDD\b/, slugified(formatter("DD"), slugify)),
'D': new Pattern(/:\bD\b/, slugified(formatter("D"), slugify)),
'day': new Pattern(/:\bday\b/, slugified(formatter("DD"), slugify)),
'DD': new Pattern(/:\bDD\b/, slugified(formatter("DD"), slugify)),
'D': new Pattern(/:\bD\b/, slugified(formatter("D"), slugify)),
// Day of the week (wednesday/wed)
'dddd': new Pattern(/:\bdddd\b/, slugified(formatter("dddd"), slugify)),
'ddd': new Pattern(/:\bddd\b/, slugified(formatter("ddd"), slugify)),
'dd': new Pattern(/:\bdd\b/, slugified(formatter("dd"), slugify)),
'd': new Pattern(/:\bd\b/, slugified(formatter("d"), slugify)),
'dddd': new Pattern(/:\bdddd\b/, slugified(formatter("dddd"), slugify)),
'ddd': new Pattern(/:\bddd\b/, slugified(formatter("ddd"), slugify)),
'dd': new Pattern(/:\bdd\b/, slugified(formatter("dd"), slugify)),
'd': new Pattern(/:\bd\b/, slugified(formatter("d"), slugify)),
// Hour
'hour': new Pattern(/:\bhour\b/, slugified(formatter("HH"), slugify)),
'HH': new Pattern(/:\bHH\b/, slugified(formatter("HH"), slugify)),
'H': new Pattern(/:\bH\b/, slugified(formatter("H"), slugify)),
'hh': new Pattern(/:\bhh\b/, slugified(formatter("hh"), slugify)),
'h': new Pattern(/:\bh\b/, slugified(formatter("h"), slugify)),
'hour': new Pattern(/:\bhour\b/, slugified(formatter("HH"), slugify)),
'HH': new Pattern(/:\bHH\b/, slugified(formatter("HH"), slugify)),
'H': new Pattern(/:\bH\b/, slugified(formatter("H"), slugify)),
'hh': new Pattern(/:\bhh\b/, slugified(formatter("hh"), slugify)),
'h': new Pattern(/:\bh\b/, slugified(formatter("h"), slugify)),
// Minute
'minute': new Pattern(/:\bminute\b/, slugified(formatter("mm"), slugify)),
'min': new Pattern(/:\bmin\b/, slugified(formatter("mm"), slugify)),
'mm': new Pattern(/:\bmm\b/, slugified(formatter("mm"), slugify)),
'm': new Pattern(/:\bm\b/, slugified(formatter("m"), slugify)),
'minute': new Pattern(/:\bminute\b/, slugified(formatter("mm"), slugify)),
'min': new Pattern(/:\bmin\b/, slugified(formatter("mm"), slugify)),
'mm': new Pattern(/:\bmm\b/, slugified(formatter("mm"), slugify)),
'm': new Pattern(/:\bm\b/, slugified(formatter("m"), slugify)),
// Second
'second': new Pattern(/:\bsecond\b/, slugified(formatter("ss"), slugify)),
'sec': new Pattern(/:\bsec\b/, slugified(formatter("ss"), slugify)),
'ss': new Pattern(/:\bss\b/, slugified(formatter("ss"), slugify)),
's': new Pattern(/:\bs\b/, slugified(formatter("s"), slugify)),
'second': new Pattern(/:\bsecond\b/, slugified(formatter("ss"), slugify)),
'sec': new Pattern(/:\bsec\b/, slugified(formatter("ss"), slugify)),
'ss': new Pattern(/:\bss\b/, slugified(formatter("ss"), slugify)),
's': new Pattern(/:\bs\b/, slugified(formatter("s"), slugify)),
// AM/PM, am/pm
'A': new Pattern(/:\bA\b/, slugified(formatter("A"), slugify)),
'a': new Pattern(/:\ba\b/, slugified(formatter("a"), slugify)),
'P': new Pattern(/:\bP\b/, slugified(formatter("P"), slugify)),
'p': new Pattern(/:\bp\b/, slugified(formatter("p"), slugify))
'A': new Pattern(/:\bA\b/, slugified(formatter("A"), slugify)),
'a': new Pattern(/:\ba\b/, slugified(formatter("a"), slugify)),
'P': new Pattern(/:\bP\b/, slugified(formatter("P"), slugify)),
'p': new Pattern(/:\bp\b/, slugified(formatter("p"), slugify))
};

@@ -91,0 +103,0 @@

/**
* Sellside
* Strings <https://github.com/sellside/strings>
*
* Sellside <http://www.sellside.com>
* Created and maintained by Jon Schlinkert and Brian Woodward
*
* Copyright (c) 2013 Sellside.
* Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward
* Licensed under the MIT License (MIT).

@@ -9,0 +6,0 @@ */

/**
* Sellside
* Strings <https://github.com/sellside/strings>
*
* Sellside <http://www.sellside.com>
* Created and maintained by Jon Schlinkert and Brian Woodward
*
* Copyright (c) 2013 Sellside.
* Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward
* Licensed under the MIT License (MIT).

@@ -9,0 +6,0 @@ */

/**
* Sellside
* Strings <https://github.com/sellside/strings>
*
* Sellside <http://www.sellside.com>
* Created and maintained by Jon Schlinkert and Brian Woodward
*
* Copyright (c) 2013 Sellside.
* Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward
* Licensed under the MIT License (MIT).
*/
'use strict';
var _s = require('underscore.string');

@@ -11,0 +11,0 @@ var url = require('url');

/**
* Sellside
* Strings <https://github.com/sellside/strings>
*
* Sellside <http://www.sellside.com>
* Created and maintained by Jon Schlinkert and Brian Woodward
*
* Copyright (c) 2013 Sellside.
* Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward
* Licensed under the MIT License (MIT).

@@ -9,0 +6,0 @@ */

/**
* Sellside
* Strings <https://github.com/sellside/strings>
*
* Sellside <http://www.sellside.com>
* Created and maintained by Jon Schlinkert and Brian Woodward
*
* Copyright (c) 2013 Sellside.
* Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward
* Licensed under the MIT License (MIT).

@@ -18,18 +15,14 @@ */

var Strings = module.exports = function (structure, options) {
if (_.isPlainObject(structure)) {
options = structure;
this.structure = '';
} else {
this.structure = structure || '';
}
this.options = options || {};
this.middleware = [];
};
var Strings = module.exports = function (config) {
this.config = config || {};
this.options = config.options || {};
this.structure = config.structure || '';
this.middleware = config.middleware || [];
};
var wrap = function (ctx) {
return function () {
return ctx;
};
return function () {
return ctx;
};
};

@@ -44,12 +37,12 @@ var ensureMiddleware = function (middleware) {

var extend = function (middleware) {
return function (context) {
return _.extend(context, ensureMiddleware(middleware)());
};
return function (context) {
return _.extend(context, ensureMiddleware(middleware)());
};
};
var remove = function (middleware) {
return function (context) {
return _.omit(context, ensureMiddleware(middleware)());
};
return function (context) {
return _.omit(context, ensureMiddleware(middleware)());
};
};

@@ -74,10 +67,37 @@ Strings.prototype.use = function (middleware) {

var context = this.context();
/**
* @param { RegExp,String } key String or RegExp pattern to find strings to replace
* @param { String|Function } value Replacement string or function
* @example `new RegExp( pattern ), replacement )`
*
* @return {String} Returns the transformed string.
* @api Public
*/
var patterns = _.map(context, function (value, key) {
// if the value is a Pattern
// it's already in the correct format
if (value instanceof Pattern) {
// if replacement is a function, make sure it runs
// with the correct context
if (_.isFunction(value.replacement)) {
var fn = value.replacement;
value.replacement = function () {
return fn.apply(context, [].slice(arguments));
};
}
return value;
}
return new Pattern(
new RegExp(':\\b' + key + '\\b'), // pattern
value // replacement
);
// if value is a function, make sure it runs
// with the correct context
if (_.isFunction(value)) {
var fn = value;
value = function () {
return fn.apply(context, [].slice(arguments));
};
}
return new Pattern(new RegExp(':\\b' + key + '\\b'), value );
});

@@ -84,0 +104,0 @@ return patterns;

{
"name": "strings",
"version": "0.1.4",
"description": "Manipulate and rename strings using patterns, structures and presets.",
"version": "0.2.0",
"description": "String replacement and transformation library.",
"main": "index.js",

@@ -27,3 +27,3 @@ "scripts": {

"type": "MIT",
"url": "https://github.com/assemble/example-pagination/blob/master/LICENSE-MIT"
"url": "https://github.com/sellside/strings/blob/master/LICENSE-MIT"
}

@@ -48,5 +48,15 @@ ],

"keywords": [
"date",
"find",
"middleware",
"modify",
"regex",
"RegExp",
"regular expressions",
"replace",
"scrub",
"string",
"strings",
"string"
"transform"
]
}

@@ -1,5 +0,43 @@

# strings
# Strings [![NPM version](https://badge.fury.io/js/strings.png)](http://badge.fury.io/js/strings)
> Manipulate and rename strings using patterns, structures and presets
> Powerful and easy-to-use string generation and transformation library.
Please [report any bugs or feature requests](https://github.com/sellside/strings/issues/new), thanks!
## Install
### [npm](npmjs.org)
```bash
npm i strings --save
```
### [bower](https://github.com/bower/bower)
```bash
bower install strings --save
```
## Getting started
Main concepts:
1. `structures`: a sort of template that tells Strings how to assemble your data into a formatted string.
2. `patterns`: patterns tell Strings how to parse and tokenize structures. Patterns may be simple strings or RegExp.
3. `data`: data source that Strings will use to replace the tokens into the provided structure
4. `replacements`: string or function used to tranform the data
_(TODO)_
## API
_(TODO)_
### middleware
_(TODO)_
## Author

@@ -10,2 +48,7 @@

+ [github.com/doowb](https://github.com/doowb)
+ [twitter.com/doowb](http://twitter.com/doowb)
+ [twitter.com/doowb](http://twitter.com/doowb)
## License
Copyright (c) 2014 Brian Woodward, contributors.
Released under the MIT license
{
"instrumentation": "node-jscoverage",
"sloc": 103,
"hits": 99,
"sloc": 101,
"hits": 97,
"misses": 4,
"coverage": 96.11650485436894,
"coverage": 96.03960396039604,
"files": [
{
"filename": "c:/Work/sellside/strings/lib/index.js",
"coverage": 100,
"hits": 9,
"misses": 0,
"sloc": 9,
"source": {
"1": {
"source": "/**",
"coverage": ""
},
"2": {
"source": " * Sellside",
"coverage": ""
},
"3": {
"source": " *",
"coverage": ""
},
"4": {
"source": " * Sellside <http://www.sellside.com>",
"coverage": ""
},
"5": {
"source": " * Created and maintained by Jon Schlinkert and Brian Woodward",
"coverage": ""
},
"6": {
"source": " *",
"coverage": ""
},
"7": {
"source": " * Copyright (c) 2013 Sellside.",
"coverage": ""
},
"8": {
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
},
"9": {
"source": " */",
"coverage": ""
},
"10": {
"source": "",
"coverage": ""
},
"11": {
"source": "'use strict';",
"coverage": 1
},
"12": {
"source": "",
"coverage": ""
},
"13": {
"source": "var _ = require('lodash');",
"coverage": 1
},
"14": {
"source": "",
"coverage": ""
},
"15": {
"source": "var Strings = require('./strings');",
"coverage": 1
},
"16": {
"source": "",
"coverage": ""
},
"17": {
"source": "var strings = module.exports = function(structure, options) {",
"coverage": 1
},
"18": {
"source": " return new Strings(structure, options);",
"coverage": 19
},
"19": {
"source": "};",
"coverage": ""
},
"20": {
"source": "",
"coverage": ""
},
"21": {
"source": "strings.Pattern = require('./pattern');",
"coverage": 1
},
"22": {
"source": "",
"coverage": ""
},
"23": {
"source": "// middleware",
"coverage": ""
},
"24": {
"source": "var middleware = require('./middleware');",
"coverage": 1
},
"25": {
"source": "_.map(middleware, function(value, key) {",
"coverage": 1
},
"26": {
"source": " strings[key] = value;",
"coverage": 3
},
"27": {
"source": "});",
"coverage": ""
}
}
},
{
"filename": "c:/Work/sellside/strings/lib/middleware/dates.js",

@@ -137,3 +20,3 @@ "coverage": 100,

"2": {
"source": " * Sellside",
"source": " * Strings <https://github.com/sellside/strings>",
"coverage": ""

@@ -146,366 +29,414 @@ },

"4": {
"source": " * Sellside <http://www.sellside.com>",
"source": " * Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward",
"coverage": ""
},
"5": {
"source": " * Created and maintained by Jon Schlinkert and Brian Woodward",
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
},
"6": {
"source": " *",
"source": " */",
"coverage": ""
},
"7": {
"source": " * Copyright (c) 2013 Sellside.",
"source": "",
"coverage": ""
},
"8": {
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
},
"9": {
"source": " */",
"coverage": ""
},
"10": {
"source": "",
"coverage": ""
},
"11": {
"source": "'use strict';",
"coverage": 1
},
"12": {
"9": {
"source": "",
"coverage": ""
},
"13": {
"10": {
"source": "var _s = require('underscore.string');",
"coverage": 1
},
"14": {
"11": {
"source": "var moment = require('moment');",
"coverage": 1
},
"15": {
"12": {
"source": "",
"coverage": ""
},
"16": {
"13": {
"source": "var Pattern = require('../pattern');",
"coverage": 1
},
"17": {
"14": {
"source": "",
"coverage": ""
},
"18": {
"15": {
"source": "var slugified = function(str, slugify) {",
"coverage": 1
},
"19": {
"16": {
"source": " return slugify ? _s.slugify(str) : str;",
"coverage": 39
},
"20": {
"17": {
"source": "};",
"coverage": ""
},
"21": {
"18": {
"source": "",
"coverage": ""
},
"22": {
"19": {
"source": "var format = function(d, options) {",
"coverage": 1
},
"23": {
"20": {
"source": " moment.lang(options.lang);",
"coverage": 1
},
"24": {
"21": {
"source": " return function(f) {",
"coverage": 1
},
"25": {
"22": {
"source": " return moment(d).format(f);",
"coverage": 39
},
"26": {
"23": {
"source": " };",
"coverage": ""
},
"27": {
"24": {
"source": "};",
"coverage": ""
},
"28": {
"25": {
"source": "",
"coverage": ""
},
"29": {
"26": {
"source": "var dates = module.exports = function(d, options) {",
"coverage": 1
},
"30": {
"27": {
"source": "",
"coverage": ""
},
"31": {
"28": {
"source": " options = options || { slugify: false };",
"coverage": 1
},
"32": {
"29": {
"source": " var slugify = ((typeof options.slugify === 'undefined') || options.slugify === false) ? false : true;",
"coverage": 1
},
"33": {
"30": {
"source": " options.lang = options.lang || 'en';",
"coverage": 1
},
"34": {
"31": {
"source": "",
"coverage": ""
},
"35": {
"32": {
"source": " var formatter = format(d, options);",
"coverage": 1
},
"33": {
"source": "",
"coverage": ""
},
"34": {
"source": " /**",
"coverage": ""
},
"35": {
"source": " * Date patterns",
"coverage": ""
},
"36": {
"source": " */",
"coverage": ""
},
"37": {
"source": "",
"coverage": ""
},
"37": {
"38": {
"source": " var datePatterns = {",
"coverage": 1
},
"38": {
"39": {
"source": " // Full date",
"coverage": ""
},
"39": {
"source": " 'date': new Pattern(/:\\bdate\\b/, slugified(formatter(\"YYYY/MM/DD\"), slugify)),",
"coverage": ""
},
"40": {
"source": " // Long date formats",
"source": " 'date': new Pattern(/:\\bdate\\b/, slugified(formatter(\"YYYY/MM/DD\"), slugify)),",
"coverage": ""
},
"41": {
"source": " 'L': new Pattern(/:\\bL\\b/, slugified(formatter(\"MM/DD/YYYY\"), slugify)),",
"source": "",
"coverage": ""
},
"42": {
"source": " '1': new Pattern(/:\\b1\\b/, slugified(formatter(\"M/D/YYYY\"), slugify)),",
"source": " // Long date formats",
"coverage": ""
},
"43": {
"source": " // Year (2013, 13)",
"source": " 'L': new Pattern(/:\\bL\\b/, slugified(formatter(\"MM/DD/YYYY\"), slugify)),",
"coverage": ""
},
"44": {
"source": " 'year': new Pattern(/:\\byear\\b/, slugified(formatter(\"YYYY\"), slugify)),",
"source": " '1': new Pattern(/:\\b1\\b/, slugified(formatter(\"M/D/YYYY\"), slugify)),",
"coverage": ""
},
"45": {
"source": " 'YYYY': new Pattern(/:\\bYYYY\\b/, slugified(formatter(\"YYYY\"), slugify)),",
"source": "",
"coverage": ""
},
"46": {
"source": " 'YY': new Pattern(/:\\bYY\\b/, slugified(formatter(\"YY\"), slugify)),",
"source": " // Year (2013, 13)",
"coverage": ""
},
"47": {
"source": " // Month name (January, Jan)",
"source": " 'year': new Pattern(/:\\byear\\b/, slugified(formatter(\"YYYY\"), slugify)),",
"coverage": ""
},
"48": {
"source": " 'monthname': new Pattern(/:\\bmonthname\\b/,slugified(formatter(\"MMMM\"), slugify)),",
"source": " 'YYYY': new Pattern(/:\\bYYYY\\b/, slugified(formatter(\"YYYY\"), slugify)),",
"coverage": ""
},
"49": {
"source": " 'MMMM': new Pattern(/:\\bMMMM\\b/, slugified(formatter(\"MMMM\"), slugify)),",
"source": " 'YY': new Pattern(/:\\bYY\\b/, slugified(formatter(\"YY\"), slugify)),",
"coverage": ""
},
"50": {
"source": " 'MMM': new Pattern(/:\\bMMM\\b/, slugified(formatter(\"MMM\"), slugify)),",
"source": "",
"coverage": ""
},
"51": {
"source": " // Month number (1, 01)",
"source": " // Month name (January, Jan)",
"coverage": ""
},
"52": {
"source": " 'month': new Pattern(/:\\bmonth\\b/, slugified(formatter(\"MM\"), slugify)),",
"source": " 'monthname': new Pattern(/:\\bmonthname\\b/, slugified(formatter(\"MMMM\"), slugify)),",
"coverage": ""
},
"53": {
"source": " 'MM': new Pattern(/:\\bMM\\b/, slugified(formatter(\"MM\"), slugify)),",
"source": " 'MMMM': new Pattern(/:\\bMMMM\\b/, slugified(formatter(\"MMMM\"), slugify)),",
"coverage": ""
},
"54": {
"source": " 'mo': new Pattern(/:\\bmo\\b/, slugified(formatter(\"MM\"), slugify)),",
"source": " 'MMM': new Pattern(/:\\bMMM\\b/, slugified(formatter(\"MMM\"), slugify)),",
"coverage": ""
},
"55": {
"source": " 'M': new Pattern(/:\\bM\\b/, slugified(formatter(\"M\"), slugify)),",
"source": "",
"coverage": ""
},
"56": {
"source": " // Day of the year",
"source": " // Month number (1, 01)",
"coverage": ""
},
"57": {
"source": " 'DDDD': new Pattern(/:\\bDDDD\\b/, slugified(formatter(\"DDDD\"), slugify)),",
"source": " 'month': new Pattern(/:\\bmonth\\b/, slugified(formatter(\"MM\"), slugify)),",
"coverage": ""
},
"58": {
"source": " 'DDD': new Pattern(/:\\bDDD\\b/, slugified(formatter(\"DDD\"), slugify)),",
"source": " 'MM': new Pattern(/:\\bMM\\b/, slugified(formatter(\"MM\"), slugify)),",
"coverage": ""
},
"59": {
"source": " // Day of the month",
"source": " 'mo': new Pattern(/:\\bmo\\b/, slugified(formatter(\"MM\"), slugify)),",
"coverage": ""
},
"60": {
"source": " 'day': new Pattern(/:\\bday\\b/, slugified(formatter(\"DD\"), slugify)),",
"source": " 'M': new Pattern(/:\\bM\\b/, slugified(formatter(\"M\"), slugify)),",
"coverage": ""
},
"61": {
"source": " 'DD': new Pattern(/:\\bDD\\b/, slugified(formatter(\"DD\"), slugify)),",
"source": "",
"coverage": ""
},
"62": {
"source": " 'D': new Pattern(/:\\bD\\b/, slugified(formatter(\"D\"), slugify)),",
"source": " // Day of the year",
"coverage": ""
},
"63": {
"source": " // Day of the week (wednesday/wed)",
"source": " 'DDDD': new Pattern(/:\\bDDDD\\b/, slugified(formatter(\"DDDD\"), slugify)),",
"coverage": ""
},
"64": {
"source": " 'dddd': new Pattern(/:\\bdddd\\b/, slugified(formatter(\"dddd\"), slugify)),",
"source": " 'DDD': new Pattern(/:\\bDDD\\b/, slugified(formatter(\"DDD\"), slugify)),",
"coverage": ""
},
"65": {
"source": " 'ddd': new Pattern(/:\\bddd\\b/, slugified(formatter(\"ddd\"), slugify)),",
"source": "",
"coverage": ""
},
"66": {
"source": " 'dd': new Pattern(/:\\bdd\\b/, slugified(formatter(\"dd\"), slugify)),",
"source": " // Day of the month",
"coverage": ""
},
"67": {
"source": " 'd': new Pattern(/:\\bd\\b/, slugified(formatter(\"d\"), slugify)),",
"source": " 'day': new Pattern(/:\\bday\\b/, slugified(formatter(\"DD\"), slugify)),",
"coverage": ""
},
"68": {
"source": " // Hour",
"source": " 'DD': new Pattern(/:\\bDD\\b/, slugified(formatter(\"DD\"), slugify)),",
"coverage": ""
},
"69": {
"source": " 'hour': new Pattern(/:\\bhour\\b/, slugified(formatter(\"HH\"), slugify)),",
"source": " 'D': new Pattern(/:\\bD\\b/, slugified(formatter(\"D\"), slugify)),",
"coverage": ""
},
"70": {
"source": " 'HH': new Pattern(/:\\bHH\\b/, slugified(formatter(\"HH\"), slugify)),",
"source": "",
"coverage": ""
},
"71": {
"source": " 'H': new Pattern(/:\\bH\\b/, slugified(formatter(\"H\"), slugify)),",
"source": " // Day of the week (wednesday/wed)",
"coverage": ""
},
"72": {
"source": " 'hh': new Pattern(/:\\bhh\\b/, slugified(formatter(\"hh\"), slugify)),",
"source": " 'dddd': new Pattern(/:\\bdddd\\b/, slugified(formatter(\"dddd\"), slugify)),",
"coverage": ""
},
"73": {
"source": " 'h': new Pattern(/:\\bh\\b/, slugified(formatter(\"h\"), slugify)),",
"source": " 'ddd': new Pattern(/:\\bddd\\b/, slugified(formatter(\"ddd\"), slugify)),",
"coverage": ""
},
"74": {
"source": " // Minute",
"source": " 'dd': new Pattern(/:\\bdd\\b/, slugified(formatter(\"dd\"), slugify)),",
"coverage": ""
},
"75": {
"source": " 'minute': new Pattern(/:\\bminute\\b/, slugified(formatter(\"mm\"), slugify)),",
"source": " 'd': new Pattern(/:\\bd\\b/, slugified(formatter(\"d\"), slugify)),",
"coverage": ""
},
"76": {
"source": " 'min': new Pattern(/:\\bmin\\b/, slugified(formatter(\"mm\"), slugify)),",
"source": "",
"coverage": ""
},
"77": {
"source": " 'mm': new Pattern(/:\\bmm\\b/, slugified(formatter(\"mm\"), slugify)),",
"source": " // Hour",
"coverage": ""
},
"78": {
"source": " 'm': new Pattern(/:\\bm\\b/, slugified(formatter(\"m\"), slugify)),",
"source": " 'hour': new Pattern(/:\\bhour\\b/, slugified(formatter(\"HH\"), slugify)),",
"coverage": ""
},
"79": {
"source": " // Second",
"source": " 'HH': new Pattern(/:\\bHH\\b/, slugified(formatter(\"HH\"), slugify)),",
"coverage": ""
},
"80": {
"source": " 'second': new Pattern(/:\\bsecond\\b/, slugified(formatter(\"ss\"), slugify)),",
"source": " 'H': new Pattern(/:\\bH\\b/, slugified(formatter(\"H\"), slugify)),",
"coverage": ""
},
"81": {
"source": " 'sec': new Pattern(/:\\bsec\\b/, slugified(formatter(\"ss\"), slugify)),",
"source": " 'hh': new Pattern(/:\\bhh\\b/, slugified(formatter(\"hh\"), slugify)),",
"coverage": ""
},
"82": {
"source": " 'ss': new Pattern(/:\\bss\\b/, slugified(formatter(\"ss\"), slugify)),",
"source": " 'h': new Pattern(/:\\bh\\b/, slugified(formatter(\"h\"), slugify)),",
"coverage": ""
},
"83": {
"source": " 's': new Pattern(/:\\bs\\b/, slugified(formatter(\"s\"), slugify)),",
"source": "",
"coverage": ""
},
"84": {
"source": " // AM/PM, am/pm",
"source": " // Minute",
"coverage": ""
},
"85": {
"source": " 'A': new Pattern(/:\\bA\\b/, slugified(formatter(\"A\"), slugify)),",
"source": " 'minute': new Pattern(/:\\bminute\\b/, slugified(formatter(\"mm\"), slugify)),",
"coverage": ""
},
"86": {
"source": " 'a': new Pattern(/:\\ba\\b/, slugified(formatter(\"a\"), slugify)),",
"source": " 'min': new Pattern(/:\\bmin\\b/, slugified(formatter(\"mm\"), slugify)),",
"coverage": ""
},
"87": {
"source": " 'P': new Pattern(/:\\bP\\b/, slugified(formatter(\"P\"), slugify)),",
"source": " 'mm': new Pattern(/:\\bmm\\b/, slugified(formatter(\"mm\"), slugify)),",
"coverage": ""
},
"88": {
"source": " 'p': new Pattern(/:\\bp\\b/, slugified(formatter(\"p\"), slugify))",
"source": " 'm': new Pattern(/:\\bm\\b/, slugified(formatter(\"m\"), slugify)),",
"coverage": ""
},
"89": {
"source": " };",
"source": "",
"coverage": ""
},
"90": {
"source": "",
"source": " // Second",
"coverage": ""
},
"91": {
"source": " 'second': new Pattern(/:\\bsecond\\b/, slugified(formatter(\"ss\"), slugify)),",
"coverage": ""
},
"92": {
"source": " 'sec': new Pattern(/:\\bsec\\b/, slugified(formatter(\"ss\"), slugify)),",
"coverage": ""
},
"93": {
"source": " 'ss': new Pattern(/:\\bss\\b/, slugified(formatter(\"ss\"), slugify)),",
"coverage": ""
},
"94": {
"source": " 's': new Pattern(/:\\bs\\b/, slugified(formatter(\"s\"), slugify)),",
"coverage": ""
},
"95": {
"source": "",
"coverage": ""
},
"92": {
"96": {
"source": " // AM/PM, am/pm",
"coverage": ""
},
"97": {
"source": " 'A': new Pattern(/:\\bA\\b/, slugified(formatter(\"A\"), slugify)),",
"coverage": ""
},
"98": {
"source": " 'a': new Pattern(/:\\ba\\b/, slugified(formatter(\"a\"), slugify)),",
"coverage": ""
},
"99": {
"source": " 'P': new Pattern(/:\\bP\\b/, slugified(formatter(\"P\"), slugify)),",
"coverage": ""
},
"100": {
"source": " 'p': new Pattern(/:\\bp\\b/, slugified(formatter(\"p\"), slugify))",
"coverage": ""
},
"101": {
"source": " };",
"coverage": ""
},
"102": {
"source": "",
"coverage": ""
},
"103": {
"source": "",
"coverage": ""
},
"104": {
"source": " return function() {",
"coverage": 1
},
"93": {
"105": {
"source": " return datePatterns;",
"coverage": 40
},
"94": {
"106": {
"source": " };",
"coverage": ""
},
"95": {
"107": {
"source": "};",

@@ -528,3 +459,3 @@ "coverage": ""

"2": {
"source": " * Sellside",
"source": " * Strings <https://github.com/sellside/strings>",
"coverage": ""

@@ -537,46 +468,34 @@ },

"4": {
"source": " * Sellside <http://www.sellside.com>",
"source": " * Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward",
"coverage": ""
},
"5": {
"source": " * Created and maintained by Jon Schlinkert and Brian Woodward",
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
},
"6": {
"source": " *",
"source": " */",
"coverage": ""
},
"7": {
"source": " * Copyright (c) 2013 Sellside.",
"source": "",
"coverage": ""
},
"8": {
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
},
"9": {
"source": " */",
"coverage": ""
},
"10": {
"source": "",
"coverage": ""
},
"11": {
"source": "module.exports = {",
"coverage": 1
},
"12": {
"9": {
"source": " dates: require('./dates'),",
"coverage": ""
},
"13": {
"10": {
"source": " paths: require('./paths'),",
"coverage": ""
},
"14": {
"11": {
"source": " urls: require('./urls')",
"coverage": ""
},
"15": {
"12": {
"source": "};",

@@ -599,3 +518,3 @@ "coverage": ""

"2": {
"source": " * Sellside",
"source": " * Strings <https://github.com/sellside/strings>",
"coverage": ""

@@ -608,122 +527,110 @@ },

"4": {
"source": " * Sellside <http://www.sellside.com>",
"source": " * Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward",
"coverage": ""
},
"5": {
"source": " * Created and maintained by Jon Schlinkert and Brian Woodward",
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
},
"6": {
"source": " *",
"source": " */",
"coverage": ""
},
"7": {
"source": " * Copyright (c) 2013 Sellside.",
"source": "",
"coverage": ""
},
"8": {
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
},
"9": {
"source": " */",
"coverage": ""
},
"10": {
"source": "",
"coverage": ""
},
"11": {
"source": "'use strict';",
"coverage": 1
},
"12": {
"9": {
"source": "",
"coverage": ""
},
"13": {
"10": {
"source": "var _s = require('underscore.string');",
"coverage": 1
},
"14": {
"11": {
"source": "var path = require('path');",
"coverage": 1
},
"15": {
"12": {
"source": "",
"coverage": ""
},
"16": {
"13": {
"source": "var paths = module.exports = function(filePath, options) {",
"coverage": 1
},
"17": {
"14": {
"source": "",
"coverage": ""
},
"18": {
"15": {
"source": " options = options || { slugify: false };",
"coverage": 3
},
"19": {
"16": {
"source": " var slugify = ((typeof options.slugify !== 'undefined') && options.slugify === false) ? false : true;",
"coverage": 3
},
"20": {
"17": {
"source": "",
"coverage": ""
},
"21": {
"18": {
"source": " var dir = path.dirname(filePath);",
"coverage": 3
},
"22": {
"19": {
"source": " var ext = path.extname(filePath);",
"coverage": 3
},
"23": {
"20": {
"source": " var filename = path.basename(filePath);",
"coverage": 3
},
"24": {
"21": {
"source": " var basename = path.basename(filePath, ext);",
"coverage": 3
},
"25": {
"22": {
"source": "",
"coverage": ""
},
"26": {
"23": {
"source": " return function() {",
"coverage": 3
},
"27": {
"24": {
"source": " return {",
"coverage": 48
},
"28": {
"25": {
"source": " basename: slugify ? _s.slugify(basename) : basename,",
"coverage": ""
},
"29": {
"26": {
"source": " filename: slugify ? _s.slugify(filename) : filename,",
"coverage": ""
},
"30": {
"27": {
"source": " ext: slugify ? _s.slugify(ext) : ext,",
"coverage": ""
},
"31": {
"28": {
"source": " dir: slugify ? _s.slugify(dir) : dir",
"coverage": ""
},
"32": {
"29": {
"source": " };",
"coverage": ""
},
"33": {
"30": {
"source": " };",
"coverage": ""
},
"34": {
"31": {
"source": "};",

@@ -737,5 +644,5 @@ "coverage": ""

"coverage": 100,
"hits": 14,
"hits": 15,
"misses": 0,
"sloc": 14,
"sloc": 15,
"source": {

@@ -747,3 +654,3 @@ "1": {

"2": {
"source": " * Sellside",
"source": " * Strings <https://github.com/sellside/strings>",
"coverage": ""

@@ -756,23 +663,23 @@ },

"4": {
"source": " * Sellside <http://www.sellside.com>",
"source": " * Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward",
"coverage": ""
},
"5": {
"source": " * Created and maintained by Jon Schlinkert and Brian Woodward",
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
},
"6": {
"source": " *",
"source": " */",
"coverage": ""
},
"7": {
"source": " * Copyright (c) 2013 Sellside.",
"source": "",
"coverage": ""
},
"8": {
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
"source": "'use strict';",
"coverage": 1
},
"9": {
"source": " */",
"source": "",
"coverage": ""

@@ -902,3 +809,3 @@ },

"2": {
"source": " * Sellside",
"source": " * Strings <https://github.com/sellside/strings>",
"coverage": ""

@@ -911,50 +818,38 @@ },

"4": {
"source": " * Sellside <http://www.sellside.com>",
"source": " * Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward",
"coverage": ""
},
"5": {
"source": " * Created and maintained by Jon Schlinkert and Brian Woodward",
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
},
"6": {
"source": " *",
"source": " */",
"coverage": ""
},
"7": {
"source": " * Copyright (c) 2013 Sellside.",
"source": "",
"coverage": ""
},
"8": {
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
},
"9": {
"source": " */",
"coverage": ""
},
"10": {
"source": "",
"coverage": ""
},
"11": {
"source": "'use strict';",
"coverage": 1
},
"12": {
"9": {
"source": "",
"coverage": ""
},
"13": {
"10": {
"source": "var Pattern = module.exports = function(pattern, replacement) {",
"coverage": 1
},
"14": {
"11": {
"source": " this.pattern = pattern;",
"coverage": 262
"coverage": 267
},
"15": {
"12": {
"source": " this.replacement = replacement;",
"coverage": 262
"coverage": 267
},
"16": {
"13": {
"source": "};",

@@ -967,6 +862,6 @@ "coverage": ""

"filename": "c:/Work/sellside/strings/lib/strings.js",
"coverage": 91.11111111111111,
"hits": 41,
"coverage": 92.15686274509804,
"hits": 47,
"misses": 4,
"sloc": 45,
"sloc": 51,
"source": {

@@ -978,3 +873,3 @@ "1": {

"2": {
"source": " * Sellside",
"source": " * Strings <https://github.com/sellside/strings>",
"coverage": ""

@@ -987,31 +882,31 @@ },

"4": {
"source": " * Sellside <http://www.sellside.com>",
"source": " * Copyright (c) 2014 Sellside, Jon Schlinkert and Brian Woodward",
"coverage": ""
},
"5": {
"source": " * Created and maintained by Jon Schlinkert and Brian Woodward",
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
},
"6": {
"source": " *",
"source": " */",
"coverage": ""
},
"7": {
"source": " * Copyright (c) 2013 Sellside.",
"source": "",
"coverage": ""
},
"8": {
"source": " * Licensed under the MIT License (MIT).",
"coverage": ""
"source": "'use strict';",
"coverage": 1
},
"9": {
"source": " */",
"source": "",
"coverage": ""
},
"10": {
"source": "",
"coverage": ""
"source": "var _ = require('lodash');",
"coverage": 1
},
"11": {
"source": "'use strict';",
"source": "var frep = require('frep');",
"coverage": 1

@@ -1024,83 +919,83 @@ },

"13": {
"source": "var _ = require('lodash');",
"source": "var Pattern = require('./pattern');",
"coverage": 1
},
"14": {
"source": "var frep = require('frep');",
"coverage": 1
},
"15": {
"source": "",
"coverage": ""
},
"16": {
"source": "var Pattern = require('./pattern');",
"15": {
"source": "var Strings = module.exports = function (config) {",
"coverage": 1
},
"16": {
"source": " this.config = config || {};",
"coverage": 21
},
"17": {
"source": "",
"coverage": ""
"source": " this.options = config.options || {};",
"coverage": 21
},
"18": {
"source": "var Strings = module.exports = function (structure, options) {",
"coverage": 1
"source": " this.structure = config.structure || '';",
"coverage": 21
},
"19": {
"source": " if (_.isPlainObject(structure)) {",
"coverage": 19
"source": " this.middleware = config.middleware || [];",
"coverage": 21
},
"20": {
"source": " options = structure;",
"coverage": 1
"source": "};",
"coverage": ""
},
"21": {
"source": " this.structure = '';",
"coverage": 1
"source": "",
"coverage": ""
},
"22": {
"source": " } else {",
"coverage": ""
"source": "var wrap = function (ctx) {",
"coverage": 1
},
"23": {
"source": " this.structure = structure || '';",
"coverage": 18
"source": " return function () {",
"coverage": 1
},
"24": {
"source": " }",
"coverage": ""
"source": " return ctx;",
"coverage": 1
},
"25": {
"source": " this.options = options || {};",
"coverage": 19
"source": " };",
"coverage": ""
},
"26": {
"source": " this.middleware = [];",
"coverage": 19
"source": "};",
"coverage": ""
},
"27": {
"source": " };",
"source": "",
"coverage": ""
},
"28": {
"source": "",
"coverage": ""
"source": "var ensureMiddleware = function (middleware) {",
"coverage": 1
},
"29": {
"source": "var wrap = function (ctx) {",
"coverage": 1
"source": " if (_.isFunction(middleware) === false) {",
"coverage": 101
},
"30": {
"source": " return function () {",
"coverage": 0
"source": " return wrap(middleware);",
"coverage": 1
},
"31": {
"source": " return ctx;",
"coverage": 0
"source": " }",
"coverage": ""
},
"32": {
"source": " };",
"coverage": ""
"source": " return middleware;",
"coverage": 100
},
"33": {
"source": " };",
"source": "};",
"coverage": ""

@@ -1113,226 +1008,306 @@ },

"35": {
"source": "var ensureMiddleware = function (middleware) {",
"source": "var extend = function (middleware) {",
"coverage": 1
},
"36": {
"source": " if (_.isFunction(middleware) === false) {",
"coverage": 98
"source": " return function (context) {",
"coverage": 19
},
"37": {
"source": " return wrap(middleware);",
"coverage": 0
"source": " return _.extend(context, ensureMiddleware(middleware)());",
"coverage": 99
},
"38": {
"source": " }",
"source": " };",
"coverage": ""
},
"39": {
"source": " return middleware;",
"coverage": 98
},
"40": {
"source": "};",
"coverage": ""
},
"41": {
"40": {
"source": "",
"coverage": ""
},
"42": {
"source": "var extend = function (middleware) {",
"41": {
"source": "var remove = function (middleware) {",
"coverage": 1
},
"42": {
"source": " return function (context) {",
"coverage": 5
},
"43": {
"source": " return function (context) {",
"coverage": 16
"source": " return _.omit(context, ensureMiddleware(middleware)());",
"coverage": 2
},
"44": {
"source": " return _.extend(context, ensureMiddleware(middleware)());",
"coverage": 96
"source": " };",
"coverage": ""
},
"45": {
"source": " };",
"source": "};",
"coverage": ""
},
"46": {
"source": " };",
"source": "",
"coverage": ""
},
"47": {
"source": "",
"coverage": ""
"source": "Strings.prototype.use = function (middleware) {",
"coverage": 1
},
"48": {
"source": "var remove = function (middleware) {",
"coverage": 1
"source": " this.middleware.push(extend(middleware));",
"coverage": 19
},
"49": {
"source": " return function (context) {",
"coverage": 5
"source": " return this;",
"coverage": 19
},
"50": {
"source": " return _.omit(context, ensureMiddleware(middleware)());",
"coverage": 2
"source": "};",
"coverage": ""
},
"51": {
"source": " };",
"source": "",
"coverage": ""
},
"52": {
"source": " };",
"coverage": ""
"source": "Strings.prototype.exclude = function (middleware) {",
"coverage": 1
},
"53": {
"source": "",
"coverage": ""
"source": " this.middleware.push(remove(middleware));",
"coverage": 5
},
"54": {
"source": "Strings.prototype.use = function (middleware) {",
"coverage": 1
"source": " return this;",
"coverage": 5
},
"55": {
"source": " this.middleware.push(extend(middleware));",
"coverage": 16
"source": "};",
"coverage": ""
},
"56": {
"source": " return this;",
"coverage": 16
"source": "",
"coverage": ""
},
"57": {
"source": "};",
"coverage": ""
"source": "Strings.prototype.context = function () {",
"coverage": 1
},
"58": {
"source": "",
"coverage": ""
"source": " return _.reduce(this.middleware, function (ctx, middleware) {",
"coverage": 78
},
"59": {
"source": "Strings.prototype.exclude = function (middleware) {",
"coverage": 1
"source": " return middleware(ctx);",
"coverage": 101
},
"60": {
"source": " this.middleware.push(remove(middleware));",
"coverage": 5
"source": " }, {});",
"coverage": ""
},
"61": {
"source": " return this;",
"coverage": 5
},
"62": {
"source": "};",
"coverage": ""
},
"63": {
"62": {
"source": "",
"coverage": ""
},
"64": {
"source": "Strings.prototype.context = function () {",
"63": {
"source": "Strings.prototype.patterns = function () {",
"coverage": 1
},
"64": {
"source": " var context = this.context();",
"coverage": 76
},
"65": {
"source": " return _.reduce(this.middleware, function (ctx, middleware) {",
"coverage": 56
"source": "",
"coverage": ""
},
"66": {
"source": " return middleware(ctx);",
"coverage": 98
"source": " /**",
"coverage": ""
},
"67": {
"source": " }, {});",
"source": " * @param { RegExp,String } key String or RegExp pattern to find strings to replace",
"coverage": ""
},
"68": {
"source": "};",
"source": " * @param { String|Function } value Replacement string or function",
"coverage": ""
},
"69": {
"source": "",
"source": " * @example `new RegExp( pattern ), replacement )`",
"coverage": ""
},
"70": {
"source": "Strings.prototype.patterns = function () {",
"coverage": 1
"source": " *",
"coverage": ""
},
"71": {
"source": " var context = this.context();",
"coverage": 54
"source": " * @return {String} Returns the transformed string.",
"coverage": ""
},
"72": {
"source": " var patterns = _.map(context, function (value, key) {",
"coverage": 54
"source": " * @api Public",
"coverage": ""
},
"73": {
"source": " if (value instanceof Pattern) {",
"coverage": 1783
"source": " */",
"coverage": ""
},
"74": {
"source": " return value;",
"coverage": 1560
"source": " var patterns = _.map(context, function (value, key) {",
"coverage": 76
},
"75": {
"source": " }",
"source": "",
"coverage": ""
},
"76": {
"source": " return new Pattern(",
"coverage": 223
"source": " // if the value is a Pattern",
"coverage": ""
},
"77": {
"source": " new RegExp(':\\\\b' + key + '\\\\b'), // pattern",
"source": " // it's already in the correct format",
"coverage": ""
},
"78": {
"source": " value // replacement",
"coverage": ""
"source": " if (value instanceof Pattern) {",
"coverage": 1788
},
"79": {
"source": " );",
"source": "",
"coverage": ""
},
"80": {
"source": " // if replacement is a function, make sure it runs",
"coverage": ""
},
"81": {
"source": " // with the correct context",
"coverage": ""
},
"82": {
"source": " if (_.isFunction(value.replacement)) {",
"coverage": 1561
},
"83": {
"source": " var fn = value.replacement;",
"coverage": 1
},
"84": {
"source": " value.replacement = function () {",
"coverage": 1
},
"85": {
"source": " return fn.apply(context, [].slice(arguments));",
"coverage": 1
},
"86": {
"source": " };",
"coverage": ""
},
"87": {
"source": " }",
"coverage": ""
},
"88": {
"source": " return value;",
"coverage": 1561
},
"89": {
"source": " }",
"coverage": ""
},
"90": {
"source": "",
"coverage": ""
},
"91": {
"source": " // if value is a function, make sure it runs",
"coverage": ""
},
"92": {
"source": " // with the correct context",
"coverage": ""
},
"93": {
"source": " if (_.isFunction(value)) {",
"coverage": 227
},
"94": {
"source": " var fn = value;",
"coverage": 0
},
"95": {
"source": " value = function () {",
"coverage": 0
},
"96": {
"source": " return fn.apply(context, [].slice(arguments));",
"coverage": 0
},
"97": {
"source": " };",
"coverage": ""
},
"98": {
"source": " }",
"coverage": ""
},
"99": {
"source": " return new Pattern(new RegExp(':\\\\b' + key + '\\\\b'), value );",
"coverage": 227
},
"100": {
"source": " });",
"coverage": ""
},
"81": {
"101": {
"source": " return patterns;",
"coverage": 54
"coverage": 76
},
"82": {
"102": {
"source": "};",
"coverage": ""
},
"83": {
"103": {
"source": "",
"coverage": ""
},
"84": {
"104": {
"source": "Strings.prototype.run = function (structure, options) {",
"coverage": 1
},
"85": {
"105": {
"source": " if (_.isPlainObject(structure)) {",
"coverage": 54
"coverage": 76
},
"86": {
"106": {
"source": " options = structure;",
"coverage": 0
},
"87": {
"107": {
"source": " } else {",
"coverage": ""
},
"88": {
"108": {
"source": " this.structure = structure || this.structure || '';",
"coverage": 54
"coverage": 76
},
"89": {
"109": {
"source": " }",
"coverage": ""
},
"90": {
"110": {
"source": " return frep.strWithArr(this.structure, this.patterns());",
"coverage": 54
"coverage": 76
},
"91": {
"111": {
"source": "};",

@@ -1345,10 +1320,10 @@ "coverage": ""

"stats": {
"suites": 12,
"tests": 64,
"passes": 64,
"suites": 13,
"tests": 66,
"passes": 66,
"pending": 0,
"failures": 0,
"start": "2014-01-20T03:29:11.227Z",
"end": "2014-01-20T03:29:11.263Z",
"duration": 36
"start": "2014-03-09T16:02:54.096Z",
"end": "2014-03-09T16:02:54.127Z",
"duration": 31
},

@@ -1394,3 +1369,3 @@ "tests": [

"fullTitle": "middleware dates should replace :monthname",
"duration": 1
"duration": 0
},

@@ -1405,3 +1380,3 @@ {

"fullTitle": "middleware dates should replace :MMM",
"duration": 0
"duration": 1
},

@@ -1456,3 +1431,3 @@ {

"fullTitle": "middleware dates should replace :dddd",
"duration": 1
"duration": 0
},

@@ -1467,3 +1442,3 @@ {

"fullTitle": "middleware dates should replace :dd",
"duration": 0
"duration": 1
},

@@ -1478,3 +1453,3 @@ {

"fullTitle": "middleware dates should replace :hour",
"duration": 5
"duration": 0
},

@@ -1519,3 +1494,3 @@ {

"fullTitle": "middleware dates should replace :m",
"duration": 0
"duration": 1
},

@@ -1525,3 +1500,3 @@ {

"fullTitle": "middleware dates should replace :second",
"duration": 1
"duration": 0
},

@@ -1556,3 +1531,3 @@ {

"fullTitle": "middleware dates should replace :P",
"duration": 1
"duration": 0
},

@@ -1605,5 +1580,10 @@ {

{
"title": "should convert structure to string given an object",
"fullTitle": "strings default should convert structure to string given an object",
"duration": 0
},
{
"title": "should save the structure",
"fullTitle": "strings structure should save the structure",
"duration": 1
"duration": 0
},

@@ -1633,3 +1613,3 @@ {

"fullTitle": "strings middleware should add middleware with exclude",
"duration": 1
"duration": 0
},

@@ -1644,3 +1624,3 @@ {

"fullTitle": "strings middleware should build context from middleware with exclusions",
"duration": 0
"duration": 1
},

@@ -1678,2 +1658,7 @@ {

{
"title": "should run replacement functions with `context` as `this`",
"fullTitle": "strings run should run replacement functions with `context` as `this`",
"duration": 0
},
{
"title": "should replace :protocol",

@@ -1729,3 +1714,3 @@ "fullTitle": "middleware urls should replace :protocol",

"fullTitle": "middleware dates should replace :monthname",
"duration": 1
"duration": 0
},

@@ -1740,3 +1725,3 @@ {

"fullTitle": "middleware dates should replace :MMM",
"duration": 0
"duration": 1
},

@@ -1791,3 +1776,3 @@ {

"fullTitle": "middleware dates should replace :dddd",
"duration": 1
"duration": 0
},

@@ -1802,3 +1787,3 @@ {

"fullTitle": "middleware dates should replace :dd",
"duration": 0
"duration": 1
},

@@ -1813,3 +1798,3 @@ {

"fullTitle": "middleware dates should replace :hour",
"duration": 5
"duration": 0
},

@@ -1854,3 +1839,3 @@ {

"fullTitle": "middleware dates should replace :m",
"duration": 0
"duration": 1
},

@@ -1860,3 +1845,3 @@ {

"fullTitle": "middleware dates should replace :second",
"duration": 1
"duration": 0
},

@@ -1891,3 +1876,3 @@ {

"fullTitle": "middleware dates should replace :P",
"duration": 1
"duration": 0
},

@@ -1940,5 +1925,10 @@ {

{
"title": "should convert structure to string given an object",
"fullTitle": "strings default should convert structure to string given an object",
"duration": 0
},
{
"title": "should save the structure",
"fullTitle": "strings structure should save the structure",
"duration": 1
"duration": 0
},

@@ -1968,3 +1958,3 @@ {

"fullTitle": "strings middleware should add middleware with exclude",
"duration": 1
"duration": 0
},

@@ -1979,3 +1969,3 @@ {

"fullTitle": "strings middleware should build context from middleware with exclusions",
"duration": 0
"duration": 1
},

@@ -2013,2 +2003,7 @@ {

{
"title": "should run replacement functions with `context` as `this`",
"fullTitle": "strings run should run replacement functions with `context` as `this`",
"duration": 0
},
{
"title": "should replace :protocol",

@@ -2015,0 +2010,0 @@ "fullTitle": "middleware urls should replace :protocol",

@@ -27,7 +27,9 @@ /**

before(function(){
structure = strings()
.use(strings.dates(now))
.use(strings.paths('test/actual/structure_date/index.html'));
strings();
structure = strings
.instance()
.use(strings.dates(now))
.use(strings.paths('test/actual/structure_date/index.html'));
});
// YYYY/MM/DD

@@ -322,7 +324,7 @@ it('should replace :date', function() {

});
});
describe('dates-slugify', function() {
var now = new Date();

@@ -333,5 +335,4 @@ var structure = null;

});
});
});

@@ -22,3 +22,4 @@ /**

before(function(){
structure = strings().use(strings.paths(filePath));
strings();
structure = strings.instance().use(strings.paths(filePath));
});

@@ -57,3 +58,4 @@

before(function() {
structure = strings().use(strings.paths(filePath, { slugify: true }));
strings();
structure = strings.instance().use(strings.paths(filePath, { slugify: true }));
});

@@ -60,0 +62,0 @@

@@ -16,37 +16,18 @@ /**

var assert = require('chai').assert;
var slice = Array.prototype.slice;
var meld = require('meld');
var _ = require('lodash');
var utils = require('./utils');
utils.logging = false;
var strings = require('../');
var advices = {
before: function () {
utils.log('Called with: ' + Array.prototype.join.call(arguments));
}
};
var strings = meld(require('../'), advices);
var Strings = meld(require('../lib/strings'), advices);
var getStrings = function (structure, options) {
if (utils.logging) {
var args = [Strings].concat(slice.call(arguments));
return utils.create(args);
}
return strings(structure, options);
};
var pathMiddleware = function (path) {
return function () {
return {
basename: basename(path, extname(path)),
ext: extname(path)
};
return function () {
return {
basename: basename(path, extname(path)),
ext: extname(path)
};
};
};
var excludeMiddleware = function () {
return ['ext'];
};
return ['ext'];
};

@@ -58,6 +39,20 @@ var testStructure = '/:basename/index:ext';

describe('default', function() {
it('should convert structure to string given an object', function() {
var expected = '/file/index.html';
var actual = strings(testStructure, {
basename: 'file',
ext: '.html'
});
expect(actual).to.eql(expected);
});
});
describe('structure', function () {
it('should save the structure', function () {
var structure = getStrings(testStructure);
strings(testStructure);
var structure = strings.instance();
expect(structure.structure).to.equal(testStructure);

@@ -67,3 +62,4 @@ });

it('should have an empty structure', function () {
var structure = getStrings();
strings();
var structure = strings.instance();
expect(structure.structure).to.equal('');

@@ -73,3 +69,4 @@ });

it('should have an empty structure when options are passed in', function () {
var structure = getStrings({});
strings();
var structure = strings.instance();
expect(structure.structure).to.equal('');

@@ -79,3 +76,4 @@ });

it('should save the structure when options are passed in', function () {
var structure = getStrings(testStructure, {});
strings(testStructure);
var structure = strings.instance();
expect(structure.structure).to.equal(testStructure);

@@ -89,3 +87,4 @@ });

it('should add middleware with use', function () {
var structure = getStrings(testStructure);
strings(testStructure);
var structure = strings.instance();
structure.use(pathMiddleware('path/to/some/file.html'));

@@ -96,3 +95,4 @@ expect(structure.middleware.length).to.equal(1);

it('should add middleware with exclude', function () {
var structure = getStrings(testStructure);
strings(testStructure);
var structure = strings.instance();
structure.use(pathMiddleware('path/to/some/file.html'));

@@ -104,4 +104,4 @@ structure.exclude(excludeMiddleware);

it('should build context from middleware', function () {
var structure = getStrings(testStructure);
structure.use(pathMiddleware('path/to/some/file.html'));
strings(testStructure);
strings.use(pathMiddleware('path/to/some/file.html'));
var expected = {

@@ -111,3 +111,3 @@ basename: 'file',

};
var actual = structure.context();
var actual = strings.context();
expect(actual).to.eql(expected);

@@ -117,9 +117,9 @@ });

it('should build context from middleware with exclusions', function () {
var structure = getStrings(testStructure);
structure.use(pathMiddleware('path/to/some/file.html'));
structure.exclude(excludeMiddleware);
strings(testStructure);
strings.use(pathMiddleware('path/to/some/file.html'));
strings.exclude(excludeMiddleware);
var expected = {
basename: 'file'
};
var actual = structure.context();
var actual = strings.context();
expect(actual).to.eql(expected);

@@ -129,3 +129,4 @@ });

it('should add middleware with use as object', function () {
var structure = getStrings(testStructure);
strings(testStructure);
var structure = strings.instance();
structure.use({

@@ -138,3 +139,4 @@ foo: 'bar'

it('should add middleware with exclude as object', function () {
var structure = getStrings(testStructure);
strings(testStructure);
var structure = strings.instance();
structure.use(pathMiddleware('path/to/some/file.html'));

@@ -148,3 +150,4 @@ structure.exclude({

it('should add middlware with exclude as array', function () {
var structure = getStrings(testStructure);
strings(testStructure);
var structure = strings.instance();
structure.use(pathMiddleware('path/to/some/file.html'));

@@ -161,6 +164,6 @@ structure.exclude(['basename']);

it('should build the final string with no exclusions', function () {
var structure = getStrings(testStructure);
structure.use(pathMiddleware('path/to/some/file.html'));
strings(testStructure);
strings.use(pathMiddleware('path/to/some/file.html'));
var expected = '/file/index.html';
var actual = structure.run();
var actual = strings.run();
expect(actual).to.eql(expected);

@@ -170,8 +173,8 @@ });

it('should build the final string with exclusions', function () {
var structure = getStrings(testStructure);
structure.use(pathMiddleware('path/to/some/file.html'));
structure.exclude(excludeMiddleware);
strings(testStructure);
strings.use(pathMiddleware('path/to/some/file.html'));
strings.exclude(excludeMiddleware);
var expected = '/file/index:ext';
var actual = structure.run();
var actual = strings.run();
expect(actual).to.eql(expected);

@@ -181,16 +184,34 @@ });

it('should build the final string from a one time setup', function () {
var structure = getStrings();
structure.use(pathMiddleware('path/to/some/file.html'));
strings();
strings.use(pathMiddleware('path/to/some/file.html'));
var expected = 'file';
var actual = structure.run(':basename');
var actual = strings.run(':basename');
expect(actual).to.eql(expected);
expected = '.html';
actual = structure.run(':ext');
actual = strings.run(':ext');
expect(actual).to.eql(expected);
});
it('should run replacement functions with `context` as `this`', function () {
strings();
strings.use(pathMiddleware('path/to/some/file.html'));
strings.use(function () {
return [
new strings.Pattern(':BASENAME', function (src) {
//console.log(this);
return this.basename.toUpperCase();
})
];
});
var expected = 'file-FILE';
var actual = strings.run(':basename-:BASENAME');
expect(actual).to.eql(expected);
})
});
});

@@ -22,3 +22,4 @@ /**

before(function(){
structure = strings().use(strings.urls(url));
strings();
structure = strings.instance().use(strings.urls(url));
});

@@ -40,3 +41,4 @@

before(function() {
structure = strings().use(strings.urls(url, { slugify: true }));
strings();
structure = strings.instance().use(strings.urls(url, { slugify: true }));
});

@@ -43,0 +45,0 @@

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