Comparing version 0.4.0 to 0.4.1
23
index.js
@@ -11,7 +11,10 @@ /** | ||
var replace = require('frep'); | ||
var _ = require('lodash'); | ||
var isObject = require('isobject'); | ||
var isEmpty = require('is-empty'); | ||
var flatten = require('array-flatten'); | ||
var union = require('array-union'); | ||
var extend = require('xtend'); | ||
var utils = require('./lib/utils'); | ||
/** | ||
@@ -80,3 +83,3 @@ * ## Strings | ||
Strings.prototype.propstring = function (name, str, options) { | ||
options = _.extend({}, this.options, options); | ||
options = extend({}, this.options, options); | ||
@@ -218,4 +221,4 @@ if (!str) { | ||
// if there are no parsers specified, return them all | ||
if (_.isEmpty(parsers)) { | ||
parsers = _.keys(this._parsers); | ||
if (isEmpty(parsers)) { | ||
parsers = Object.keys(this._parsers); | ||
} | ||
@@ -225,5 +228,5 @@ parsers = utils.arrayify(parsers); | ||
// find the specified parsers | ||
var arr = _.flatten(_.map(parsers, function (parser) { | ||
var arr = flatten(parsers.map(function (parser) { | ||
// if this is an actual parser object, just return it | ||
if (_.isObject(parser)) { | ||
if (isObject(parser)) { | ||
return parser; | ||
@@ -273,3 +276,3 @@ } | ||
arr = utils.arrayify(arr); | ||
var parser = _.union([], this._parsers[name], arr); | ||
var parser = union([], this._parsers[name], arr); | ||
this._parsers[name] = parser; | ||
@@ -354,3 +357,3 @@ return this; | ||
Strings.prototype.replace = function (str, context) { | ||
var ctx = _.extend({}, this.context, context); | ||
var ctx = extend({}, this.context, context); | ||
return replace.strWithArr(str, utils._bind([ | ||
@@ -406,3 +409,3 @@ { | ||
var ctx = _.extend({}, this.context, context); | ||
var ctx = extend({}, this.context, context); | ||
return replace.strWithArr(str, utils._bind(arr, ctx)); | ||
@@ -409,0 +412,0 @@ }; |
@@ -10,3 +10,5 @@ /** | ||
var _ = require('lodash'); | ||
var isEmpty = require('is-empty'); | ||
var extend = require('xtend'); | ||
var clone = require('clone'); | ||
@@ -87,3 +89,3 @@ | ||
utils._normalizeObj = function (obj) { | ||
if (_.isUndefined(obj)) return []; | ||
if (isEmpty(obj)) return []; | ||
if (obj.hasOwnProperty('pattern') | ||
@@ -94,3 +96,6 @@ && obj.hasOwnProperty('replacement')) { | ||
var arr = []; | ||
_.forOwn(obj, function (value, key) { | ||
var keys = Object.keys(obj); | ||
keys.forEach(function (key) { | ||
var value = obj[key]; | ||
arr.push({pattern: key, replacement: value}); | ||
@@ -114,7 +119,7 @@ }); | ||
utils._bind = function (replacements, context) { | ||
replacements = _.cloneDeep(utils.arrayify(replacements)); | ||
replacements = clone(utils.arrayify(replacements)); | ||
context = context || {}; | ||
return _.map(replacements, function (item) { | ||
if (_.isFunction(item.replacement)) { | ||
return replacements.map(function (item) { | ||
if (typeof item.replacement === 'function') { | ||
var fn = item.replacement; | ||
@@ -121,0 +126,0 @@ item.replacement = function () { |
{ | ||
"name": "strings", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"description": "Easily replace and transform :props in strings.", | ||
"homepage": "https://github.com/doowb/strings", | ||
"homepage": "https://github.com/assemble/strings", | ||
"repository": { | ||
@@ -14,4 +14,8 @@ "type": "git", | ||
}, | ||
"contributors": [ | ||
"maintainers": [ | ||
{ | ||
"name": "Brian Woodward", | ||
"url": "http://github.com/doowb" | ||
}, | ||
{ | ||
"name": "Jon Schlinkert", | ||
@@ -56,16 +60,17 @@ "url": "http://github.com/jonschlinkert" | ||
"dependencies": { | ||
"array-flatten": "0.0.2", | ||
"array-union": "^0.1.0", | ||
"clone": "^0.1.17", | ||
"clone-shallow": "^0.1.1", | ||
"frep": "^0.2.1", | ||
"lodash": "^2.4.1" | ||
"is-empty": "0.0.1", | ||
"isobject": "^0.1.0", | ||
"xtend": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^1.9.1", | ||
"fs-utils": "^0.4.3", | ||
"js-comments": "^0.1.0", | ||
"mocha": "^1.19.0", | ||
"parse-filepath": "^0.3.0", | ||
"relative": "^0.1.4", | ||
"verb": "^0.2.11", | ||
"verb-tag-jscomments": "^0.1.4", | ||
"verbalize": "^0.1.2" | ||
"verb-tag-jscomments": "^0.1.4" | ||
} | ||
} |
@@ -36,3 +36,3 @@ # strings [![NPM version](https://badge.fury.io/js/strings.png)](http://badge.fury.io/js/strings) | ||
* `return`{Object} Instance of a Strings object | ||
* `return` {Object} Instance of a Strings object | ||
@@ -56,3 +56,4 @@ | ||
* `propstring` {String} | ||
* `return`{Strings} to allow chaining | ||
* `return` {Strings} to allow chaining | ||
* `api` public | ||
@@ -77,3 +78,4 @@ | ||
* `flags` {String}: Optionally pass RegExp flags to use. | ||
* `return`{Strings} to allow chaining | ||
* `return` {Strings} to allow chaining | ||
* `api` public | ||
@@ -100,3 +102,4 @@ | ||
* `replacement` {String|Function}: The replacement to use when patterns are matched. | ||
* `return`{Strings} to allow chaining | ||
* `return` {Strings} to allow chaining | ||
* `api` public | ||
@@ -141,3 +144,4 @@ | ||
* `arr` {Object|Array}: Object or array of replacement patterns to associate. | ||
* `return`{Strings} to allow chaining | ||
* `return` {Strings} to allow chaining | ||
* `api` public | ||
@@ -194,3 +198,4 @@ | ||
* `parsers` {String|Array}: string or array of parsers to get. | ||
* `return`{Array} | ||
* `return` {Array} | ||
* `api` public | ||
@@ -222,3 +227,4 @@ | ||
* `replacement` {String|Function} | ||
* `return`{Strings} to allow chaining | ||
* `return` {Strings} to allow chaining | ||
* `api` public | ||
@@ -250,3 +256,4 @@ | ||
* `parsers` {Array}: Names of the parsers to use with the template. | ||
* `return`{Strings} to allow chaining | ||
* `return` {Strings} to allow chaining | ||
* `api` public | ||
@@ -275,3 +282,4 @@ | ||
* `context` {String}: The object with replacement properties. | ||
* `return`{Strings} to allow chaining | ||
* `return` {Strings} to allow chaining | ||
* `api` public | ||
@@ -305,3 +313,4 @@ | ||
* `context` {Object}: context to use. optional if a global context is passed. | ||
* `return`{String} | ||
* `return` {String} | ||
* `api` public | ||
@@ -329,3 +338,4 @@ | ||
* `context` {Object}: Optional context object, to bind to replacement function as `this` | ||
* `return`{String} | ||
* `return` {String} | ||
* `api` public | ||
@@ -332,0 +342,0 @@ |
@@ -12,3 +12,3 @@ /** | ||
var expect = require('chai').expect; | ||
var Strings = require('../'); | ||
var Strings = require('..'); | ||
@@ -15,0 +15,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
54059
4
1235
351
0
8
+ Addedarray-flatten@0.0.2
+ Addedarray-union@^0.1.0
+ Addedclone@^0.1.17
+ Addedclone-shallow@^0.1.1
+ Addedis-empty@0.0.1
+ Addedisobject@^0.1.0
+ Addedxtend@^3.0.0
+ Addedarray-flatten@0.0.2(transitive)
+ Addedarray-union@0.1.0(transitive)
+ Addedarray-uniq@0.1.1(transitive)
+ Addedclone@0.1.19(transitive)
+ Addedclone-array@0.1.2(transitive)
+ Addedclone-object@0.1.0(transitive)
+ Addedclone-shallow@0.1.1(transitive)
+ Addedis-empty@0.0.1(transitive)
+ Addedisobject@0.1.1(transitive)
+ Addedxtend@3.0.0(transitive)
- Removedlodash@^2.4.1
- Removedlodash@2.4.2(transitive)