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

replace-last

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

replace-last - npm Package Compare versions

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"
}
}
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