Socket
Socket
Sign inDemoInstall

wodge

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wodge - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

65

lib/wodge.js
"use strict";
/** @module wodge */
var util = require("util"),

@@ -29,2 +28,3 @@ path = require("path");

exports.union = union;
exports.commonSequence = commonSequence;

@@ -76,8 +76,8 @@ function extend(){

@example
var obj = {
clive: 1,
hater: 3
};
var list = w.pluck(obj, function(val){ return val === 1});
// list is [ "clive" ]
var obj = {
clive: 1,
hater: 3
};
var list = w.pluck(obj, function(val){ return val === 1});
// list is [ "clive" ]
*/

@@ -233,3 +233,3 @@ function pluck1(object, fn){

Works on an array of objects. Returns the first object with `property` set to `value`.
@alias module:wodge.first
alias module:wodge.first
*/

@@ -243,29 +243,16 @@ function first(arr, prop, val){

/**
commonDir returns the directory common to each path in the list
@param {Array} files - An array of file paths to inspect
@returns {string} - A single path ending with the path separator, e.g. "/user/some/folder/"
*/
function commonDir(files){
var dirIsCommon = true,
matches = [];
if (files.length === 1){
return path.dirname(files[0]) + path.sep;
} else {
while (dirIsCommon){
var firstFileDirs = files[0].split(path.sep),
firstFileTopDir = firstFileDirs[0];
if(firstFileDirs.length === 1){
dirIsCommon = false;
} else {
dirIsCommon = files.every(function(file){
return file.split(path.sep)[0] === firstFileTopDir;
});
if (dirIsCommon){
matches.push(firstFileTopDir);
files = files.map(function(file){
return file.replace(firstFileTopDir + path.sep, "");
});
}
}
}
matches.push("");
return matches.join(path.sep);
}
return files
.map(path.dirname)
.map(function(dir){
return dir.split(path.sep);
})
.reduce(commonSequence)
.concat([""])
.join(path.sep);
}

@@ -282,1 +269,11 @@

}
function commonSequence(a, b){
var result = [];
for (var i = 0; i < Math.min(a.length, b.length); i++){
if (a[i] === b[i]){
result.push(a[i]);
}
}
return result;
}
{
"name": "wodge",
"version": "0.5.0",
"version": "0.5.1",
"description": "a wodge of functional dough",

@@ -5,0 +5,0 @@ "main": "lib/wodge.js",

var test = require("tape"),
os = require("os"),
w = require("../");
test("commonDir: simple", function(t){
var input = [
"/Users/Lloyd/Documents/Kunai/renamer/one",
"/Users/Lloyd/Documents/Kunai/renamer/folder/folder/five",
"/Users/Lloyd/Documents/Kunai/renamer/folder/four",
"/Users/Lloyd/Documents/Kunai/another",
"/Users/Lloyd/Documents/Kunai/renamer/two",
"/Users/Lloyd/Documents/Kunai/renamer/folder/three",
"/Users/Lloyd/Documents/Kunai/renamer"
];
t.equal(w.commonDir(input), "/Users/Lloyd/Documents/Kunai/");
t.end();
});
if (os.platform() === "win32"){
test("commonDir: simple (win)", function(t){
var input = [
"C:\\Users\\IEUser\\Documents\\GitHub\\wodge",
"C:\\Users\\IEUser\\Documents\\GitHub\\wodge\\folder",
"C:\\Users\\IEUser\\Documents\\GitHub\\wodge\\folder\\five",
"C:\\Users\\IEUser\\Documents\\GitHub\\wodge\\folder\\four",
];
t.equal(w.commonDir(input), "C:\\Users\\IEUser\\Documents\\GitHub\\");
t.end();
});
test("commonDir: wildly diff folders", function(t){
var input = [
"/this/that",
"/another/something",
"/andagain/different"
];
t.equal(w.commonDir(input), "/");
t.end();
});
test("commonDir: wildly diff folders (win)", function(t){
var input = [
"C:\\this\\that",
"C:\\another\\something",
"C:\\andagain\\different"
];
var parentDirs = [
"C:\\this\\",
"C:\\another\\",
"C:\\andagain\\"
];
t.equal(w.commonDir(input), "C:\\");
t.end();
});
test("commonDir: another", function(t){
var input = [
"/Users/Lloyd/Documents/LEGO Creations/MINDSTORMS EV3 Projects/Randomness.ev3",
"/Users/Lloyd/Desktop/Screen Shot 2014-03-27 at 10.00.12.png"
];
t.equal(w.commonDir(input), "/Users/Lloyd/");
t.end();
});
test("commonDir: just one (win)", function(t){
var input = [
"C:\\Users\\Lloyd\\Documents\\LEGO Creations\\MINDSTORMS EV3 Projects\\Randomness.ev3"
];
t.equal(w.commonDir(input), "C:\\Users\\Lloyd\\Documents\\LEGO Creations\\MINDSTORMS EV3 Projects\\");
t.end();
});
test("commonDir: just one", function(t){
var input = [
"/Users/Lloyd/Documents/LEGO Creations/MINDSTORMS EV3 Projects/Randomness.ev3"
];
t.equal(w.commonDir(input), "/Users/Lloyd/Documents/LEGO Creations/MINDSTORMS EV3 Projects/");
t.end();
});
} else {
test("commonDir: simple", function(t){
var input = [
"/Users/Lloyd/Documents/Kunai/renamer/one",
"/Users/Lloyd/Documents/Kunai/renamer/folder/folder/five",
"/Users/Lloyd/Documents/Kunai/renamer/folder/four",
"/Users/Lloyd/Documents/Kunai/another",
"/Users/Lloyd/Documents/Kunai/renamer/two",
"/Users/Lloyd/Documents/Kunai/renamer/folder/three",
"/Users/Lloyd/Documents/Kunai/renamer"
];
t.equal(w.commonDir(input), "/Users/Lloyd/Documents/Kunai/");
t.end();
});
test("commonDir: all same folder", function(t){
var input = [
"/Users/Lloyd/Documents/Kunai/renamer/one",
"/Users/Lloyd/Documents/Kunai/renamer/two",
"/Users/Lloyd/Documents/Kunai/renamer/three"
];
t.equal(w.commonDir(input), "/Users/Lloyd/Documents/Kunai/renamer/");
t.end();
});
test("commonDir: wildly diff folders", function(t){
var input = [ "/this/that", "/another/something", "/andagain/different" ];
var parentDirs = [
"/this/",
"/another/",
"/andagain/"
];
t.equal(w.commonDir(input), "/");
t.end();
});
test("commonDir: hangs", function(t){
var input = [
"file1.txt",
"file1.txt"
];
t.equal(w.commonDir(input), "");
t.end();
});
test("commonDir: another", function(t){
var input = [
"/Users/Lloyd/Documents/LEGO Creations/MINDSTORMS EV3 Projects/Randomness.ev3",
"/Users/Lloyd/Desktop/Screen Shot 2014-03-27 at 10.00.12.png"
];
var parentDirs = [
"/Users/Lloyd/Documents/LEGO Creations/MINDSTORMS EV3 Projects/",
"/Users/Lloyd/Desktop/"
];
t.equal(w.commonDir(input), "/Users/Lloyd/");
t.end();
});
test("commonDir: just one", function(t){
var input = [
"/Users/Lloyd/Documents/LEGO Creations/MINDSTORMS EV3 Projects/Randomness.ev3"
];
t.equal(w.commonDir(input), "/Users/Lloyd/Documents/LEGO Creations/MINDSTORMS EV3 Projects/");
t.end();
});
test("commonDir: all same folder", function(t){
var input = [
"/Users/Lloyd/Documents/Kunai/renamer/one",
"/Users/Lloyd/Documents/Kunai/renamer/two",
"/Users/Lloyd/Documents/Kunai/renamer/three"
];
t.equal(w.commonDir(input), "/Users/Lloyd/Documents/Kunai/renamer/");
t.end();
});
test("commonDir: hangs", function(t){
var input = [
"file1.txt",
"file1.txt"
];
t.equal(w.commonDir(input), "./");
t.end();
});
test("commonDir: file and parent folder", function(t){
var input = [
"/Users/Lloyd/Documents/Kunai/renamer/one",
"/Users/Lloyd/Documents/Kunai/renamer"
];
t.equal(w.commonDir(input), "/Users/Lloyd/Documents/Kunai/");
t.end();
});
}

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