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

gulp-tpl-rev

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-tpl-rev - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

plugin.d.ts

8

index.d.ts

@@ -1,7 +0,1 @@

/// <reference types="node" />
interface PluginOption {
name: string;
hash(pahtname?: string): string;
}
export default function (options?: PluginOption): import("stream").Transform;
export {};
declare const plugin: any;
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var through2_1 = __importDefault(require("through2"));
var parse5_html_rewriting_stream_1 = __importDefault(require("parse5-html-rewriting-stream"));
var url = __importStar(require("url"));
var defaultOptions = {
name: "_v",
hash: function (pahtname) { return "" + Date.now(); }
};
function default_1(options) {
if (options === void 0) { options = defaultOptions; }
return through2_1.default.obj(function (file, _, cb) {
var tpl = "";
var rewriter = new parse5_html_rewriting_stream_1.default();
rewriter.on('startTag', function (token) {
if (token.tagName === 'link') {
var attr = token.attrs.filter(function (attr) { return attr.name === "href"; })[0];
if (attr) {
var urlObject = url.parse(attr.value, true);
var query = urlObject.query;
query[options.name] = options.hash(urlObject.pathname);
attr.value = url.format(urlObject);
}
}
rewriter.emitStartTag(token);
});
rewriter.on("text", function (token) {
rewriter.emitText(token);
});
rewriter.on("data", function (token) {
tpl += token;
});
rewriter.on("end", function () {
file.contents = Buffer.from(tpl);
cb(null, file);
});
rewriter.end(file.contents.toString());
});
}
exports.default = default_1;
var plugin = require('./plugin').default;
exports = module.exports = plugin;

@@ -1,43 +0,3 @@

import through2 from "through2";
import RewritingStream from "parse5-html-rewriting-stream"
import * as url from "url";
const plugin = require('./plugin').default
interface PluginOption {
name: string,
hash(pahtname?: string):string
}
const defaultOptions: PluginOption = {
name: "_v",
hash: function(pahtname: string) { return "" + Date.now() }
}
export default function(options: PluginOption = defaultOptions) {
return through2.obj(function(file, _, cb) {
let tpl = "";
const rewriter = new RewritingStream();
rewriter.on('startTag', token => {
if (token.tagName === 'link') {
const attr = token.attrs.filter(attr => attr.name === "href")[0];
if (attr) {
const urlObject = url.parse(attr.value, true);
const query = urlObject.query;
query[options.name] = options.hash(urlObject.pathname);
attr.value = url.format(urlObject);
}
}
rewriter.emitStartTag(token);
});
rewriter.on("text", function(token) {
rewriter.emitText(token)
})
rewriter.on("data", function(token) {
tpl += token
})
rewriter.on("end", function() {
file.contents = Buffer.from(tpl)
cb(null, file)
})
rewriter.end(file.contents.toString())
})
}
exports = module.exports = plugin
{
"name": "gulp-tpl-rev",
"version": "1.0.2",
"version": "1.0.3",
"description": "template resource url revisioning by appending content hash to filenames: unicorn.css => unicorn.css?_v=1",
"main": "dist/index.js",
"typings": "index.ts",
"typings": "plugin.ts",
"scripts": {

@@ -8,0 +8,0 @@ "prepublishOnly": "npm run compile",

@@ -52,4 +52,5 @@ {

"files": [
"index.ts"
"index.ts",
"plugin.ts"
]
}
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