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

replace-in-file

Package Overview
Dependencies
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

replace-in-file - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

20

package.json
{
"name": "replace-in-file",
"version": "1.0.1",
"version": "1.0.2",
"description": "A simple utility to quickly replace text in one or more files.",

@@ -27,16 +27,20 @@ "homepage": "https://github.com/adambuczynski/replace-in-file#readme",

"scripts": {
"lint": "npm run lint:jshint --silent && npm run lint:jscs --silent",
"lint": "npm run lint:jshint -s && npm run lint:jscs -s",
"lint:jshint": "jshint . --reporter=node_modules/jshint-stylish",
"lint:jscs": "jscs . --reporter=node_modules/jscs-stylish",
"pretest": "npm run lint",
"test": "mocha test/**/*.spec.js",
"test-ci": "npm run lint && istanbul cover ./node_modules/mocha/bin/_mocha",
"preversion": "npm run test",
"postversion": "git push && git push --tags && npm publish"
"pretest": "npm run lint -s",
"istanbul": "babel-node ./node_modules/istanbul/lib/cli cover ./node_modules/mocha/bin/_mocha test/**/*.spec.js",
"test": "npm run istanbul -s",
"preversion": "npm run test -s",
"postversion": "git push && git push --tags && npm publish",
"coverage": "open -a \"Google Chrome\" ./coverage/lcov-report/index.html"
},
"devDependencies": {
"babel-cli": "^6.5.1",
"babel-preset-es2015": "^6.5.0",
"babel-register": "^6.5.2",
"bluebird": "^3.3.1",
"chai": "^3.5.0",
"chai-as-promised": "^5.2.0",
"dirty-chai": "^1.2.2",
"istanbul": "^1.0.0-alpha.2",
"jscs": "^2.9.0",

@@ -43,0 +47,0 @@ "jscs-stylish": "^0.3.1",

@@ -5,3 +5,4 @@ # Replace in file

[![node dependencies](https://david-dm.org/adambuczynski/replace-in-file.svg)](https://david-dm.org/adambuczynski/replace-in-file)
[![Build Status](https://travis-ci.org/adambuczynski/replace-in-file.svg?branch=master)](https://travis-ci.org/adambuczynski/replace-in-file)
[![build status](https://travis-ci.org/adambuczynski/replace-in-file.svg?branch=master)](https://travis-ci.org/adambuczynski/replace-in-file)
[![coverage status](https://coveralls.io/repos/github/adambuczynski/replace-in-file/badge.svg?branch=master)](https://coveralls.io/github/adambuczynski/replace-in-file?branch=master)
[![github issues](https://img.shields.io/github/issues/adambuczynski/replace-in-file.svg)](https://github.com/adambuczynski/replace-in-file/issues)

@@ -50,2 +51,2 @@

Copyright 2015, [Adam Buczynski](http://adambuczynski.com)
Copyright 2015-2016, [Adam Buczynski](http://adambuczynski.com)

12

test/helpers/setup.js
'use strict';
//Load dependencies
let Promise = require('bluebird');
let chai = require('chai');
let dirtyChai = require('dirty-chai');
let chaiAsPromised = require('chai-as-promised');
//Enable should assertion style for usage with chai-as-promised
chai.should();
//Extend chai
chai.use(dirtyChai);
chai.use(chaiAsPromised);
//Expose globals
global.Promise = Promise;
global.expect = chai.expect;
global.assert = chai.assert;

@@ -24,3 +24,4 @@ 'use strict';

writeFile('test1', testData, 'utf8'),
writeFile('test2', testData, 'utf8')
writeFile('test2', testData, 'utf8'),
writeFile('test3', 'nope', 'utf8')
]));

@@ -33,9 +34,10 @@

deleteFile('test1'),
deleteFile('test2')
deleteFile('test2'),
deleteFile('test3')
]));
/**
* Replace in one file
* Tests
*/
it('should replace contents in a single file', function(done) {
it('should replace contents in a single file with regex', function(done) {
replace({

@@ -54,5 +56,14 @@ files: 'test1',

/**
* Replace in multiple file
*/
it('should replace contents with a string replacement', function(done) {
replace({
files: 'test1',
replace: 're place',
with: 'b'
}, () => {
let test1 = fs.readFileSync('test1', 'utf8');
expect(test1).to.equal('a b c');
done();
});
});
it('should replace contents in a an array of files', function(done) {

@@ -72,16 +83,70 @@ replace({

/**
* Replace in one file
*/
it('should replace contents with a string replacement', function(done) {
it('should not return an error on success', function(done) {
replace({
files: 'test1',
replace: 're place',
replace: /re\splace/g,
with: 'b'
}, () => {
let test1 = fs.readFileSync('test1', 'utf8');
expect(test1).to.equal('a b c');
}, (error) => {
expect(error).to.equal(null);
done();
});
});
it('should return an error on failure', function(done) {
replace({
files: 'nope',
replace: /re\splace/g,
with: 'b'
}, (error) => {
expect(error).not.to.equal(null);
done();
});
});
it('should return a changed files array', function(done) {
replace({
files: 'test1',
replace: /re\splace/g,
with: 'b'
}, (error, changedFiles) => {
expect(changedFiles).to.be.instanceof(Array);
done();
});
});
it('should return in changed files if something was replaced', function(done) {
replace({
files: 'test1',
replace: /re\splace/g,
with: 'b'
}, (error, changedFiles) => {
expect(changedFiles).to.have.length(1);
expect(changedFiles[0]).to.equal('test1');
done();
});
});
it('should not return in changed files if nothing replaced', function(done) {
replace({
files: 'test1',
replace: 'nope',
with: 'b'
}, (error, changedFiles) => {
expect(changedFiles).to.have.length(0);
done();
});
});
it('should return changed files for multiple files', function(done) {
replace({
files: ['test1', 'test2', 'test3'],
replace: /re\splace/g,
with: 'b'
}, (error, changedFiles) => {
expect(changedFiles).to.have.length(2);
expect(changedFiles).to.contain('test1');
expect(changedFiles).to.contain('test2');
done();
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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