Comparing version 0.2.2 to 0.3.0
@@ -1,8 +0,8 @@ | ||
import { IObject } from "@daybrush/utils"; | ||
declare class OrderMap<T = number | string> { | ||
private separator; | ||
orderMap: IObject<T[]>; | ||
orderMap: Record<string, T[]>; | ||
constructor(separator: string); | ||
getFullName(names: T[]): string; | ||
get(names: T[]): T[] | undefined; | ||
hasName(names: T[]): boolean; | ||
gets(names: T[], isFull?: boolean): T[][]; | ||
@@ -17,6 +17,6 @@ set(names: T[], orders: T[]): T[]; | ||
clear(): void; | ||
setObject(obj: IObject<T[]>): void; | ||
getObject(): IObject<T[]>; | ||
setObject(obj: Record<string, T[]>): void; | ||
getObject(): Record<string, T[]>; | ||
clone(): OrderMap<T>; | ||
} | ||
export default OrderMap; |
@@ -7,236 +7,218 @@ /* | ||
repository: git+https://github.com/daybrush/order-map.git | ||
version: 0.2.2 | ||
version: 0.3.0 | ||
*/ | ||
'use strict'; | ||
/** | ||
* | ||
*/ | ||
var OrderMap = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
* | ||
*/ | ||
function OrderMap(separator) { | ||
this.separator = separator; | ||
this.orderMap = {}; | ||
} | ||
/** | ||
* | ||
*/ | ||
/****************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
var __proto = OrderMap.prototype; | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
__proto.getFullName = function (names) { | ||
return names.join(this.separator); | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.get = function (names) { | ||
return this.orderMap[this.getFullName(names)]; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.gets = function (names, isFull) { | ||
if (isFull === void 0) { | ||
isFull = true; | ||
} | ||
var fullOrders = []; | ||
var self = this; | ||
function pushOrders(nextNames, stack) { | ||
var orders = self.get(nextNames); | ||
if (!orders) { | ||
return; | ||
} | ||
orders.forEach(function (name) { | ||
var nextStack = stack.concat([name]); | ||
var nextOrders = pushOrders(nextNames.concat([name]), nextStack); | ||
if (!nextOrders || !nextOrders.length) { | ||
fullOrders.push(stack.concat([name])); | ||
function __spreadArray(to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
}); | ||
return orders; | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
} | ||
pushOrders(names, isFull ? names : []); | ||
return fullOrders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.set = function (names, orders) { | ||
var _this = this; | ||
names.forEach(function (name, i) { | ||
_this.addName(names.slice(0, i), name); | ||
}); | ||
this.orderMap[this.getFullName(names)] = orders; | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.add = function (names) { | ||
var length = names.length; | ||
if (!length) { | ||
return []; | ||
/** | ||
* | ||
*/ | ||
var OrderMap = /*#__PURE__*/ (function () { | ||
/** | ||
* | ||
*/ | ||
function OrderMap(separator) { | ||
this.separator = separator; | ||
this.orderMap = {}; | ||
} | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.getFullName = function (names) { | ||
return names.join(this.separator); | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.get = function (names) { | ||
return this.orderMap[this.getFullName(names)]; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.hasName = function (names) { | ||
var length = names.length; | ||
if (!length) { | ||
return false; | ||
} | ||
var lastName = names[length - 1]; | ||
var arr = this.get(names.slice(0, length - 1)); | ||
if (arr) { | ||
return arr.indexOf(lastName) >= 0; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.gets = function (names, isFull) { | ||
if (isFull === void 0) { isFull = true; } | ||
var fullOrders = []; | ||
var self = this; | ||
function pushOrders(nextNames, stack) { | ||
var orders = self.get(nextNames); | ||
if (!orders) { | ||
return; | ||
} | ||
orders.forEach(function (name) { | ||
var nextStack = __spreadArray(__spreadArray([], stack, true), [name], false); | ||
var nextOrders = pushOrders(__spreadArray(__spreadArray([], nextNames, true), [name], false), nextStack); | ||
if (!nextOrders || !nextOrders.length) { | ||
fullOrders.push(__spreadArray(__spreadArray([], stack, true), [name], false)); | ||
} | ||
}); | ||
return orders; | ||
} | ||
pushOrders(names, isFull ? names : []); | ||
return fullOrders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.set = function (names, orders) { | ||
var _this = this; | ||
names.forEach(function (name, i) { | ||
_this.addName(names.slice(0, i), name); | ||
}); | ||
this.orderMap[this.getFullName(names)] = orders; | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.add = function (names) { | ||
var length = names.length; | ||
if (!length) { | ||
return []; | ||
} | ||
return this.addName(names.slice(0, -1), names[length - 1]); | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.addName = function (names, name) { | ||
var orders = this.get(names) || this.set(names, []); | ||
if (orders.indexOf(name) === -1) { | ||
orders.push(name); | ||
} | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.findIndex = function (names, orderName) { | ||
var orders = this.orderMap[this.getFullName(names)]; | ||
if (!orders) { | ||
return -1; | ||
} | ||
return orders.indexOf(orderName); | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.remove = function (names) { | ||
var fullName = this.getFullName(names); | ||
var orderMap = this.orderMap; | ||
for (var name_1 in orderMap) { | ||
if (name_1.indexOf(fullName) === 0) { | ||
delete orderMap[name_1]; | ||
} | ||
} | ||
var length = names.length; | ||
if (length) { | ||
var prevNames = names.slice(0, -1); | ||
var lastName = names[length - 1]; | ||
this.splice(prevNames, this.findIndex(prevNames, lastName), 1); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.filter = function (names, callback, isFull) { | ||
if (isFull === void 0) { isFull = true; } | ||
var result = this.gets(names, isFull).filter(callback); | ||
var map = new OrderMap(this.separator); | ||
var stack = isFull ? [] : names; | ||
result.forEach(function (nextNames) { | ||
map.add(__spreadArray(__spreadArray([], stack, true), nextNames, true)); | ||
}); | ||
return map; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.splice = function (names, index, deleteCount) { | ||
var orders = []; | ||
for (var _i = 3; _i < arguments.length; _i++) { | ||
orders[_i - 3] = arguments[_i]; | ||
} | ||
var currentOrders = this.get(names) || this.set(names, []); | ||
currentOrders.splice.apply(currentOrders, __spreadArray([index, deleteCount], orders, false)); | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.clear = function () { | ||
this.orderMap = {}; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.setObject = function (obj) { | ||
var orderMap = this.orderMap; | ||
for (var name_2 in obj) { | ||
orderMap[name_2] = obj[name_2].slice(); | ||
} | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.getObject = function () { | ||
var nextMap = {}; | ||
var orderMap = this.orderMap; | ||
for (var name_3 in orderMap) { | ||
nextMap[name_3] = orderMap[name_3].slice(); | ||
} | ||
return nextMap; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.clone = function () { | ||
var map = new OrderMap(this.separator); | ||
map.setObject(map.orderMap); | ||
return map; | ||
}; | ||
return OrderMap; | ||
}()); | ||
return this.addName(names.slice(0, -1), names[length - 1]); | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.addName = function (names, name) { | ||
var orders = this.get(names) || this.set(names, []); | ||
if (orders.indexOf(name) === -1) { | ||
orders.push(name); | ||
} | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.findIndex = function (names, orderName) { | ||
var orders = this.orderMap[this.getFullName(names)]; | ||
if (!orders) { | ||
return -1; | ||
} | ||
return orders.indexOf(orderName); | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.remove = function (names) { | ||
var fullName = this.getFullName(names); | ||
var orderMap = this.orderMap; | ||
for (var name in orderMap) { | ||
if (name.indexOf(fullName) === 0) { | ||
delete orderMap[name]; | ||
} | ||
} | ||
var length = names.length; | ||
if (length) { | ||
var prevNames = names.slice(0, -1); | ||
var lastName = names[length - 1]; | ||
this.splice(prevNames, this.findIndex(prevNames, lastName), 1); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.filter = function (names, callback, isFull) { | ||
if (isFull === void 0) { | ||
isFull = true; | ||
} | ||
var result = this.gets(names, isFull).filter(callback); | ||
var map = new OrderMap(this.separator); | ||
var stack = isFull ? [] : names; | ||
result.forEach(function (nextNames) { | ||
map.add(stack.concat(nextNames)); | ||
}); | ||
return map; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.splice = function (names, index, deleteCount) { | ||
var orders = []; | ||
for (var _i = 3; _i < arguments.length; _i++) { | ||
orders[_i - 3] = arguments[_i]; | ||
} | ||
var currentOrders = this.get(names) || this.set(names, []); | ||
currentOrders.splice.apply(currentOrders, [index, deleteCount].concat(orders)); | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.clear = function () { | ||
this.orderMap = {}; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.setObject = function (obj) { | ||
var orderMap = this.orderMap; | ||
for (var name in obj) { | ||
orderMap[name] = obj[name].slice(); | ||
} | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.getObject = function () { | ||
var nextMap = {}; | ||
var orderMap = this.orderMap; | ||
for (var name in orderMap) { | ||
nextMap[name] = orderMap[name].slice(); | ||
} | ||
return nextMap; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.clone = function () { | ||
var map = new OrderMap(this.separator); | ||
map.setObject(map.orderMap); | ||
return map; | ||
}; | ||
return OrderMap; | ||
}(); | ||
module.exports = OrderMap; | ||
exports.default = OrderMap; | ||
//# sourceMappingURL=order-map.cjs.js.map |
@@ -7,234 +7,216 @@ /* | ||
repository: git+https://github.com/daybrush/order-map.git | ||
version: 0.2.2 | ||
version: 0.3.0 | ||
*/ | ||
/** | ||
* | ||
*/ | ||
var OrderMap = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
* | ||
*/ | ||
function OrderMap(separator) { | ||
this.separator = separator; | ||
this.orderMap = {}; | ||
} | ||
/** | ||
* | ||
*/ | ||
/****************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
var __proto = OrderMap.prototype; | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
__proto.getFullName = function (names) { | ||
return names.join(this.separator); | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.get = function (names) { | ||
return this.orderMap[this.getFullName(names)]; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.gets = function (names, isFull) { | ||
if (isFull === void 0) { | ||
isFull = true; | ||
} | ||
var fullOrders = []; | ||
var self = this; | ||
function pushOrders(nextNames, stack) { | ||
var orders = self.get(nextNames); | ||
if (!orders) { | ||
return; | ||
} | ||
orders.forEach(function (name) { | ||
var nextStack = stack.concat([name]); | ||
var nextOrders = pushOrders(nextNames.concat([name]), nextStack); | ||
if (!nextOrders || !nextOrders.length) { | ||
fullOrders.push(stack.concat([name])); | ||
function __spreadArray(to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
}); | ||
return orders; | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
} | ||
pushOrders(names, isFull ? names : []); | ||
return fullOrders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.set = function (names, orders) { | ||
var _this = this; | ||
names.forEach(function (name, i) { | ||
_this.addName(names.slice(0, i), name); | ||
}); | ||
this.orderMap[this.getFullName(names)] = orders; | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.add = function (names) { | ||
var length = names.length; | ||
if (!length) { | ||
return []; | ||
/** | ||
* | ||
*/ | ||
var OrderMap = /*#__PURE__*/ (function () { | ||
/** | ||
* | ||
*/ | ||
function OrderMap(separator) { | ||
this.separator = separator; | ||
this.orderMap = {}; | ||
} | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.getFullName = function (names) { | ||
return names.join(this.separator); | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.get = function (names) { | ||
return this.orderMap[this.getFullName(names)]; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.hasName = function (names) { | ||
var length = names.length; | ||
if (!length) { | ||
return false; | ||
} | ||
var lastName = names[length - 1]; | ||
var arr = this.get(names.slice(0, length - 1)); | ||
if (arr) { | ||
return arr.indexOf(lastName) >= 0; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.gets = function (names, isFull) { | ||
if (isFull === void 0) { isFull = true; } | ||
var fullOrders = []; | ||
var self = this; | ||
function pushOrders(nextNames, stack) { | ||
var orders = self.get(nextNames); | ||
if (!orders) { | ||
return; | ||
} | ||
orders.forEach(function (name) { | ||
var nextStack = __spreadArray(__spreadArray([], stack, true), [name], false); | ||
var nextOrders = pushOrders(__spreadArray(__spreadArray([], nextNames, true), [name], false), nextStack); | ||
if (!nextOrders || !nextOrders.length) { | ||
fullOrders.push(__spreadArray(__spreadArray([], stack, true), [name], false)); | ||
} | ||
}); | ||
return orders; | ||
} | ||
pushOrders(names, isFull ? names : []); | ||
return fullOrders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.set = function (names, orders) { | ||
var _this = this; | ||
names.forEach(function (name, i) { | ||
_this.addName(names.slice(0, i), name); | ||
}); | ||
this.orderMap[this.getFullName(names)] = orders; | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.add = function (names) { | ||
var length = names.length; | ||
if (!length) { | ||
return []; | ||
} | ||
return this.addName(names.slice(0, -1), names[length - 1]); | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.addName = function (names, name) { | ||
var orders = this.get(names) || this.set(names, []); | ||
if (orders.indexOf(name) === -1) { | ||
orders.push(name); | ||
} | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.findIndex = function (names, orderName) { | ||
var orders = this.orderMap[this.getFullName(names)]; | ||
if (!orders) { | ||
return -1; | ||
} | ||
return orders.indexOf(orderName); | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.remove = function (names) { | ||
var fullName = this.getFullName(names); | ||
var orderMap = this.orderMap; | ||
for (var name_1 in orderMap) { | ||
if (name_1.indexOf(fullName) === 0) { | ||
delete orderMap[name_1]; | ||
} | ||
} | ||
var length = names.length; | ||
if (length) { | ||
var prevNames = names.slice(0, -1); | ||
var lastName = names[length - 1]; | ||
this.splice(prevNames, this.findIndex(prevNames, lastName), 1); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.filter = function (names, callback, isFull) { | ||
if (isFull === void 0) { isFull = true; } | ||
var result = this.gets(names, isFull).filter(callback); | ||
var map = new OrderMap(this.separator); | ||
var stack = isFull ? [] : names; | ||
result.forEach(function (nextNames) { | ||
map.add(__spreadArray(__spreadArray([], stack, true), nextNames, true)); | ||
}); | ||
return map; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.splice = function (names, index, deleteCount) { | ||
var orders = []; | ||
for (var _i = 3; _i < arguments.length; _i++) { | ||
orders[_i - 3] = arguments[_i]; | ||
} | ||
var currentOrders = this.get(names) || this.set(names, []); | ||
currentOrders.splice.apply(currentOrders, __spreadArray([index, deleteCount], orders, false)); | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.clear = function () { | ||
this.orderMap = {}; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.setObject = function (obj) { | ||
var orderMap = this.orderMap; | ||
for (var name_2 in obj) { | ||
orderMap[name_2] = obj[name_2].slice(); | ||
} | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.getObject = function () { | ||
var nextMap = {}; | ||
var orderMap = this.orderMap; | ||
for (var name_3 in orderMap) { | ||
nextMap[name_3] = orderMap[name_3].slice(); | ||
} | ||
return nextMap; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.clone = function () { | ||
var map = new OrderMap(this.separator); | ||
map.setObject(map.orderMap); | ||
return map; | ||
}; | ||
return OrderMap; | ||
}()); | ||
return this.addName(names.slice(0, -1), names[length - 1]); | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.addName = function (names, name) { | ||
var orders = this.get(names) || this.set(names, []); | ||
if (orders.indexOf(name) === -1) { | ||
orders.push(name); | ||
} | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.findIndex = function (names, orderName) { | ||
var orders = this.orderMap[this.getFullName(names)]; | ||
if (!orders) { | ||
return -1; | ||
} | ||
return orders.indexOf(orderName); | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.remove = function (names) { | ||
var fullName = this.getFullName(names); | ||
var orderMap = this.orderMap; | ||
for (var name in orderMap) { | ||
if (name.indexOf(fullName) === 0) { | ||
delete orderMap[name]; | ||
} | ||
} | ||
var length = names.length; | ||
if (length) { | ||
var prevNames = names.slice(0, -1); | ||
var lastName = names[length - 1]; | ||
this.splice(prevNames, this.findIndex(prevNames, lastName), 1); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.filter = function (names, callback, isFull) { | ||
if (isFull === void 0) { | ||
isFull = true; | ||
} | ||
var result = this.gets(names, isFull).filter(callback); | ||
var map = new OrderMap(this.separator); | ||
var stack = isFull ? [] : names; | ||
result.forEach(function (nextNames) { | ||
map.add(stack.concat(nextNames)); | ||
}); | ||
return map; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.splice = function (names, index, deleteCount) { | ||
var orders = []; | ||
for (var _i = 3; _i < arguments.length; _i++) { | ||
orders[_i - 3] = arguments[_i]; | ||
} | ||
var currentOrders = this.get(names) || this.set(names, []); | ||
currentOrders.splice.apply(currentOrders, [index, deleteCount].concat(orders)); | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.clear = function () { | ||
this.orderMap = {}; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.setObject = function (obj) { | ||
var orderMap = this.orderMap; | ||
for (var name in obj) { | ||
orderMap[name] = obj[name].slice(); | ||
} | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.getObject = function () { | ||
var nextMap = {}; | ||
var orderMap = this.orderMap; | ||
for (var name in orderMap) { | ||
nextMap[name] = orderMap[name].slice(); | ||
} | ||
return nextMap; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.clone = function () { | ||
var map = new OrderMap(this.separator); | ||
map.setObject(map.orderMap); | ||
return map; | ||
}; | ||
return OrderMap; | ||
}(); | ||
export default OrderMap; | ||
export { OrderMap as default }; | ||
//# sourceMappingURL=order-map.esm.js.map |
@@ -7,3 +7,3 @@ /* | ||
repository: git+https://github.com/daybrush/order-map.git | ||
version: 0.2.2 | ||
version: 0.3.0 | ||
*/ | ||
@@ -13,234 +13,216 @@ (function (global, factory) { | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.OrderMap = factory()); | ||
}(this, function () { 'use strict'; | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.OrderMap = factory()); | ||
})(this, (function () { 'use strict'; | ||
/** | ||
* | ||
*/ | ||
var OrderMap = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
* | ||
*/ | ||
function OrderMap(separator) { | ||
this.separator = separator; | ||
this.orderMap = {}; | ||
} | ||
/** | ||
* | ||
*/ | ||
/****************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
var __proto = OrderMap.prototype; | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
__proto.getFullName = function (names) { | ||
return names.join(this.separator); | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.get = function (names) { | ||
return this.orderMap[this.getFullName(names)]; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.gets = function (names, isFull) { | ||
if (isFull === void 0) { | ||
isFull = true; | ||
} | ||
var fullOrders = []; | ||
var self = this; | ||
function pushOrders(nextNames, stack) { | ||
var orders = self.get(nextNames); | ||
if (!orders) { | ||
return; | ||
} | ||
orders.forEach(function (name) { | ||
var nextStack = stack.concat([name]); | ||
var nextOrders = pushOrders(nextNames.concat([name]), nextStack); | ||
if (!nextOrders || !nextOrders.length) { | ||
fullOrders.push(stack.concat([name])); | ||
function __spreadArray(to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
}); | ||
return orders; | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
} | ||
pushOrders(names, isFull ? names : []); | ||
return fullOrders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.set = function (names, orders) { | ||
var _this = this; | ||
names.forEach(function (name, i) { | ||
_this.addName(names.slice(0, i), name); | ||
}); | ||
this.orderMap[this.getFullName(names)] = orders; | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.add = function (names) { | ||
var length = names.length; | ||
if (!length) { | ||
return []; | ||
/** | ||
* | ||
*/ | ||
var OrderMap = /*#__PURE__*/ (function () { | ||
/** | ||
* | ||
*/ | ||
function OrderMap(separator) { | ||
this.separator = separator; | ||
this.orderMap = {}; | ||
} | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.getFullName = function (names) { | ||
return names.join(this.separator); | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.get = function (names) { | ||
return this.orderMap[this.getFullName(names)]; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.hasName = function (names) { | ||
var length = names.length; | ||
if (!length) { | ||
return false; | ||
} | ||
var lastName = names[length - 1]; | ||
var arr = this.get(names.slice(0, length - 1)); | ||
if (arr) { | ||
return arr.indexOf(lastName) >= 0; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.gets = function (names, isFull) { | ||
if (isFull === void 0) { isFull = true; } | ||
var fullOrders = []; | ||
var self = this; | ||
function pushOrders(nextNames, stack) { | ||
var orders = self.get(nextNames); | ||
if (!orders) { | ||
return; | ||
} | ||
orders.forEach(function (name) { | ||
var nextStack = __spreadArray(__spreadArray([], stack, true), [name], false); | ||
var nextOrders = pushOrders(__spreadArray(__spreadArray([], nextNames, true), [name], false), nextStack); | ||
if (!nextOrders || !nextOrders.length) { | ||
fullOrders.push(__spreadArray(__spreadArray([], stack, true), [name], false)); | ||
} | ||
}); | ||
return orders; | ||
} | ||
pushOrders(names, isFull ? names : []); | ||
return fullOrders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.set = function (names, orders) { | ||
var _this = this; | ||
names.forEach(function (name, i) { | ||
_this.addName(names.slice(0, i), name); | ||
}); | ||
this.orderMap[this.getFullName(names)] = orders; | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.add = function (names) { | ||
var length = names.length; | ||
if (!length) { | ||
return []; | ||
} | ||
return this.addName(names.slice(0, -1), names[length - 1]); | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.addName = function (names, name) { | ||
var orders = this.get(names) || this.set(names, []); | ||
if (orders.indexOf(name) === -1) { | ||
orders.push(name); | ||
} | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.findIndex = function (names, orderName) { | ||
var orders = this.orderMap[this.getFullName(names)]; | ||
if (!orders) { | ||
return -1; | ||
} | ||
return orders.indexOf(orderName); | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.remove = function (names) { | ||
var fullName = this.getFullName(names); | ||
var orderMap = this.orderMap; | ||
for (var name_1 in orderMap) { | ||
if (name_1.indexOf(fullName) === 0) { | ||
delete orderMap[name_1]; | ||
} | ||
} | ||
var length = names.length; | ||
if (length) { | ||
var prevNames = names.slice(0, -1); | ||
var lastName = names[length - 1]; | ||
this.splice(prevNames, this.findIndex(prevNames, lastName), 1); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.filter = function (names, callback, isFull) { | ||
if (isFull === void 0) { isFull = true; } | ||
var result = this.gets(names, isFull).filter(callback); | ||
var map = new OrderMap(this.separator); | ||
var stack = isFull ? [] : names; | ||
result.forEach(function (nextNames) { | ||
map.add(__spreadArray(__spreadArray([], stack, true), nextNames, true)); | ||
}); | ||
return map; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.splice = function (names, index, deleteCount) { | ||
var orders = []; | ||
for (var _i = 3; _i < arguments.length; _i++) { | ||
orders[_i - 3] = arguments[_i]; | ||
} | ||
var currentOrders = this.get(names) || this.set(names, []); | ||
currentOrders.splice.apply(currentOrders, __spreadArray([index, deleteCount], orders, false)); | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.clear = function () { | ||
this.orderMap = {}; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.setObject = function (obj) { | ||
var orderMap = this.orderMap; | ||
for (var name_2 in obj) { | ||
orderMap[name_2] = obj[name_2].slice(); | ||
} | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.getObject = function () { | ||
var nextMap = {}; | ||
var orderMap = this.orderMap; | ||
for (var name_3 in orderMap) { | ||
nextMap[name_3] = orderMap[name_3].slice(); | ||
} | ||
return nextMap; | ||
}; | ||
/** | ||
* | ||
*/ | ||
OrderMap.prototype.clone = function () { | ||
var map = new OrderMap(this.separator); | ||
map.setObject(map.orderMap); | ||
return map; | ||
}; | ||
return OrderMap; | ||
}()); | ||
return this.addName(names.slice(0, -1), names[length - 1]); | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.addName = function (names, name) { | ||
var orders = this.get(names) || this.set(names, []); | ||
if (orders.indexOf(name) === -1) { | ||
orders.push(name); | ||
} | ||
return orders; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.findIndex = function (names, orderName) { | ||
var orders = this.orderMap[this.getFullName(names)]; | ||
if (!orders) { | ||
return -1; | ||
} | ||
return orders.indexOf(orderName); | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.remove = function (names) { | ||
var fullName = this.getFullName(names); | ||
var orderMap = this.orderMap; | ||
for (var name in orderMap) { | ||
if (name.indexOf(fullName) === 0) { | ||
delete orderMap[name]; | ||
} | ||
} | ||
var length = names.length; | ||
if (length) { | ||
var prevNames = names.slice(0, -1); | ||
var lastName = names[length - 1]; | ||
this.splice(prevNames, this.findIndex(prevNames, lastName), 1); | ||
} | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.filter = function (names, callback, isFull) { | ||
if (isFull === void 0) { | ||
isFull = true; | ||
} | ||
var result = this.gets(names, isFull).filter(callback); | ||
var map = new OrderMap(this.separator); | ||
var stack = isFull ? [] : names; | ||
result.forEach(function (nextNames) { | ||
map.add(stack.concat(nextNames)); | ||
}); | ||
return map; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.splice = function (names, index, deleteCount) { | ||
var orders = []; | ||
for (var _i = 3; _i < arguments.length; _i++) { | ||
orders[_i - 3] = arguments[_i]; | ||
} | ||
var currentOrders = this.get(names) || this.set(names, []); | ||
currentOrders.splice.apply(currentOrders, [index, deleteCount].concat(orders)); | ||
return this; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.clear = function () { | ||
this.orderMap = {}; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.setObject = function (obj) { | ||
var orderMap = this.orderMap; | ||
for (var name in obj) { | ||
orderMap[name] = obj[name].slice(); | ||
} | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.getObject = function () { | ||
var nextMap = {}; | ||
var orderMap = this.orderMap; | ||
for (var name in orderMap) { | ||
nextMap[name] = orderMap[name].slice(); | ||
} | ||
return nextMap; | ||
}; | ||
/** | ||
* | ||
*/ | ||
__proto.clone = function () { | ||
var map = new OrderMap(this.separator); | ||
map.setObject(map.orderMap); | ||
return map; | ||
}; | ||
return OrderMap; | ||
}(); | ||
return OrderMap; | ||
@@ -247,0 +229,0 @@ |
@@ -7,5 +7,5 @@ /* | ||
repository: git+https://github.com/daybrush/order-map.git | ||
version: 0.2.2 | ||
version: 0.3.0 | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).OrderMap=e()}(this,function(){"use strict";return function(){function a(t){this.separator=t,this.orderMap={}}var t=a.prototype;return t.getFullName=function(t){return t.join(this.separator)},t.get=function(t){return this.orderMap[this.getFullName(t)]},t.gets=function(t,e){void 0===e&&(e=!0);var a=[],r=this;return function n(i,o){var t=r.get(i);if(t)return t.forEach(function(t){var e=o.concat([t]),r=n(i.concat([t]),e);r&&r.length||a.push(o.concat([t]))}),t}(t,e?t:[]),a},t.set=function(r,t){var n=this;return r.forEach(function(t,e){n.addName(r.slice(0,e),t)}),this.orderMap[this.getFullName(r)]=t},t.add=function(t){var e=t.length;return e?this.addName(t.slice(0,-1),t[e-1]):[]},t.addName=function(t,e){var r=this.get(t)||this.set(t,[]);return-1===r.indexOf(e)&&r.push(e),r},t.findIndex=function(t,e){var r=this.orderMap[this.getFullName(t)];return r?r.indexOf(e):-1},t.remove=function(t){var e=this.getFullName(t),r=this.orderMap;for(var n in r)0===n.indexOf(e)&&delete r[n];var i=t.length;if(i){var o=t.slice(0,-1),a=t[i-1];this.splice(o,this.findIndex(o,a),1)}return this},t.filter=function(t,e,r){void 0===r&&(r=!0);var n=this.gets(t,r).filter(e),i=new a(this.separator),o=r?[]:t;return n.forEach(function(t){i.add(o.concat(t))}),i},t.splice=function(t,e,r){for(var n=[],i=3;i<arguments.length;i++)n[i-3]=arguments[i];var o=this.get(t)||this.set(t,[]);return o.splice.apply(o,[e,r].concat(n)),this},t.clear=function(){this.orderMap={}},t.setObject=function(t){var e=this.orderMap;for(var r in t)e[r]=t[r].slice()},t.getObject=function(){var t={},e=this.orderMap;for(var r in e)t[r]=e[r].slice();return t},t.clone=function(){var t=new a(this.separator);return t.setObject(t.orderMap),t},a}()}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).OrderMap=e()}(this,(function(){"use strict";function t(t,e,r){if(r||2===arguments.length)for(var n,o=0,i=e.length;o<i;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}var e=function(){function e(t){this.separator=t,this.orderMap={}}return e.prototype.getFullName=function(t){return t.join(this.separator)},e.prototype.get=function(t){return this.orderMap[this.getFullName(t)]},e.prototype.hasName=function(t){var e=t.length;if(!e)return!1;var r=t[e-1],n=this.get(t.slice(0,e-1));return!!n&&n.indexOf(r)>=0},e.prototype.gets=function(e,r){void 0===r&&(r=!0);var n=[],o=this;return function e(r,i){var a=o.get(r);if(a)return a.forEach((function(o){var a=t(t([],i,!0),[o],!1),s=e(t(t([],r,!0),[o],!1),a);s&&s.length||n.push(t(t([],i,!0),[o],!1))})),a}(e,r?e:[]),n},e.prototype.set=function(t,e){var r=this;return t.forEach((function(e,n){r.addName(t.slice(0,n),e)})),this.orderMap[this.getFullName(t)]=e,e},e.prototype.add=function(t){var e=t.length;return e?this.addName(t.slice(0,-1),t[e-1]):[]},e.prototype.addName=function(t,e){var r=this.get(t)||this.set(t,[]);return-1===r.indexOf(e)&&r.push(e),r},e.prototype.findIndex=function(t,e){var r=this.orderMap[this.getFullName(t)];return r?r.indexOf(e):-1},e.prototype.remove=function(t){var e=this.getFullName(t),r=this.orderMap;for(var n in r)0===n.indexOf(e)&&delete r[n];var o=t.length;if(o){var i=t.slice(0,-1),a=t[o-1];this.splice(i,this.findIndex(i,a),1)}return this},e.prototype.filter=function(r,n,o){void 0===o&&(o=!0);var i=this.gets(r,o).filter(n),a=new e(this.separator),s=o?[]:r;return i.forEach((function(e){a.add(t(t([],s,!0),e,!0))})),a},e.prototype.splice=function(e,r,n){for(var o=[],i=3;i<arguments.length;i++)o[i-3]=arguments[i];var a=this.get(e)||this.set(e,[]);return a.splice.apply(a,t([r,n],o,!1)),this},e.prototype.clear=function(){this.orderMap={}},e.prototype.setObject=function(t){var e=this.orderMap;for(var r in t)e[r]=t[r].slice()},e.prototype.getObject=function(){var t={},e=this.orderMap;for(var r in e)t[r]=e[r].slice();return t},e.prototype.clone=function(){var t=new e(this.separator);return t.setObject(t.orderMap),t},e}();return e})); | ||
//# sourceMappingURL=order-map.min.js.map |
{ | ||
"name": "order-map", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "A order-map collection in the form of key, value, that ensures the index.", | ||
@@ -31,8 +31,2 @@ "main": "./dist/order-map.cjs.js", | ||
"homepage": "https://github.com/daybrush/order-map#readme", | ||
"dependencies": { | ||
"@daybrush/utils": "^1.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@daybrush/utils": ">=1.0.0" | ||
}, | ||
"keywords": [ | ||
@@ -49,8 +43,8 @@ "order", | ||
"devDependencies": { | ||
"@daybrush/builder": "^0.1.0", | ||
"@daybrush/jsdoc": "^0.3.7", | ||
"@daybrush/release": "^0.2.4", | ||
"@daybrush/builder": "^0.2.4", | ||
"@daybrush/jsdoc": "^0.4.7", | ||
"@daybrush/release": "^0.7.1", | ||
"@types/jest": "^24.0.13", | ||
"coveralls": "^3.0.3", | ||
"daybrush-jsdoc-template": "^1.6.0", | ||
"daybrush-jsdoc-template": "^1.10.0", | ||
"jest": "^24.8.0", | ||
@@ -60,5 +54,6 @@ "print-coveralls": "^1.2.2", | ||
"ts-jest": "^24.0.2", | ||
"tslib": "^2.5.3", | ||
"tslint": "^5.16.0", | ||
"typescript": "^3.4.5" | ||
"typescript": "^4.5 <4.6" | ||
} | ||
} |
import builder from "@daybrush/builder"; | ||
const builder = require("@daybrush/builder"); | ||
export default builder([ | ||
module.exports = builder([ | ||
{ | ||
@@ -22,3 +22,3 @@ name: "OrderMap", | ||
output: "./dist/order-map.esm.js", | ||
exports: "default", | ||
exports: "named", | ||
format: "es", | ||
@@ -29,5 +29,5 @@ }, | ||
output: "./dist/order-map.cjs.js", | ||
exports: "default", | ||
exports: "named", | ||
format: "cjs", | ||
}, | ||
]); |
@@ -1,3 +0,1 @@ | ||
import { IObject } from "@daybrush/utils"; | ||
/** | ||
@@ -7,3 +5,3 @@ * | ||
class OrderMap<T = number | string> { | ||
public orderMap: IObject<T[]> = {}; | ||
public orderMap: Record<string, T[]> = {}; | ||
@@ -28,3 +26,20 @@ /** | ||
} | ||
/** | ||
* | ||
*/ | ||
public hasName(names: T[]) { | ||
const length = names.length; | ||
if (!length) { | ||
return false; | ||
} | ||
const lastName = names[length - 1]; | ||
const arr = this.get(names.slice(0, length - 1)); | ||
if (arr) { | ||
return arr.indexOf(lastName) >= 0; | ||
} | ||
return false; | ||
} | ||
/** | ||
@@ -169,3 +184,3 @@ * | ||
*/ | ||
public setObject(obj: IObject<T[]>) { | ||
public setObject(obj: Record<string, T[]>) { | ||
const orderMap = this.orderMap; | ||
@@ -180,3 +195,3 @@ | ||
*/ | ||
public getObject(): IObject<T[]> { | ||
public getObject(): Record<string, T[]> { | ||
const nextMap = {}; | ||
@@ -183,0 +198,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105118
0
23
1042
13
- Removed@daybrush/utils@^1.0.0
- Removed@daybrush/utils@1.13.0(transitive)