[vendor,refactor][xs]: remove long-unused vendor libs jquery.hotkeys.js and traverse.js.
This commit is contained in:
parent
e8ad368347
commit
ccde07574a
99
vendor/jquery.hotkeys.js
vendored
99
vendor/jquery.hotkeys.js
vendored
@ -1,99 +0,0 @@
|
||||
/*
|
||||
* jQuery Hotkeys Plugin
|
||||
* Copyright 2010, John Resig
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
*
|
||||
* Based upon the plugin by Tzury Bar Yochay:
|
||||
* http://github.com/tzuryby/hotkeys
|
||||
*
|
||||
* Original idea by:
|
||||
* Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/
|
||||
*/
|
||||
|
||||
(function(jQuery){
|
||||
|
||||
jQuery.hotkeys = {
|
||||
version: "0.8",
|
||||
|
||||
specialKeys: {
|
||||
8: "backspace", 9: "tab", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause",
|
||||
20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home",
|
||||
37: "left", 38: "up", 39: "right", 40: "down", 45: "insert", 46: "del",
|
||||
96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7",
|
||||
104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/",
|
||||
112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8",
|
||||
120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 191: "/", 224: "meta"
|
||||
},
|
||||
|
||||
shiftNums: {
|
||||
"`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", "6": "^", "7": "&",
|
||||
"8": "*", "9": "(", "0": ")", "-": "_", "=": "+", ";": ": ", "'": "\"", ",": "<",
|
||||
".": ">", "/": "?", "\\": "|"
|
||||
}
|
||||
};
|
||||
|
||||
function keyHandler( handleObj ) {
|
||||
// Only care when a possible input has been specified
|
||||
if ( typeof handleObj.data !== "string" ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var origHandler = handleObj.handler,
|
||||
keys = handleObj.data.toLowerCase().split(" ");
|
||||
|
||||
handleObj.handler = function( event ) {
|
||||
// Don't fire in text-accepting inputs that we didn't directly bind to
|
||||
if ( this !== event.target && (/textarea|select/i.test( event.target.nodeName ) ||
|
||||
event.target.type === "text") ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Keypress represents characters, not special keys
|
||||
var special = event.type !== "keypress" && jQuery.hotkeys.specialKeys[ event.which ],
|
||||
character = String.fromCharCode( event.which ).toLowerCase(),
|
||||
key, modif = "", possible = {};
|
||||
|
||||
// check combinations (alt|ctrl|shift+anything)
|
||||
if ( event.altKey && special !== "alt" ) {
|
||||
modif += "alt+";
|
||||
}
|
||||
|
||||
if ( event.ctrlKey && special !== "ctrl" ) {
|
||||
modif += "ctrl+";
|
||||
}
|
||||
|
||||
// TODO: Need to make sure this works consistently across platforms
|
||||
if ( event.metaKey && !event.ctrlKey && special !== "meta" ) {
|
||||
modif += "meta+";
|
||||
}
|
||||
|
||||
if ( event.shiftKey && special !== "shift" ) {
|
||||
modif += "shift+";
|
||||
}
|
||||
|
||||
if ( special ) {
|
||||
possible[ modif + special ] = true;
|
||||
|
||||
} else {
|
||||
possible[ modif + character ] = true;
|
||||
possible[ modif + jQuery.hotkeys.shiftNums[ character ] ] = true;
|
||||
|
||||
// "$" can be triggered as "Shift+4" or "Shift+$" or just "$"
|
||||
if ( modif === "shift+" ) {
|
||||
possible[ jQuery.hotkeys.shiftNums[ character ] ] = true;
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0, l = keys.length; i < l; i++ ) {
|
||||
if ( possible[ keys[i] ] ) {
|
||||
return origHandler.apply( this, arguments );
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
jQuery.each([ "keydown", "keyup", "keypress" ], function() {
|
||||
jQuery.event.special[ this ] = { add: keyHandler };
|
||||
});
|
||||
|
||||
})( jQuery );
|
||||
675
vendor/traverse.js
vendored
675
vendor/traverse.js
vendored
@ -1,675 +0,0 @@
|
||||
var require = function (file, cwd) {
|
||||
var resolved = require.resolve(file, cwd || '/');
|
||||
var mod = require.modules[resolved];
|
||||
if (!mod) throw new Error(
|
||||
'Failed to resolve module ' + file + ', tried ' + resolved
|
||||
);
|
||||
var res = mod._cached ? mod._cached : mod();
|
||||
return res;
|
||||
}
|
||||
var __require = require;
|
||||
|
||||
require.paths = [];
|
||||
require.modules = {};
|
||||
require.extensions = [".js",".coffee"];
|
||||
|
||||
require.resolve = (function () {
|
||||
var core = {
|
||||
'assert': true,
|
||||
'events': true,
|
||||
'fs': true,
|
||||
'path': true,
|
||||
'vm': true
|
||||
};
|
||||
|
||||
return function (x, cwd) {
|
||||
if (!cwd) cwd = '/';
|
||||
|
||||
if (core[x]) return x;
|
||||
var path = require.modules.path();
|
||||
var y = cwd || '.';
|
||||
|
||||
if (x.match(/^(?:\.\.?\/|\/)/)) {
|
||||
var m = loadAsFileSync(path.resolve(y, x))
|
||||
|| loadAsDirectorySync(path.resolve(y, x));
|
||||
if (m) return m;
|
||||
}
|
||||
|
||||
var n = loadNodeModulesSync(x, y);
|
||||
if (n) return n;
|
||||
|
||||
throw new Error("Cannot find module '" + x + "'");
|
||||
|
||||
function loadAsFileSync (x) {
|
||||
if (require.modules[x]) {
|
||||
return x;
|
||||
}
|
||||
|
||||
for (var i = 0; i < require.extensions.length; i++) {
|
||||
var ext = require.extensions[i];
|
||||
if (require.modules[x + ext]) return x + ext;
|
||||
}
|
||||
}
|
||||
|
||||
function loadAsDirectorySync (x) {
|
||||
x = x.replace(/\/+$/, '');
|
||||
var pkgfile = x + '/package.json';
|
||||
if (require.modules[pkgfile]) {
|
||||
var pkg = require.modules[pkgfile]();
|
||||
var b = pkg.browserify;
|
||||
if (typeof b === 'object' && b.main) {
|
||||
var m = loadAsFileSync(path.resolve(x, b.main));
|
||||
if (m) return m;
|
||||
}
|
||||
else if (typeof b === 'string') {
|
||||
var m = loadAsFileSync(path.resolve(x, b));
|
||||
if (m) return m;
|
||||
}
|
||||
else if (pkg.main) {
|
||||
var m = loadAsFileSync(path.resolve(x, pkg.main));
|
||||
if (m) return m;
|
||||
}
|
||||
}
|
||||
|
||||
return loadAsFileSync(x + '/index');
|
||||
}
|
||||
|
||||
function loadNodeModulesSync (x, start) {
|
||||
var dirs = nodeModulesPathsSync(start);
|
||||
for (var i = 0; i < dirs.length; i++) {
|
||||
var dir = dirs[i];
|
||||
var m = loadAsFileSync(dir + '/' + x);
|
||||
if (m) return m;
|
||||
var n = loadAsDirectorySync(dir + '/' + x);
|
||||
if (n) return n;
|
||||
}
|
||||
|
||||
var m = loadAsFileSync(x);
|
||||
if (m) return m;
|
||||
}
|
||||
|
||||
function nodeModulesPathsSync (start) {
|
||||
var parts;
|
||||
if (start === '/') parts = [ '' ];
|
||||
else parts = path.normalize(start).split('/');
|
||||
|
||||
var dirs = [];
|
||||
for (var i = parts.length - 1; i >= 0; i--) {
|
||||
if (parts[i] === 'node_modules') continue;
|
||||
var dir = parts.slice(0, i + 1).join('/') + '/node_modules';
|
||||
dirs.push(dir);
|
||||
}
|
||||
|
||||
return dirs;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
require.alias = function (from, to) {
|
||||
var path = require.modules.path();
|
||||
var res = null;
|
||||
try {
|
||||
res = require.resolve(from + '/package.json', '/');
|
||||
}
|
||||
catch (err) {
|
||||
res = require.resolve(from, '/');
|
||||
}
|
||||
var basedir = path.dirname(res);
|
||||
|
||||
Object.keys(require.modules)
|
||||
.forEach(function (x) {
|
||||
if (x.slice(0, basedir.length + 1) === basedir + '/') {
|
||||
var f = x.slice(basedir.length);
|
||||
require.modules[to + f] = require.modules[basedir + f];
|
||||
}
|
||||
else if (x === basedir) {
|
||||
require.modules[to] = require.modules[basedir];
|
||||
}
|
||||
})
|
||||
;
|
||||
};
|
||||
|
||||
if (typeof process === 'undefined') process = {};
|
||||
|
||||
if (!process.nextTick) process.nextTick = function (fn) {
|
||||
setTimeout(fn, 0);
|
||||
};
|
||||
|
||||
if (!process.title) process.title = 'browser';
|
||||
|
||||
if (!process.binding) process.binding = function (name) {
|
||||
if (name === 'evals') return require('vm')
|
||||
else throw new Error('No such module')
|
||||
};
|
||||
|
||||
if (!process.cwd) process.cwd = function () { return '.' };
|
||||
|
||||
require.modules["path"] = function () {
|
||||
var module = { exports : {} };
|
||||
var exports = module.exports;
|
||||
var __dirname = ".";
|
||||
var __filename = "path";
|
||||
|
||||
var require = function (file) {
|
||||
return __require(file, ".");
|
||||
};
|
||||
|
||||
require.resolve = function (file) {
|
||||
return __require.resolve(name, ".");
|
||||
};
|
||||
|
||||
require.modules = __require.modules;
|
||||
__require.modules["path"]._cached = module.exports;
|
||||
|
||||
(function () {
|
||||
// resolves . and .. elements in a path array with directory names there
|
||||
// must be no slashes, empty elements, or device names (c:\) in the array
|
||||
// (so also no leading and trailing slashes - it does not distinguish
|
||||
// relative and absolute paths)
|
||||
function normalizeArray(parts, allowAboveRoot) {
|
||||
// if the path tries to go above the root, `up` ends up > 0
|
||||
var up = 0;
|
||||
for (var i = parts.length; i >= 0; i--) {
|
||||
var last = parts[i];
|
||||
if (last == '.') {
|
||||
parts.splice(i, 1);
|
||||
} else if (last === '..') {
|
||||
parts.splice(i, 1);
|
||||
up++;
|
||||
} else if (up) {
|
||||
parts.splice(i, 1);
|
||||
up--;
|
||||
}
|
||||
}
|
||||
|
||||
// if the path is allowed to go above the root, restore leading ..s
|
||||
if (allowAboveRoot) {
|
||||
for (; up--; up) {
|
||||
parts.unshift('..');
|
||||
}
|
||||
}
|
||||
|
||||
return parts;
|
||||
}
|
||||
|
||||
// Regex to split a filename into [*, dir, basename, ext]
|
||||
// posix version
|
||||
var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;
|
||||
|
||||
// path.resolve([from ...], to)
|
||||
// posix version
|
||||
exports.resolve = function() {
|
||||
var resolvedPath = '',
|
||||
resolvedAbsolute = false;
|
||||
|
||||
for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {
|
||||
var path = (i >= 0)
|
||||
? arguments[i]
|
||||
: process.cwd();
|
||||
|
||||
// Skip empty and invalid entries
|
||||
if (typeof path !== 'string' || !path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
resolvedPath = path + '/' + resolvedPath;
|
||||
resolvedAbsolute = path.charAt(0) === '/';
|
||||
}
|
||||
|
||||
// At this point the path should be resolved to a full absolute path, but
|
||||
// handle relative paths to be safe (might happen when process.cwd() fails)
|
||||
|
||||
// Normalize the path
|
||||
resolvedPath = normalizeArray(resolvedPath.split('/').filter(function(p) {
|
||||
return !!p;
|
||||
}), !resolvedAbsolute).join('/');
|
||||
|
||||
return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';
|
||||
};
|
||||
|
||||
// path.normalize(path)
|
||||
// posix version
|
||||
exports.normalize = function(path) {
|
||||
var isAbsolute = path.charAt(0) === '/',
|
||||
trailingSlash = path.slice(-1) === '/';
|
||||
|
||||
// Normalize the path
|
||||
path = normalizeArray(path.split('/').filter(function(p) {
|
||||
return !!p;
|
||||
}), !isAbsolute).join('/');
|
||||
|
||||
if (!path && !isAbsolute) {
|
||||
path = '.';
|
||||
}
|
||||
if (path && trailingSlash) {
|
||||
path += '/';
|
||||
}
|
||||
|
||||
return (isAbsolute ? '/' : '') + path;
|
||||
};
|
||||
|
||||
|
||||
// posix version
|
||||
exports.join = function() {
|
||||
var paths = Array.prototype.slice.call(arguments, 0);
|
||||
return exports.normalize(paths.filter(function(p, index) {
|
||||
return p && typeof p === 'string';
|
||||
}).join('/'));
|
||||
};
|
||||
|
||||
|
||||
exports.dirname = function(path) {
|
||||
var dir = splitPathRe.exec(path)[1] || '';
|
||||
var isWindows = false;
|
||||
if (!dir) {
|
||||
// No dirname
|
||||
return '.';
|
||||
} else if (dir.length === 1 ||
|
||||
(isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {
|
||||
// It is just a slash or a drive letter with a slash
|
||||
return dir;
|
||||
} else {
|
||||
// It is a full dirname, strip trailing slash
|
||||
return dir.substring(0, dir.length - 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.basename = function(path, ext) {
|
||||
var f = splitPathRe.exec(path)[2] || '';
|
||||
// TODO: make this comparison case-insensitive on windows?
|
||||
if (ext && f.substr(-1 * ext.length) === ext) {
|
||||
f = f.substr(0, f.length - ext.length);
|
||||
}
|
||||
return f;
|
||||
};
|
||||
|
||||
|
||||
exports.extname = function(path) {
|
||||
return splitPathRe.exec(path)[3] || '';
|
||||
};
|
||||
;
|
||||
}).call(module.exports);
|
||||
|
||||
__require.modules["path"]._cached = module.exports;
|
||||
return module.exports;
|
||||
};
|
||||
|
||||
require.modules["/node_modules/traverse/package.json"] = function () {
|
||||
var module = { exports : {} };
|
||||
var exports = module.exports;
|
||||
var __dirname = "/node_modules/traverse";
|
||||
var __filename = "/node_modules/traverse/package.json";
|
||||
|
||||
var require = function (file) {
|
||||
return __require(file, "/node_modules/traverse");
|
||||
};
|
||||
|
||||
require.resolve = function (file) {
|
||||
return __require.resolve(name, "/node_modules/traverse");
|
||||
};
|
||||
|
||||
require.modules = __require.modules;
|
||||
__require.modules["/node_modules/traverse/package.json"]._cached = module.exports;
|
||||
|
||||
(function () {
|
||||
module.exports = {"name":"traverse","version":"0.4.4","description":"Traverse and transform objects by visiting every node on a recursive walk","author":"James Halliday","license":"MIT/X11","main":"./index","repository":{"type":"git","url":"http://github.com/substack/js-traverse.git"},"devDependencies":{"expresso":"0.7.x"},"scripts":{"test":"expresso"}};
|
||||
}).call(module.exports);
|
||||
|
||||
__require.modules["/node_modules/traverse/package.json"]._cached = module.exports;
|
||||
return module.exports;
|
||||
};
|
||||
|
||||
require.modules["/node_modules/traverse/index.js"] = function () {
|
||||
var module = { exports : {} };
|
||||
var exports = module.exports;
|
||||
var __dirname = "/node_modules/traverse";
|
||||
var __filename = "/node_modules/traverse/index.js";
|
||||
|
||||
var require = function (file) {
|
||||
return __require(file, "/node_modules/traverse");
|
||||
};
|
||||
|
||||
require.resolve = function (file) {
|
||||
return __require.resolve(name, "/node_modules/traverse");
|
||||
};
|
||||
|
||||
require.modules = __require.modules;
|
||||
__require.modules["/node_modules/traverse/index.js"]._cached = module.exports;
|
||||
|
||||
(function () {
|
||||
module.exports = Traverse;
|
||||
function Traverse (obj) {
|
||||
if (!(this instanceof Traverse)) return new Traverse(obj);
|
||||
this.value = obj;
|
||||
}
|
||||
|
||||
Traverse.prototype.get = function (ps) {
|
||||
var node = this.value;
|
||||
for (var i = 0; i < ps.length; i ++) {
|
||||
var key = ps[i];
|
||||
if (!Object.hasOwnProperty.call(node, key)) {
|
||||
node = undefined;
|
||||
break;
|
||||
}
|
||||
node = node[key];
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
Traverse.prototype.set = function (ps, value) {
|
||||
var node = this.value;
|
||||
for (var i = 0; i < ps.length - 1; i ++) {
|
||||
var key = ps[i];
|
||||
if (!Object.hasOwnProperty.call(node, key)) node[key] = {};
|
||||
node = node[key];
|
||||
}
|
||||
node[ps[i]] = value;
|
||||
return value;
|
||||
};
|
||||
|
||||
Traverse.prototype.map = function (cb) {
|
||||
return walk(this.value, cb, true);
|
||||
};
|
||||
|
||||
Traverse.prototype.forEach = function (cb) {
|
||||
this.value = walk(this.value, cb, false);
|
||||
return this.value;
|
||||
};
|
||||
|
||||
Traverse.prototype.reduce = function (cb, init) {
|
||||
var skip = arguments.length === 1;
|
||||
var acc = skip ? this.value : init;
|
||||
this.forEach(function (x) {
|
||||
if (!this.isRoot || !skip) {
|
||||
acc = cb.call(this, acc, x);
|
||||
}
|
||||
});
|
||||
return acc;
|
||||
};
|
||||
|
||||
Traverse.prototype.deepEqual = function (obj) {
|
||||
if (arguments.length !== 1) {
|
||||
throw new Error(
|
||||
'deepEqual requires exactly one object to compare against'
|
||||
);
|
||||
}
|
||||
|
||||
var equal = true;
|
||||
var node = obj;
|
||||
|
||||
this.forEach(function (y) {
|
||||
var notEqual = (function () {
|
||||
equal = false;
|
||||
//this.stop();
|
||||
return undefined;
|
||||
}).bind(this);
|
||||
|
||||
//if (node === undefined || node === null) return notEqual();
|
||||
|
||||
if (!this.isRoot) {
|
||||
/*
|
||||
if (!Object.hasOwnProperty.call(node, this.key)) {
|
||||
return notEqual();
|
||||
}
|
||||
*/
|
||||
if (typeof node !== 'object') return notEqual();
|
||||
node = node[this.key];
|
||||
}
|
||||
|
||||
var x = node;
|
||||
|
||||
this.post(function () {
|
||||
node = x;
|
||||
});
|
||||
|
||||
var toS = function (o) {
|
||||
return Object.prototype.toString.call(o);
|
||||
};
|
||||
|
||||
if (this.circular) {
|
||||
if (Traverse(obj).get(this.circular.path) !== x) notEqual();
|
||||
}
|
||||
else if (typeof x !== typeof y) {
|
||||
notEqual();
|
||||
}
|
||||
else if (x === null || y === null || x === undefined || y === undefined) {
|
||||
if (x !== y) notEqual();
|
||||
}
|
||||
else if (x.__proto__ !== y.__proto__) {
|
||||
notEqual();
|
||||
}
|
||||
else if (x === y) {
|
||||
// nop
|
||||
}
|
||||
else if (typeof x === 'function') {
|
||||
if (x instanceof RegExp) {
|
||||
// both regexps on account of the __proto__ check
|
||||
if (x.toString() != y.toString()) notEqual();
|
||||
}
|
||||
else if (x !== y) notEqual();
|
||||
}
|
||||
else if (typeof x === 'object') {
|
||||
if (toS(y) === '[object Arguments]'
|
||||
|| toS(x) === '[object Arguments]') {
|
||||
if (toS(x) !== toS(y)) {
|
||||
notEqual();
|
||||
}
|
||||
}
|
||||
else if (x instanceof Date || y instanceof Date) {
|
||||
if (!(x instanceof Date) || !(y instanceof Date)
|
||||
|| x.getTime() !== y.getTime()) {
|
||||
notEqual();
|
||||
}
|
||||
}
|
||||
else {
|
||||
var kx = Object.keys(x);
|
||||
var ky = Object.keys(y);
|
||||
if (kx.length !== ky.length) return notEqual();
|
||||
for (var i = 0; i < kx.length; i++) {
|
||||
var k = kx[i];
|
||||
if (!Object.hasOwnProperty.call(y, k)) {
|
||||
notEqual();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return equal;
|
||||
};
|
||||
|
||||
Traverse.prototype.paths = function () {
|
||||
var acc = [];
|
||||
this.forEach(function (x) {
|
||||
acc.push(this.path);
|
||||
});
|
||||
return acc;
|
||||
};
|
||||
|
||||
Traverse.prototype.nodes = function () {
|
||||
var acc = [];
|
||||
this.forEach(function (x) {
|
||||
acc.push(this.node);
|
||||
});
|
||||
return acc;
|
||||
};
|
||||
|
||||
Traverse.prototype.clone = function () {
|
||||
var parents = [], nodes = [];
|
||||
|
||||
return (function clone (src) {
|
||||
for (var i = 0; i < parents.length; i++) {
|
||||
if (parents[i] === src) {
|
||||
return nodes[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof src === 'object' && src !== null) {
|
||||
var dst = copy(src);
|
||||
|
||||
parents.push(src);
|
||||
nodes.push(dst);
|
||||
|
||||
Object.keys(src).forEach(function (key) {
|
||||
dst[key] = clone(src[key]);
|
||||
});
|
||||
|
||||
parents.pop();
|
||||
nodes.pop();
|
||||
return dst;
|
||||
}
|
||||
else {
|
||||
return src;
|
||||
}
|
||||
})(this.value);
|
||||
};
|
||||
|
||||
function walk (root, cb, immutable) {
|
||||
var path = [];
|
||||
var parents = [];
|
||||
var alive = true;
|
||||
|
||||
return (function walker (node_) {
|
||||
var node = immutable ? copy(node_) : node_;
|
||||
var modifiers = {};
|
||||
|
||||
var keepGoing = true;
|
||||
|
||||
var state = {
|
||||
node : node,
|
||||
node_ : node_,
|
||||
path : [].concat(path),
|
||||
parent : parents[parents.length - 1],
|
||||
key : path.slice(-1)[0],
|
||||
isRoot : path.length === 0,
|
||||
level : path.length,
|
||||
circular : null,
|
||||
update : function (x, stopHere) {
|
||||
if (!state.isRoot) {
|
||||
state.parent.node[state.key] = x;
|
||||
}
|
||||
state.node = x;
|
||||
if (stopHere) keepGoing = false;
|
||||
},
|
||||
'delete' : function () {
|
||||
delete state.parent.node[state.key];
|
||||
},
|
||||
remove : function () {
|
||||
if (Array.isArray(state.parent.node)) {
|
||||
state.parent.node.splice(state.key, 1);
|
||||
}
|
||||
else {
|
||||
delete state.parent.node[state.key];
|
||||
}
|
||||
},
|
||||
before : function (f) { modifiers.before = f },
|
||||
after : function (f) { modifiers.after = f },
|
||||
pre : function (f) { modifiers.pre = f },
|
||||
post : function (f) { modifiers.post = f },
|
||||
stop : function () { alive = false },
|
||||
block : function () { keepGoing = false }
|
||||
};
|
||||
|
||||
if (!alive) return state;
|
||||
|
||||
if (typeof node === 'object' && node !== null) {
|
||||
state.isLeaf = Object.keys(node).length == 0;
|
||||
|
||||
for (var i = 0; i < parents.length; i++) {
|
||||
if (parents[i].node_ === node_) {
|
||||
state.circular = parents[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
state.isLeaf = true;
|
||||
}
|
||||
|
||||
state.notLeaf = !state.isLeaf;
|
||||
state.notRoot = !state.isRoot;
|
||||
|
||||
// use return values to update if defined
|
||||
var ret = cb.call(state, state.node);
|
||||
if (ret !== undefined && state.update) state.update(ret);
|
||||
state.keys = null;
|
||||
if (modifiers.before) modifiers.before.call(state, state.node);
|
||||
|
||||
if (!keepGoing) return state;
|
||||
|
||||
if (typeof state.node == 'object'
|
||||
&& state.node !== null && !state.circular) {
|
||||
parents.push(state);
|
||||
|
||||
var keys = state.keys || Object.keys(state.node);
|
||||
keys.forEach(function (key, i) {
|
||||
path.push(key);
|
||||
|
||||
if (modifiers.pre) modifiers.pre.call(state, state.node[key], key);
|
||||
|
||||
var child = walker(state.node[key]);
|
||||
if (immutable && Object.hasOwnProperty.call(state.node, key)) {
|
||||
state.node[key] = child.node;
|
||||
}
|
||||
|
||||
child.isLast = i == keys.length - 1;
|
||||
child.isFirst = i == 0;
|
||||
|
||||
if (modifiers.post) modifiers.post.call(state, child);
|
||||
|
||||
path.pop();
|
||||
});
|
||||
parents.pop();
|
||||
}
|
||||
|
||||
if (modifiers.after) modifiers.after.call(state, state.node);
|
||||
|
||||
return state;
|
||||
})(root).node;
|
||||
}
|
||||
|
||||
Object.keys(Traverse.prototype).forEach(function (key) {
|
||||
Traverse[key] = function (obj) {
|
||||
var args = [].slice.call(arguments, 1);
|
||||
var t = Traverse(obj);
|
||||
return t[key].apply(t, args);
|
||||
};
|
||||
});
|
||||
|
||||
function copy (src) {
|
||||
if (typeof src === 'object' && src !== null) {
|
||||
var dst;
|
||||
|
||||
if (Array.isArray(src)) {
|
||||
dst = [];
|
||||
}
|
||||
else if (src instanceof Date) {
|
||||
dst = new Date(src);
|
||||
}
|
||||
else if (src instanceof Boolean) {
|
||||
dst = new Boolean(src);
|
||||
}
|
||||
else if (src instanceof Number) {
|
||||
dst = new Number(src);
|
||||
}
|
||||
else if (src instanceof String) {
|
||||
dst = new String(src);
|
||||
}
|
||||
else {
|
||||
dst = Object.create(Object.getPrototypeOf(src));
|
||||
}
|
||||
|
||||
Object.keys(src).forEach(function (key) {
|
||||
dst[key] = src[key];
|
||||
});
|
||||
return dst;
|
||||
}
|
||||
else return src;
|
||||
}
|
||||
;
|
||||
}).call(module.exports);
|
||||
|
||||
__require.modules["/node_modules/traverse/index.js"]._cached = module.exports;
|
||||
return module.exports;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user