react-string-replace-recursively
Advanced tools
Comparing version 0.1.24 to 0.1.25
@@ -5,3 +5,5 @@ 'use strict'; | ||
var _ = require('lodash'); | ||
var omit = require('lodash.omit'); | ||
var identity = require('lodash.identity'); | ||
var keys = require('lodash.keys'); | ||
var substituteHelper = require('./substituteHelper'); | ||
@@ -16,3 +18,3 @@ | ||
var patternIds = _.keys(remnantConfig); | ||
var patternIds = keys(remnantConfig); | ||
@@ -30,3 +32,3 @@ var createNewRowKey = function createNewRowKey(i) { | ||
var tail = _.omit(remnantConfig, headId); | ||
var tail = omit(remnantConfig, headId); | ||
@@ -38,3 +40,3 @@ var nonMatcherFn = function nonMatcherFn(text, i) { | ||
var rightFlankNonMatcherTextFn = headValue.rightFlankNonMatcherTextFn || _.identity; | ||
var rightFlankNonMatcherTextFn = headValue.rightFlankNonMatcherTextFn || identity; | ||
var rightFlankNonMatcherFn = function rightFlankNonMatcherFn(text, i) { | ||
@@ -46,6 +48,6 @@ var x = rightFlankNonMatcherTextFn(text); | ||
var matcherFn = function matcherFn(text, i) { | ||
var textFn = headValue.textFn || _.identity; | ||
var textFn = headValue.textFn || identity; | ||
var newText = textFn(text); | ||
var toIgnore = headValue.ignore || []; | ||
var matcherTail = _.omit(tail, toIgnore); | ||
var matcherTail = omit(tail, toIgnore); | ||
@@ -52,0 +54,0 @@ var newRowKey = createNewRowKey(i); |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var _ = require('lodash'); | ||
var reduce = require('lodash.reduce'); | ||
// PATTERN MUST BE SUCH THAT MATCHES ARE NOT REMOVED IN SPLIT | ||
@@ -14,3 +14,3 @@ var _isEven = function _isEven(n) { | ||
var arr = text.split(pattern); | ||
return _.reduce(arr, function (acc, ele, i) { | ||
return reduce(arr, function (acc, ele, i) { | ||
var next = void 0; | ||
@@ -17,0 +17,0 @@ if (_isEven(i)) { |
{ | ||
"name": "react-string-replace-recursively", | ||
"version": "0.1.24", | ||
"version": "0.1.25", | ||
"description": "replace strings that match a particular pattern with a React Component, recursively", | ||
@@ -43,4 +43,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"lodash": "^4.11.1" | ||
"lodash.identity": "^3.0.0", | ||
"lodash.keys": "^4.0.6", | ||
"lodash.omit": "^4.2.1", | ||
"lodash.reduce": "^4.3.0" | ||
} | ||
} |
@@ -13,9 +13,9 @@ # React String Replace Recursively | ||
pattern: /(#[a-z\d][\w-]*)/ig, | ||
matcherFn: function (rawText, processed) { | ||
return <Link to={"tags/" + rawText}>{processed}</Link> | ||
matcherFn: function (rawText, processed, key) { | ||
return <Link key={key} to={"tags/" + rawText}>{processed}</Link> | ||
}, | ||
'searchTerm': { | ||
pattern: /(chair)/ig, | ||
matcherFn: function (rawText, processed) { | ||
return <span className='search-term-match'>{processed}</span> | ||
matcherFn: function (rawText, processed, key) { | ||
return <span key={key} className='search-term-match'>{processed}</span> | ||
} | ||
@@ -34,5 +34,5 @@ } | ||
["I appreciate a good ", | ||
<Link to={"tags/#chairback"}> | ||
<Link key={'0-1'} to={"tags/#chairback"}> | ||
["#", | ||
<span className='search-term-match'>"chair"</span>, | ||
<span key={'0-1-1'} className='search-term-match'>"chair"</span>, | ||
"back"] | ||
@@ -45,3 +45,3 @@ </Link>, | ||
Note that the `matcherFn` has two parameters : `rawText` and `processed`. | ||
Note that the `matcherFn` has three parameters : `rawText`, `processed` and `key`. | ||
The `rawText` corresponds to the section of the string which matches the pattern. | ||
@@ -51,2 +51,5 @@ The `processsed` parameter, however, corresponds to the result of replacing other patterns which occur within `rawText`. | ||
The `key` is a string that will be unique for any substring of `inputString` that gets replaced. | ||
Be sure to include it within the `key` prop of the returned React component as we did in this example, for React asks that components in an array are provided with unique keys. | ||
## English Description | ||
@@ -53,0 +56,0 @@ |
@@ -1,2 +0,4 @@ | ||
const _ = require('lodash') | ||
const omit = require('lodash.omit') | ||
const identity = require('lodash.identity') | ||
const keys = require('lodash.keys') | ||
const substituteHelper = require('./substituteHelper') | ||
@@ -9,3 +11,3 @@ | ||
const patternIds = _.keys(remnantConfig) | ||
const patternIds = keys(remnantConfig) | ||
@@ -23,3 +25,3 @@ const createNewRowKey = function (i) { | ||
const tail = _.omit(remnantConfig, headId) | ||
const tail = omit(remnantConfig, headId) | ||
@@ -31,3 +33,3 @@ const nonMatcherFn = function (text, i) { | ||
const rightFlankNonMatcherTextFn = headValue.rightFlankNonMatcherTextFn || _.identity; | ||
const rightFlankNonMatcherTextFn = headValue.rightFlankNonMatcherTextFn || identity; | ||
const rightFlankNonMatcherFn = function (text, i) { | ||
@@ -39,6 +41,6 @@ const x = rightFlankNonMatcherTextFn(text) | ||
const matcherFn = function (text, i) { | ||
const textFn = (headValue.textFn || _.identity) | ||
const textFn = (headValue.textFn || identity) | ||
const newText = textFn(text) | ||
const toIgnore = headValue.ignore || []; | ||
const matcherTail = _.omit(tail, toIgnore) | ||
const matcherTail = omit(tail, toIgnore) | ||
@@ -45,0 +47,0 @@ const newRowKey = createNewRowKey(i) |
@@ -1,9 +0,8 @@ | ||
const _ = require('lodash'); | ||
const reduce = require('lodash.reduce'); | ||
// PATTERN MUST BE SUCH THAT MATCHES ARE NOT REMOVED IN SPLIT | ||
const _isEven = n => n % 2 === 0 | ||
module.exports = function(text, pattern, matcherFn, nonMatcherFn, rightFlankNonMatcherFn) { | ||
const arr = text.split(pattern) | ||
return _.reduce(arr, function (acc, ele, i) { | ||
return reduce(arr, function (acc, ele, i) { | ||
let next; | ||
@@ -10,0 +9,0 @@ if (_isEven(i)) { |
const expect = require('chai').expect; | ||
const _ = require('lodash') | ||
const patternReplacerCreator = require('../lib/patternReplacerCreator') | ||
@@ -4,0 +3,0 @@ |
const expect = require('chai').expect | ||
const substituteHelper = require('../lib/substituteHelper') | ||
const _ = require('lodash') | ||
@@ -19,3 +18,3 @@ describe('substituteHelper', function () { | ||
const pattern = /(#[a-z\d][\w-]*)/ig // pattern for hashtag | ||
const matcherFn = function (input) { return {match: _.toUpper(input)} }; | ||
const matcherFn = function (input) { return {match: input.toUpperCase()} }; | ||
const nonMatcherFn = function (input) { return [input] } | ||
@@ -22,0 +21,0 @@ const result = substituteHelper(input, pattern, matcherFn, nonMatcherFn, nonMatcherFn) |
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
16656
208
128
4
+ Addedlodash.identity@^3.0.0
+ Addedlodash.keys@^4.0.6
+ Addedlodash.omit@^4.2.1
+ Addedlodash.reduce@^4.3.0
+ Addedlodash.identity@3.0.0(transitive)
+ Addedlodash.keys@4.2.0(transitive)
+ Addedlodash.omit@4.5.0(transitive)
+ Addedlodash.reduce@4.6.0(transitive)
- Removedlodash@^4.11.1
- Removedlodash@4.17.21(transitive)