Socket
Socket
Sign inDemoInstall

gulp-ext-replace

Package Overview
Dependencies
7
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.2.0

14

index.js
'use strict';
var gutil = require('gulp-util');
// dependencies
var through = require('through2');
var path = require('path');
module.exports = function(ext) {
module.exports = function(ext, replaceExt) {
var extension_replace = function(file, encoding, callback) {
if (typeof ext === 'undefined') {
gutil.log('You failed to supply a new extension so nothing will be changed');
} else {
file.path = file.path.replace(/\.\w+$/gi, ext);
replaceExt = replaceExt || false;
if (typeof ext === 'string' && ext.length > 0) {
ext = ext.indexOf('.') === 0 ? ext : '.' + ext;
file.path = file.path.replace(replaceExt ? replaceExt : path.extname(file.path), ext);
}

@@ -13,0 +15,0 @@

{
"name": "gulp-ext-replace",
"version": "0.1.0",
"version": "0.2.0",
"homepage": "https://github.com/tjeastmond/gulp-ext-replace",

@@ -23,11 +23,13 @@ "description": "Small gulp plugin to change a file's extension",

"replace",
"gulp"
"gulp",
"util",
"extensions"
],
"license": "MIT",
"dependencies": {
"gulp-util": "~2.2.12",
"through2": "~0.4.1"
"through2": "~0.6.5"
},
"devDependencies": {
"gulp": "~3.4.0",
"gulp": "~3.8.11",
"gulp-util": "~3.0.4",
"mocha": "~1.15.1",

@@ -34,0 +36,0 @@ "should": "~2.1.1"

@@ -5,5 +5,5 @@ # gulp-ext-replace

### Update
### Update - v0.2.0
I removed the `gulpplugin` keyword from the package file so that this plugin doesn't show up on the Gulp website. While I'd prefer to continue using this plugin, the very awesome `gulp-replace` plugin is likely a better choice for you.
I've added a feature that allows you to tell this plugin what extension you want replaced instead of relying on Node.js to figure it out, which is always just the characters from the last period forward. See below for an example.

@@ -19,7 +19,7 @@ ## Install

```javascript
var ext-replace = require('gulp-ext-replace');
var ext_replace = require('gulp-ext-replace');
gulp.task('change', function() {
gulp.src('styles/*.css')
.pipe(ext-replace('.scss'))
.pipe(ext_replace('.scss'))
.pipe(gulp.dest('dist'))

@@ -29,2 +29,13 @@ });

If you have a slightly more involved extension you'd like to replace like `.min.css`, you can tell the plugin to replace that instead of the default behavior by passing in a second variable to `ext_replace` in the following example:
```javascript
gulp.task('change', function() {
gulp.src('styles/*.css')
.pipe(ext_replace('.scss', '.min.css'))
.pipe(gulp.dest('dist'))
});
```
## Testing

@@ -39,5 +50,20 @@

## Change Log
#### 0.2.0
- Added ability to specify the extension to be replaced
- Updated tests to test for `undefined`, `false` or blank extensions
- Added check for period at beginning of new extension
- Updated version of dependency `through2`
#### 0.1.0
- Bug fix: typo in README
- Bumped version number
#### 0.0.5
- Initial release
## The License (MIT)
Copyright (c) 2014 TJ Eastmond
Copyright (c) 2015 TJ Eastmond

@@ -44,0 +70,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

@@ -16,3 +16,3 @@ var gulp = require('gulp');

var testChange = function(options, done) {
var stream = replace(options.newExt);
var stream = replace(options.newExt, options.replaceExt || false);
var file = fakeFile(options.filename);

@@ -34,3 +34,8 @@

it('should change the extension', function(done) {
var options = { filename: 'styles.scss', newFilename: 'styles.css', newExt: '.css'};
var options = {
filename: 'styles.scss',
newFilename: 'styles.css',
newExt: '.css'
};
testChange(options, done);

@@ -40,8 +45,29 @@ });

it('should change the tricky extension', function(done) {
var options = { filename: 'styles.min.css', newFilename: 'styles.min.scss', newExt: '.scss'};
var options = {
filename: 'styles.min.css',
newFilename: 'styles.min.scss',
newExt: '.scss'
};
testChange(options, done);
});
it('should work with custom replace extension', function(done) {
var options = {
filename: 'styles.min.css',
newFilename: 'styles.scss',
newExt: '.scss',
replaceExt: '.min.css'
};
testChange(options, done);
});
it('should not change the extension', function(done) {
var options = { filename: 'styles.css', newFilename: 'styles.css', newExt: '.css'};
var options = {
filename: 'styles.css',
newFilename: 'styles.css',
newExt: '.css'
};
testChange(options, done);

@@ -51,5 +77,40 @@ });

it('should work with numbers too', function(done) {
var options = { filename: 'styles.mp4', newFilename: 'styles.mp3', newExt: '.mp3'};
var options = {
filename: 'styles.mp4',
newFilename: 'styles.mp3',
newExt: '.mp3'
};
testChange(options, done);
});
it('should not blow up with an undefined extension', function(done) {
var options = {
filename: 'styles.css',
newFilename: 'styles.css',
newExt: undefined
};
testChange(options, done);
});
it('should not blow up with false as an extension', function(done) {
var options = {
filename: 'styles.css',
newFilename: 'styles.css',
newExt: false
};
testChange(options, done);
});
it('should add the missing first period', function(done) {
var options = {
filename: 'styles.css',
newFilename: 'styles.scss',
newExt: 'scss'
};
testChange(options, done);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc