replace-last
Advanced tools
Comparing version 1.0.2 to 1.0.3
20
index.js
'use strict'; | ||
const kindOf = require('kind-of'); | ||
const _ = require('lodash'); | ||
var escapeRegExp = require('lodash.escaperegexp'); | ||
var isRegExp = require('lodash.isregexp'); | ||
const replaceLast = function(str, pattern, replacement) { | ||
if (kindOf(str) === 'number') str = str.toString(); | ||
if (kindOf(pattern) === 'number') pattern = pattern.toString(); | ||
if (kindOf(replacement) === 'number') replacement = replacement.toString(); | ||
if (typeof(str) === 'number') str = str.toString(); | ||
if (typeof(pattern) === 'number') pattern = pattern.toString(); | ||
if (typeof(replacement) === 'number') replacement = replacement.toString(); | ||
if (kindOf(str) !== 'string') return str; | ||
if (kindOf(replacement) !== 'string') return str; | ||
if (typeof(str) !== 'string') return str; | ||
if (typeof(replacement) !== 'string') return str; | ||
if (kindOf(pattern) === 'string') { | ||
pattern = new RegExp(_.escapeRegExp(pattern), 'g'); | ||
} else if (kindOf(pattern) === 'regexp') { | ||
if (typeof(pattern) === 'string') { | ||
pattern = new RegExp(escapeRegExp(pattern), 'g'); | ||
} else if (isRegExp(pattern)) { | ||
pattern = new RegExp(pattern.source, 'g'); | ||
@@ -19,0 +19,0 @@ } else { |
{ | ||
"name": "replace-last", | ||
"version": "1.0.2", | ||
"description": "Replaces last match for pattern in string with replacement", | ||
"author": "Daniel Lewis BSc (Hons)", | ||
"version": "1.0.3", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": {}, | ||
"author": "", | ||
"license": "ISC", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/istanbul cover -x \"**/*.spec.js\" ./node_modules/mocha/bin/_mocha", | ||
"enforcer": "./node_modules/.bin/istanbul check-coverage --statement 100 --branch 100 --function 100 --line 100", | ||
"build": "npm-run-all test enforcer", | ||
"prepush": "npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/danday74/replace-last.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/danday74/replace-last/issues" | ||
}, | ||
"homepage": "https://github.com/danday74/replace-last#readme", | ||
"keywords": [], | ||
"dependencies": { | ||
"kind-of": "^6.0.0", | ||
"lodash": "^4.17.4" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.1.2", | ||
"coveralls": "2.11.16", | ||
"eslint": "^4.9.0", | ||
"husky": "^0.14.3", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^4.0.1", | ||
"npm-run-all": "^4.1.1" | ||
}, | ||
"engines": { | ||
"node": ">= 4.0.0" | ||
"lodash.escaperegexp": "^4.1.2", | ||
"lodash.isregexp": "^4.0.1" | ||
} | ||
} |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
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
0
1144
2
23
3
1
1
0
1
+ Addedlodash.escaperegexp@^4.1.2
+ Addedlodash.isregexp@^4.0.1
+ Addedlodash.escaperegexp@4.1.2(transitive)
+ Addedlodash.isregexp@4.0.1(transitive)
- Removedkind-of@^6.0.0
- Removedlodash@^4.17.4
- Removedkind-of@6.0.3(transitive)
- Removedlodash@4.17.21(transitive)