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

glob-rewriter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glob-rewriter - npm Package Compare versions

Comparing version 1.0.0 to 1.0.2

bower.json

65

dist/glob-rewriter.js

@@ -9,5 +9,5 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.GlobRewriter = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

validate: validate,
rewrite: function() {
validate.apply(this, arguments);
return rewrite.apply(this, arguments);
rewrite: function(path, locale, source, target) {
validate(source, target);
return rewrite(path, locale, source, target);
}

@@ -35,3 +35,18 @@ };

module.exports = function(path, locale, source, target) {
if (typeof path !== 'string') {
throw new Error('Path is not a string');
} else if (typeof locale !== 'string') {
throw new Error('Locale is not a string');
}
// Create source regexp
var sourceRegexp = globToRegExp(source, {globstar: true});
// Validate path against source
var sourceRegexp = globToRegExp(source, {globstar: true});
if (!sourceRegexp.test(path)) {
throw new Error(
'Source expression "' + source +
'" does not match path "' + path + '"'
);
}
// Match path against source regexp
var matches = sourceRegexp.exec(path);

@@ -114,3 +129,3 @@ // Get rid of the first match, it's the whole string

if (haystack.indexOf(needle) !== -1) {
return true;
return needle;
}

@@ -120,9 +135,5 @@ }

module.exports = function(path, locale, source, target) {
module.exports = function(source, target) {
// Validate input
if (typeof path !== 'string') {
throw new Error('Path is not a string');
} else if (typeof locale !== 'string') {
throw new Error('Locale is not a string');
} else if (typeof source !== 'string') {
if (typeof source !== 'string') {
throw new Error('Source expression is not a string');

@@ -132,33 +143,25 @@ } else if (typeof target !== 'string') {

} else if (/\*{3,}/.test(source)) {
throw new Error('Source expression is malformed');
throw new Error('Source expression contains an invalid glob');
} else if (/\*{3,}/.test(target)) {
throw new Error('Target expression is malformed');
} else if (contains(source, invalidChars)) {
throw new Error('Source expression contains one or more invalid characters');
} else if (contains(target.replace('<LOCALE>', ''), invalidChars)) {
throw new Error('Target expression contains one or more invalid characters');
throw new Error('Target expression contains an invalid glob');
}
var cs = contains(source, invalidChars);
var ct = contains(target.replace('<LOCALE>', ''), invalidChars);
if (cs) {
throw new Error('Source expression contains an invalid character "' + cs + '"');
} else if (ct) {
throw new Error('Target expression contains an invalid character "' + ct + '"');
} else if (source[0] === '/') {
throw new Error('Source expression is not relative');
throw new Error('Source expression is not a relative path');
} else if (target[0] === '/') {
throw new Error('Target expression is not relative');
throw new Error('Target expression is not a relative path');
} else if (!/<LOCALE>/.test(target)) {
throw new Error('Placeholder is missing from the target expression');
throw new Error('Target expression is missing the "<LOCALE>" placeholder');
}
// Validate source against target
if (!globsMatch(source, target)) {
throw new Error(
'Globs in source expression "' + source +
'" do not match globs in target expression "' + target + '"'
'Globs in source expression do not match globs in target expression'
);
}
// Validate path against source
var sourceRegexp = globToRegExp(source, {globstar: true});
if (!sourceRegexp.test(path)) {
throw new Error(
'Source expression "' + source +
'" does not match path "' + path + '"'
);
}
};

@@ -165,0 +168,0 @@

@@ -8,6 +8,6 @@ 'use strict';

validate: validate,
rewrite: function() {
validate.apply(this, arguments);
return rewrite.apply(this, arguments);
rewrite: function(path, locale, source, target) {
validate(source, target);
return rewrite(path, locale, source, target);
}
};

@@ -6,3 +6,18 @@ 'use strict';

module.exports = function(path, locale, source, target) {
if (typeof path !== 'string') {
throw new Error('Path is not a string');
} else if (typeof locale !== 'string') {
throw new Error('Locale is not a string');
}
// Create source regexp
var sourceRegexp = globToRegExp(source, {globstar: true});
// Validate path against source
var sourceRegexp = globToRegExp(source, {globstar: true});
if (!sourceRegexp.test(path)) {
throw new Error(
'Source expression "' + source +
'" does not match path "' + path + '"'
);
}
// Match path against source regexp
var matches = sourceRegexp.exec(path);

@@ -9,0 +24,0 @@ // Get rid of the first match, it's the whole string

@@ -46,3 +46,3 @@ 'use strict';

if (haystack.indexOf(needle) !== -1) {
return true;
return needle;
}

@@ -52,9 +52,5 @@ }

module.exports = function(path, locale, source, target) {
module.exports = function(source, target) {
// Validate input
if (typeof path !== 'string') {
throw new Error('Path is not a string');
} else if (typeof locale !== 'string') {
throw new Error('Locale is not a string');
} else if (typeof source !== 'string') {
if (typeof source !== 'string') {
throw new Error('Source expression is not a string');

@@ -64,33 +60,25 @@ } else if (typeof target !== 'string') {

} else if (/\*{3,}/.test(source)) {
throw new Error('Source expression is malformed');
throw new Error('Source expression contains an invalid glob');
} else if (/\*{3,}/.test(target)) {
throw new Error('Target expression is malformed');
} else if (contains(source, invalidChars)) {
throw new Error('Source expression contains one or more invalid characters');
} else if (contains(target.replace('<LOCALE>', ''), invalidChars)) {
throw new Error('Target expression contains one or more invalid characters');
throw new Error('Target expression contains an invalid glob');
}
var cs = contains(source, invalidChars);
var ct = contains(target.replace('<LOCALE>', ''), invalidChars);
if (cs) {
throw new Error('Source expression contains an invalid character "' + cs + '"');
} else if (ct) {
throw new Error('Target expression contains an invalid character "' + ct + '"');
} else if (source[0] === '/') {
throw new Error('Source expression is not relative');
throw new Error('Source expression is not a relative path');
} else if (target[0] === '/') {
throw new Error('Target expression is not relative');
throw new Error('Target expression is not a relative path');
} else if (!/<LOCALE>/.test(target)) {
throw new Error('Placeholder is missing from the target expression');
throw new Error('Target expression is missing the "<LOCALE>" placeholder');
}
// Validate source against target
if (!globsMatch(source, target)) {
throw new Error(
'Globs in source expression "' + source +
'" do not match globs in target expression "' + target + '"'
'Globs in source expression do not match globs in target expression'
);
}
// Validate path against source
var sourceRegexp = globToRegExp(source, {globstar: true});
if (!sourceRegexp.test(path)) {
throw new Error(
'Source expression "' + source +
'" does not match path "' + path + '"'
);
}
};
{
"name": "glob-rewriter",
"version": "1.0.0",
"version": "1.0.2",
"description": "Rewrites paths, using two globs as patterns",

@@ -12,2 +12,3 @@ "main": "index.js",

"license": "MIT",
"repository": "roccivic/glob-rewriter",
"devDependencies": {

@@ -14,0 +15,0 @@ "browserify": "^13.1.1",

[![Build Status](https://travis-ci.org/roccivic/glob-rewriter.svg)](https://travis-ci.org/roccivic/glob-rewriter)
[![npm](https://img.shields.io/npm/v/glob-rewriter.svg)](https://www.npmjs.com/package/glob-rewriter)
![Bower](https://img.shields.io/bower/v/glob-rewriter.svg)

@@ -3,0 +5,0 @@ # Glob rewriter

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