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

gulp-rename

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-rename - npm Package Compare versions

Comparing version 1.2.0 to 1.2.2

81

index.js

@@ -1,58 +0,65 @@

var Stream = require("stream"),
Path = require("path");
'use strict';
var Stream = require('stream');
var Path = require('path');
function gulpRename(obj) {
"use strict";
var stream = new Stream.Transform({objectMode: true});
function parsePath(path) {
var extname = Path.extname(path);
return {
dirname: Path.dirname(path),
basename: Path.basename(path, extname),
extname: extname
};
}
function parsePath(path) {
var extname = Path.extname(path);
return {
dirname: Path.dirname(path),
basename: Path.basename(path, extname),
extname: extname
};
}
stream._transform = function(file, unused, callback) {
stream._transform = function(file, unused, callback) {
var parsedPath = parsePath(file.relative);
var path;
var parsedPath = parsePath(file.relative);
var path;
var type = typeof obj;
var type = typeof obj;
if (type === "string" && obj !== "") {
if (type === 'string' && obj !== '') {
path = obj;
path = obj;
} else if (type === "function") {
} else if (type === 'function') {
var result = obj(parsedPath) || parsedPath;
path = Path.join(result.dirname, result.basename + result.extname);
obj(parsedPath);
path = Path.join(parsedPath.dirname, parsedPath.basename + parsedPath.extname);
} else if (type === "object" && obj !== undefined && obj !== null) {
} else if (type === 'object' && obj !== undefined && obj !== null) {
var dirname = 'dirname' in obj ? obj.dirname : parsedPath.dirname,
prefix = obj.prefix || "",
suffix = obj.suffix || "",
basename = 'basename' in obj ? obj.basename : parsedPath.basename,
extname = 'extname' in obj ? obj.extname : parsedPath.extname;
var dirname = 'dirname' in obj ? obj.dirname : parsedPath.dirname,
prefix = obj.prefix || '',
suffix = obj.suffix || '',
basename = 'basename' in obj ? obj.basename : parsedPath.basename,
extname = 'extname' in obj ? obj.extname : parsedPath.extname;
path = Path.join(dirname, prefix + basename + suffix + extname);
path = Path.join(dirname, prefix + basename + suffix + extname);
} else {
callback(new Error("Unsupported renaming parameter type supplied"), undefined);
return;
}
} else {
file.path = Path.join(file.base, path);
callback(new Error('Unsupported renaming parameter type supplied'), undefined);
return;
callback(null, file);
}
}
return stream;
};
file.path = Path.join(file.base, path);
// Rename sourcemap if present
if (file.sourceMap) {
file.sourceMap.file = file.relative;
}
callback(null, file);
};
return stream;
}
module.exports = gulpRename;
{
"name": "gulp-rename",
"version": "1.2.0",
"version": "1.2.2",
"description": "Rename files",

@@ -16,2 +16,5 @@ "keywords": [

"main": "./index.js",
"files": [
"index.js"
],
"repository": {

@@ -22,10 +25,13 @@ "type": "git",

"scripts": {
"test": "mocha test/*.spec.js"
"pretest": "jshint index.js test/",
"test": "mocha"
},
"devDependencies": {
"gulp": ">=3.0.0",
"gulp-sourcemaps": "^1.5.0",
"gulp-util": "^3.0.4",
"jshint": "^2.6.3",
"map-stream": ">=0.0.4",
"mocha": ">=1.15.0",
"should": ">=2.1.0",
"gulp": ">=3.0.0",
"gulp-jshint": ">=1.1.0"
"should": ">=2.1.0"
},

@@ -32,0 +38,0 @@ "engines": {

@@ -5,2 +5,7 @@ # gulp-rename

[![NPM](https://nodei.co/npm/gulp-rename.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/gulp-rename/)
[![build status](https://secure.travis-ci.org/hparra/gulp-rename.svg)](http://travis-ci.org/hparra/gulp-rename)
[![devDependency Status](https://david-dm.org/hparra/gulp-rename/dev-status.svg)](https://david-dm.org/hparra/gulp-rename#info=devDependencies)
## Usage

@@ -15,24 +20,24 @@

gulp.src("./src/main/text/hello.txt")
.pipe(rename("main/text/ciao/goodbye.md"))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/goodbye.md
.pipe(rename("main/text/ciao/goodbye.md"))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/goodbye.md
// rename via function
gulp.src("./src/**/hello.txt")
.pipe(rename(function (path) {
path.dirname += "/ciao";
path.basename += "-goodbye";
path.extname = ".md"
}))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md
.pipe(rename(function (path) {
path.dirname += "/ciao";
path.basename += "-goodbye";
path.extname = ".md"
}))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/hello-goodbye.md
// rename via hash
gulp.src("./src/main/text/hello.txt", { base: process.cwd() })
.pipe(rename({
dirname: "main/text/ciao",
basename: "aloha",
prefix: "bonjour-",
suffix: "-hola",
extname: ".md"
}))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/bonjour-aloha-hola.md
.pipe(rename({
dirname: "main/text/ciao",
basename: "aloha",
prefix: "bonjour-",
suffix: "-hola",
extname: ".md"
}))
.pipe(gulp.dest("./dist")); // ./dist/main/text/ciao/bonjour-aloha-hola.md
```

@@ -47,3 +52,2 @@

* `gulp.dest()` renames the directories between `process.cwd()` and `dirname` (i.e. the base relative to CWD). Use `dirname` to rename the directories matched by the glob or descendents of the base of option.
* KNOWN ISSUE: The base set when using brace expansion may not be what you expect (See wearefractal/glob2base#1). Use the `base` option described above.
* `basename` is the filename without the extension like path.basename(filename, path.extname(filename)).

@@ -50,0 +54,0 @@ * `extname` is the file extension including the '.' like path.extname(filename).

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