Comparing version 0.3.2 to 0.4.0
@@ -1,5 +0,5 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.lill=e()}}(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){ | ||
(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.lill = 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){ | ||
/* | ||
* The MIT License (MIT) | ||
* Copyright © 2014 Daniel K. (FredyC) | ||
* Copyright © 2015 Daniel K. (FredyC) | ||
* | ||
@@ -12,6 +12,6 @@ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* Version: 0.3.2 | ||
* Version: 0.4.0 | ||
*/ | ||
'use strict'; | ||
var LiLL, Symbol, add, attach, bData, bOwner, checkAttached, checkItem, clear, detach, each, each$noContext, each$withContext, getHead, getNext, getPrevious, getSize, getTail, has, idSequence, isAttached, remove; | ||
var LiLL, Symbol, add, attach, bData, bOwner, checkAttached, checkItem, clear, detach, each, find, func$noContext, func$withContext, getHead, getNext, getPrevious, getSize, getTail, has, idSequence, isAttached, remove; | ||
@@ -27,4 +27,4 @@ Symbol = require('es6-symbol'); | ||
attach = function(owner) { | ||
var data, _ref; | ||
if (!(owner && ((_ref = typeof owner) === 'object' || _ref === 'function'))) { | ||
var data, ref; | ||
if (!(owner && ((ref = typeof owner) === 'object' || ref === 'function'))) { | ||
throw new TypeError('LiLL.attach needs an object or function'); | ||
@@ -168,3 +168,3 @@ } | ||
} | ||
iterator = ctx !== void 0 ? each$withContext : each$noContext; | ||
iterator = ctx !== void 0 ? func$withContext : func$noContext; | ||
while (true) { | ||
@@ -181,7 +181,32 @@ next = item[data.next]; | ||
each$noContext = function(fn, item, i) { | ||
find = function(owner, predicate, ctx) { | ||
var data, func, i, item, next, result; | ||
data = checkAttached(owner); | ||
if (typeof predicate !== 'function') { | ||
throw new TypeError('LiLL.find method expects predicate function'); | ||
} | ||
if (!(item = data.head)) { | ||
return null; | ||
} | ||
func = ctx !== void 0 ? func$withContext : func$noContext; | ||
i = 0; | ||
while (true) { | ||
next = item[data.next]; | ||
result = func(predicate, item, i, ctx); | ||
if (result === true) { | ||
return item; | ||
} | ||
if (!(item = next)) { | ||
break; | ||
} | ||
i += 1; | ||
} | ||
return null; | ||
}; | ||
func$noContext = function(fn, item, i) { | ||
return fn(item, i); | ||
}; | ||
each$withContext = function(fn, item, i, ctx) { | ||
func$withContext = function(fn, item, i, ctx) { | ||
return fn.call(ctx, item, i); | ||
@@ -203,4 +228,4 @@ }; | ||
checkItem = function(owner, item, method) { | ||
var _ref; | ||
if (!(item && ((_ref = typeof item) === 'object' || _ref === 'function'))) { | ||
var ref; | ||
if (!(item && ((ref = typeof item) === 'object' || ref === 'function'))) { | ||
throw new TypeError("LiLL." + method + " needs an object or function to be added"); | ||
@@ -229,2 +254,3 @@ } | ||
each: each, | ||
find: find, | ||
isAttached: isAttached | ||
@@ -240,3 +266,3 @@ }; | ||
},{"./is-implemented":3,"./polyfill":17}],3:[function(require,module,exports){ | ||
},{"./is-implemented":3,"./polyfill":18}],3:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -248,5 +274,3 @@ | ||
symbol = Symbol('test symbol'); | ||
try { | ||
if (String(symbol) !== 'Symbol (test symbol)') return false; | ||
} catch (e) { return false; } | ||
try { String(symbol); } catch (e) { return false; } | ||
if (typeof Symbol.iterator === 'symbol') return true; | ||
@@ -256,3 +280,2 @@ | ||
if (typeof Symbol.isConcatSpreadable !== 'object') return false; | ||
if (typeof Symbol.isRegExp !== 'object') return false; | ||
if (typeof Symbol.iterator !== 'object') return false; | ||
@@ -269,2 +292,9 @@ if (typeof Symbol.toPrimitive !== 'object') return false; | ||
module.exports = function (x) { | ||
return (x && ((typeof x === 'symbol') || (x['@@toStringTag'] === 'Symbol'))) || false; | ||
}; | ||
},{}],5:[function(require,module,exports){ | ||
'use strict'; | ||
var assign = require('es5-ext/object/assign') | ||
@@ -332,3 +362,3 @@ , normalizeOpts = require('es5-ext/object/normalize-options') | ||
},{"es5-ext/object/assign":5,"es5-ext/object/is-callable":8,"es5-ext/object/normalize-options":12,"es5-ext/string/#/contains":14}],5:[function(require,module,exports){ | ||
},{"es5-ext/object/assign":6,"es5-ext/object/is-callable":9,"es5-ext/object/normalize-options":13,"es5-ext/string/#/contains":15}],6:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -340,3 +370,3 @@ | ||
},{"./is-implemented":6,"./shim":7}],6:[function(require,module,exports){ | ||
},{"./is-implemented":7,"./shim":8}],7:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -352,3 +382,3 @@ | ||
},{}],7:[function(require,module,exports){ | ||
},{}],8:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -377,3 +407,3 @@ | ||
},{"../keys":9,"../valid-value":13}],8:[function(require,module,exports){ | ||
},{"../keys":10,"../valid-value":14}],9:[function(require,module,exports){ | ||
// Deprecated | ||
@@ -385,3 +415,3 @@ | ||
},{}],9:[function(require,module,exports){ | ||
},{}],10:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -393,3 +423,3 @@ | ||
},{"./is-implemented":10,"./shim":11}],10:[function(require,module,exports){ | ||
},{"./is-implemented":11,"./shim":12}],11:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -404,3 +434,3 @@ | ||
},{}],11:[function(require,module,exports){ | ||
},{}],12:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -414,15 +444,10 @@ | ||
},{}],12:[function(require,module,exports){ | ||
},{}],13:[function(require,module,exports){ | ||
'use strict'; | ||
var assign = require('./assign') | ||
var forEach = Array.prototype.forEach, create = Object.create; | ||
, forEach = Array.prototype.forEach | ||
, create = Object.create, getPrototypeOf = Object.getPrototypeOf | ||
, process; | ||
process = function (src, obj) { | ||
var proto = getPrototypeOf(src); | ||
return assign(proto ? process(proto, obj) : obj, src); | ||
var process = function (src, obj) { | ||
var key; | ||
for (key in src) obj[key] = src[key]; | ||
}; | ||
@@ -439,3 +464,3 @@ | ||
},{"./assign":5}],13:[function(require,module,exports){ | ||
},{}],14:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -448,3 +473,3 @@ | ||
},{}],14:[function(require,module,exports){ | ||
},{}],15:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -456,3 +481,3 @@ | ||
},{"./is-implemented":15,"./shim":16}],15:[function(require,module,exports){ | ||
},{"./is-implemented":16,"./shim":17}],16:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -467,3 +492,3 @@ | ||
},{}],16:[function(require,module,exports){ | ||
},{}],17:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -477,27 +502,35 @@ | ||
},{}],17:[function(require,module,exports){ | ||
},{}],18:[function(require,module,exports){ | ||
'use strict'; | ||
var d = require('d') | ||
var d = require('d') | ||
, validateSymbol = require('./validate-symbol') | ||
, create = Object.create, defineProperties = Object.defineProperties | ||
, generateName, Symbol; | ||
, defineProperty = Object.defineProperty, objPrototype = Object.prototype | ||
, Symbol, HiddenSymbol, globalSymbols = create(null); | ||
generateName = (function () { | ||
var generateName = (function () { | ||
var created = create(null); | ||
return function (desc) { | ||
var postfix = 0; | ||
var postfix = 0, name; | ||
while (created[desc + (postfix || '')]) ++postfix; | ||
desc += (postfix || ''); | ||
created[desc] = true; | ||
return '@@' + desc; | ||
name = '@@' + desc; | ||
defineProperty(objPrototype, name, d.gs(null, function (value) { | ||
defineProperty(this, name, d(value)); | ||
})); | ||
return name; | ||
}; | ||
}()); | ||
module.exports = Symbol = function (description) { | ||
HiddenSymbol = function Symbol(description) { | ||
if (this instanceof HiddenSymbol) throw new TypeError('TypeError: Symbol is not a constructor'); | ||
return Symbol(description); | ||
}; | ||
module.exports = Symbol = function Symbol(description) { | ||
var symbol; | ||
if (this instanceof Symbol) { | ||
throw new TypeError('TypeError: Symbol is not a constructor'); | ||
} | ||
symbol = create(Symbol.prototype); | ||
if (this instanceof Symbol) throw new TypeError('TypeError: Symbol is not a constructor'); | ||
symbol = create(HiddenSymbol.prototype); | ||
description = (description === undefined ? '' : String(description)); | ||
@@ -509,9 +542,20 @@ return defineProperties(symbol, { | ||
}; | ||
Object.defineProperties(Symbol, { | ||
create: d('', Symbol('create')), | ||
defineProperties(Symbol, { | ||
for: d(function (key) { | ||
if (globalSymbols[key]) return globalSymbols[key]; | ||
return (globalSymbols[key] = Symbol(String(key))); | ||
}), | ||
keyFor: d(function (s) { | ||
var key; | ||
validateSymbol(s); | ||
for (key in globalSymbols) if (globalSymbols[key] === s) return key; | ||
}), | ||
hasInstance: d('', Symbol('hasInstance')), | ||
isConcatSpreadable: d('', Symbol('isConcatSpreadable')), | ||
isRegExp: d('', Symbol('isRegExp')), | ||
iterator: d('', Symbol('iterator')), | ||
match: d('', Symbol('match')), | ||
replace: d('', Symbol('replace')), | ||
search: d('', Symbol('search')), | ||
species: d('', Symbol('species')), | ||
split: d('', Symbol('split')), | ||
toPrimitive: d('', Symbol('toPrimitive')), | ||
@@ -521,16 +565,31 @@ toStringTag: d('', Symbol('toStringTag')), | ||
}); | ||
defineProperties(HiddenSymbol.prototype, { | ||
constructor: d(Symbol), | ||
toString: d('', function () { return this.__name__; }) | ||
}); | ||
defineProperties(Symbol.prototype, { | ||
properToString: d(function () { | ||
return 'Symbol (' + this.__description__ + ')'; | ||
}), | ||
toString: d('', function () { return this.__name__; }) | ||
toString: d(function () { return 'Symbol (' + validateSymbol(this).__description__ + ')'; }), | ||
valueOf: d(function () { return validateSymbol(this); }) | ||
}); | ||
Object.defineProperty(Symbol.prototype, Symbol.toPrimitive, d('', | ||
function (hint) { | ||
throw new TypeError("Conversion of symbol objects is not allowed"); | ||
})); | ||
Object.defineProperty(Symbol.prototype, Symbol.toStringTag, d('c', 'Symbol')); | ||
defineProperty(Symbol.prototype, Symbol.toPrimitive, d('', | ||
function () { return validateSymbol(this); })); | ||
defineProperty(Symbol.prototype, Symbol.toStringTag, d('c', 'Symbol')); | ||
},{"d":4}]},{},[1])(1) | ||
defineProperty(HiddenSymbol.prototype, Symbol.toPrimitive, | ||
d('c', Symbol.prototype[Symbol.toPrimitive])); | ||
defineProperty(HiddenSymbol.prototype, Symbol.toStringTag, | ||
d('c', Symbol.prototype[Symbol.toStringTag])); | ||
},{"./validate-symbol":19,"d":5}],19:[function(require,module,exports){ | ||
'use strict'; | ||
var isSymbol = require('./is-symbol'); | ||
module.exports = function (value) { | ||
if (!isSymbol(value)) throw new TypeError(value + " is not a symbol"); | ||
return value; | ||
}; | ||
},{"./is-symbol":4}]},{},[1])(1) | ||
}); |
/* | ||
* The MIT License (MIT) | ||
* Copyright © 2014 Daniel K. (FredyC) | ||
* Copyright © 2015 Daniel K. (FredyC) | ||
* | ||
@@ -11,4 +11,4 @@ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* Version: 0.3.2 | ||
* Version: 0.4.0 | ||
*/ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.lill=e()}}(function(){return function e(t,n,r){function o(a,c){if(!n[a]){if(!t[a]){var s="function"==typeof require&&require;if(!c&&s)return s(a,!0);if(i)return i(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var l=n[a]={exports:{}};t[a][0].call(l.exports,function(e){var n=t[a][1][e];return o(n?n:e)},l,l.exports,e,t,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<r.length;a++)o(r[a]);return o}({1:[function(e,t){"use strict";var n,r,o,i,a,c,s,u,l,f,p,d,b,y,m,v,h,x,g,w,j,S;r=e("es6-symbol"),a=r("lill related data"),c=r("lill owner of item"),w=0,i=function(e){var t,n;if(!e||"object"!=(n=typeof e)&&"function"!==n)throw new TypeError("LiLL.attach needs an object or function");if(e[a])throw new TypeError("LiLL.attach cannot use already attached object");if(!Object.isExtensible(e))throw new TypeError("LiLL.attach needs extensible object");return e[a]=t={owner:r("lill parent owner"),next:r("lill next item"),prev:r("lill previous item"),head:null,tail:null,size:0,id:w},w+=1,Object.seal(t),e},f=function(e){return e[a]?(l(e),delete e[a],e):e},o=function(e,t){var n;return n=s(e),u(e,t,"add"),t[n.owner]===e?e:(t[n.next]=t[n.prev]=null,t[n.owner]=e,n.head?(n.tail[n.next]=t,t[n.prev]=n.tail,n.tail=t):n.head=n.tail=t,n.size+=1,e)},g=function(e,t){var n;return n=s(e),u(e,t,"has"),t[n.owner]===e},S=function(e,t){var n,r,o;return n=s(e),u(e,t,"remove"),t[n.owner]!==e?e:(n.head===t&&(n.head=n.head[n.next]),n.tail===t&&(n.tail=n.tail[n.prev]),(o=t[n.prev])&&(o[n.next]=t[n.next]),(r=t[n.next])&&(r[n.prev]=t[n.prev]),delete t[n.next],delete t[n.prev],delete t[n.owner],n.size-=1,e)},l=function(e){var t,n;for(t=s(e);n=t.head;)t.head=n[t.next],delete n[t.next],delete n[t.prev],delete n[t.owner];return t.head=t.tail=null,t.size=0,e},y=function(e){var t;return t=s(e),t.head},x=function(e){var t;return t=s(e),t.tail},m=function(e,t){var n;return n=s(e),null!=t?t[n.next]:void 0},v=function(e,t){var n;return n=s(e),null!=t?t[n.prev]:void 0},h=function(e){var t;return t=s(e),t.size},p=function(e,t,n){var r,o,i,a,c;if(r=s(e),"function"!=typeof t)throw new TypeError("LiLL.each method expects callback function");if(o=0,!(i=r.head))return o;for(a=void 0!==n?b:d;;){if(c=i[r.next],a(t,i,o,n),!(i=c))break;o+=1}return o},d=function(e,t,n){return e(t,n)},b=function(e,t,n,r){return e.call(r,t,n)},j=function(e){return null!=e[a]},s=function(e){var t;if(t=null!=e?e[a]:void 0)return t;throw new TypeError("use LiLL.attach() method on owner object")},u=function(e,t,n){var r;if(!t||"object"!=(r=typeof t)&&"function"!==r)throw new TypeError("LiLL."+n+" needs an object or function to be added");if(!Object.isExtensible(t))throw new TypeError("LiLL."+n+" method needs an extensible item");if(t[c]&&t[c]!==e)throw new TypeError("LiLL cannot "+n+" item that is managed by another list")},n={attach:i,detach:f,add:o,has:g,remove:S,clear:l,getHead:y,getTail:x,getNext:m,getPrevious:v,getSize:h,each:p,isAttached:j},t.exports=Object.freeze(n)},{"es6-symbol":2}],2:[function(e,t){"use strict";t.exports=e("./is-implemented")()?Symbol:e("./polyfill")},{"./is-implemented":3,"./polyfill":17}],3:[function(e,t){"use strict";t.exports=function(){var e;if("function"!=typeof Symbol)return!1;e=Symbol("test symbol");try{if("Symbol (test symbol)"!==String(e))return!1}catch(t){return!1}return"symbol"==typeof Symbol.iterator?!0:"object"!=typeof Symbol.isConcatSpreadable?!1:"object"!=typeof Symbol.isRegExp?!1:"object"!=typeof Symbol.iterator?!1:"object"!=typeof Symbol.toPrimitive?!1:"object"!=typeof Symbol.toStringTag?!1:"object"!=typeof Symbol.unscopables?!1:!0}},{}],4:[function(e,t){"use strict";var n,r=e("es5-ext/object/assign"),o=e("es5-ext/object/normalize-options"),i=e("es5-ext/object/is-callable"),a=e("es5-ext/string/#/contains");n=t.exports=function(e,t){var n,i,c,s,u;return arguments.length<2||"string"!=typeof e?(s=t,t=e,e=null):s=arguments[2],null==e?(n=c=!0,i=!1):(n=a.call(e,"c"),i=a.call(e,"e"),c=a.call(e,"w")),u={value:t,configurable:n,enumerable:i,writable:c},s?r(o(s),u):u},n.gs=function(e,t,n){var c,s,u,l;return"string"!=typeof e?(u=n,n=t,t=e,e=null):u=arguments[3],null==t?t=void 0:i(t)?null==n?n=void 0:i(n)||(u=n,n=void 0):(u=t,t=n=void 0),null==e?(c=!0,s=!1):(c=a.call(e,"c"),s=a.call(e,"e")),l={get:t,set:n,configurable:c,enumerable:s},u?r(o(u),l):l}},{"es5-ext/object/assign":5,"es5-ext/object/is-callable":8,"es5-ext/object/normalize-options":12,"es5-ext/string/#/contains":14}],5:[function(e,t){"use strict";t.exports=e("./is-implemented")()?Object.assign:e("./shim")},{"./is-implemented":6,"./shim":7}],6:[function(e,t){"use strict";t.exports=function(){var e,t=Object.assign;return"function"!=typeof t?!1:(e={foo:"raz"},t(e,{bar:"dwa"},{trzy:"trzy"}),e.foo+e.bar+e.trzy==="razdwatrzy")}},{}],7:[function(e,t){"use strict";var n=e("../keys"),r=e("../valid-value"),o=Math.max;t.exports=function(e,t){var i,a,c,s=o(arguments.length,2);for(e=Object(r(e)),c=function(n){try{e[n]=t[n]}catch(r){i||(i=r)}},a=1;s>a;++a)t=arguments[a],n(t).forEach(c);if(void 0!==i)throw i;return e}},{"../keys":9,"../valid-value":13}],8:[function(e,t){"use strict";t.exports=function(e){return"function"==typeof e}},{}],9:[function(e,t){"use strict";t.exports=e("./is-implemented")()?Object.keys:e("./shim")},{"./is-implemented":10,"./shim":11}],10:[function(e,t){"use strict";t.exports=function(){try{return Object.keys("primitive"),!0}catch(e){return!1}}},{}],11:[function(e,t){"use strict";var n=Object.keys;t.exports=function(e){return n(null==e?e:Object(e))}},{}],12:[function(e,t){"use strict";var n,r=e("./assign"),o=Array.prototype.forEach,i=Object.create,a=Object.getPrototypeOf;n=function(e,t){var o=a(e);return r(o?n(o,t):t,e)},t.exports=function(){var e=i(null);return o.call(arguments,function(t){null!=t&&n(Object(t),e)}),e}},{"./assign":5}],13:[function(e,t){"use strict";t.exports=function(e){if(null==e)throw new TypeError("Cannot use null or undefined");return e}},{}],14:[function(e,t){"use strict";t.exports=e("./is-implemented")()?String.prototype.contains:e("./shim")},{"./is-implemented":15,"./shim":16}],15:[function(e,t){"use strict";var n="razdwatrzy";t.exports=function(){return"function"!=typeof n.contains?!1:n.contains("dwa")===!0&&n.contains("foo")===!1}},{}],16:[function(e,t){"use strict";var n=String.prototype.indexOf;t.exports=function(e){return n.call(this,e,arguments[1])>-1}},{}],17:[function(e,t){"use strict";var n,r,o=e("d"),i=Object.create,a=Object.defineProperties;n=function(){var e=i(null);return function(t){for(var n=0;e[t+(n||"")];)++n;return t+=n||"",e[t]=!0,"@@"+t}}(),t.exports=r=function(e){var t;if(this instanceof r)throw new TypeError("TypeError: Symbol is not a constructor");return t=i(r.prototype),e=void 0===e?"":String(e),a(t,{__description__:o("",e),__name__:o("",n(e))})},Object.defineProperties(r,{create:o("",r("create")),hasInstance:o("",r("hasInstance")),isConcatSpreadable:o("",r("isConcatSpreadable")),isRegExp:o("",r("isRegExp")),iterator:o("",r("iterator")),toPrimitive:o("",r("toPrimitive")),toStringTag:o("",r("toStringTag")),unscopables:o("",r("unscopables"))}),a(r.prototype,{properToString:o(function(){return"Symbol ("+this.__description__+")"}),toString:o("",function(){return this.__name__})}),Object.defineProperty(r.prototype,r.toPrimitive,o("",function(){throw new TypeError("Conversion of symbol objects is not allowed")})),Object.defineProperty(r.prototype,r.toStringTag,o("c","Symbol"))},{d:4}]},{},[1])(1)}); | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.lill=t()}}(function(){return function t(e,n,r){function o(c,u){if(!n[c]){if(!e[c]){var a="function"==typeof require&&require;if(!u&&a)return a(c,!0);if(i)return i(c,!0);var s=new Error("Cannot find module '"+c+"'");throw s.code="MODULE_NOT_FOUND",s}var l=n[c]={exports:{}};e[c][0].call(l.exports,function(t){var n=e[c][1][t];return o(n?n:t)},l,l.exports,t,e,n,r)}return n[c].exports}for(var i="function"==typeof require&&require,c=0;c<r.length;c++)o(r[c]);return o}({1:[function(t,e,n){"use strict";var r,o,i,c,u,a,s,l,f,p,d,y,b,m,v,h,x,g,w,j,S,L,T;o=t("es6-symbol"),u=o("lill related data"),a=o("lill owner of item"),S=0,c=function(t){var e,n;if(!t||"object"!=(n=typeof t)&&"function"!==n)throw new TypeError("LiLL.attach needs an object or function");if(t[u])throw new TypeError("LiLL.attach cannot use already attached object");if(!Object.isExtensible(t))throw new TypeError("LiLL.attach needs extensible object");return t[u]=e={owner:o("lill parent owner"),next:o("lill next item"),prev:o("lill previous item"),head:null,tail:null,size:0,id:S},S+=1,Object.seal(e),t},p=function(t){return t[u]?(f(t),delete t[u],t):t},i=function(t,e){var n;return n=s(t),l(t,e,"add"),e[n.owner]===t?t:(e[n.next]=e[n.prev]=null,e[n.owner]=t,n.head?(n.tail[n.next]=e,e[n.prev]=n.tail,n.tail=e):n.head=n.tail=e,n.size+=1,t)},j=function(t,e){var n;return n=s(t),l(t,e,"has"),e[n.owner]===t},T=function(t,e){var n,r,o;return n=s(t),l(t,e,"remove"),e[n.owner]!==t?t:(n.head===e&&(n.head=n.head[n.next]),n.tail===e&&(n.tail=n.tail[n.prev]),(o=e[n.prev])&&(o[n.next]=e[n.next]),(r=e[n.next])&&(r[n.prev]=e[n.prev]),delete e[n.next],delete e[n.prev],delete e[n.owner],n.size-=1,t)},f=function(t){var e,n;for(e=s(t);n=e.head;)e.head=n[e.next],delete n[e.next],delete n[e.prev],delete n[e.owner];return e.head=e.tail=null,e.size=0,t},v=function(t){var e;return e=s(t),e.head},w=function(t){var e;return e=s(t),e.tail},h=function(t,e){var n;return n=s(t),null!=e?e[n.next]:void 0},x=function(t,e){var n;return n=s(t),null!=e?e[n.prev]:void 0},g=function(t){var e;return e=s(t),e.size},d=function(t,e,n){var r,o,i,c,u;if(r=s(t),"function"!=typeof e)throw new TypeError("LiLL.each method expects callback function");if(o=0,!(i=r.head))return o;for(c=void 0!==n?m:b;;){if(u=i[r.next],c(e,i,o,n),!(i=u))break;o+=1}return o},y=function(t,e,n){var r,o,i,c,u,a;if(r=s(t),"function"!=typeof e)throw new TypeError("LiLL.find method expects predicate function");if(!(c=r.head))return null;for(o=void 0!==n?m:b,i=0;;){if(u=c[r.next],a=o(e,c,i,n),a===!0)return c;if(!(c=u))break;i+=1}return null},b=function(t,e,n){return t(e,n)},m=function(t,e,n,r){return t.call(r,e,n)},L=function(t){return null!=t[u]},s=function(t){var e;if(e=null!=t?t[u]:void 0)return e;throw new TypeError("use LiLL.attach() method on owner object")},l=function(t,e,n){var r;if(!e||"object"!=(r=typeof e)&&"function"!==r)throw new TypeError("LiLL."+n+" needs an object or function to be added");if(!Object.isExtensible(e))throw new TypeError("LiLL."+n+" method needs an extensible item");if(e[a]&&e[a]!==t)throw new TypeError("LiLL cannot "+n+" item that is managed by another list")},r={attach:c,detach:p,add:i,has:j,remove:T,clear:f,getHead:v,getTail:w,getNext:h,getPrevious:x,getSize:g,each:d,find:y,isAttached:L},e.exports=Object.freeze(r)},{"es6-symbol":2}],2:[function(t,e,n){"use strict";e.exports=t("./is-implemented")()?Symbol:t("./polyfill")},{"./is-implemented":3,"./polyfill":18}],3:[function(t,e,n){"use strict";e.exports=function(){var t;if("function"!=typeof Symbol)return!1;t=Symbol("test symbol");try{String(t)}catch(e){return!1}return"symbol"==typeof Symbol.iterator?!0:"object"!=typeof Symbol.isConcatSpreadable?!1:"object"!=typeof Symbol.iterator?!1:"object"!=typeof Symbol.toPrimitive?!1:"object"!=typeof Symbol.toStringTag?!1:"object"!=typeof Symbol.unscopables?!1:!0}},{}],4:[function(t,e,n){"use strict";e.exports=function(t){return t&&("symbol"==typeof t||"Symbol"===t["@@toStringTag"])||!1}},{}],5:[function(t,e,n){"use strict";var r,o=t("es5-ext/object/assign"),i=t("es5-ext/object/normalize-options"),c=t("es5-ext/object/is-callable"),u=t("es5-ext/string/#/contains");r=e.exports=function(t,e){var n,r,c,a,s;return arguments.length<2||"string"!=typeof t?(a=e,e=t,t=null):a=arguments[2],null==t?(n=c=!0,r=!1):(n=u.call(t,"c"),r=u.call(t,"e"),c=u.call(t,"w")),s={value:e,configurable:n,enumerable:r,writable:c},a?o(i(a),s):s},r.gs=function(t,e,n){var r,a,s,l;return"string"!=typeof t?(s=n,n=e,e=t,t=null):s=arguments[3],null==e?e=void 0:c(e)?null==n?n=void 0:c(n)||(s=n,n=void 0):(s=e,e=n=void 0),null==t?(r=!0,a=!1):(r=u.call(t,"c"),a=u.call(t,"e")),l={get:e,set:n,configurable:r,enumerable:a},s?o(i(s),l):l}},{"es5-ext/object/assign":6,"es5-ext/object/is-callable":9,"es5-ext/object/normalize-options":13,"es5-ext/string/#/contains":15}],6:[function(t,e,n){"use strict";e.exports=t("./is-implemented")()?Object.assign:t("./shim")},{"./is-implemented":7,"./shim":8}],7:[function(t,e,n){"use strict";e.exports=function(){var t,e=Object.assign;return"function"!=typeof e?!1:(t={foo:"raz"},e(t,{bar:"dwa"},{trzy:"trzy"}),t.foo+t.bar+t.trzy==="razdwatrzy")}},{}],8:[function(t,e,n){"use strict";var r=t("../keys"),o=t("../valid-value"),i=Math.max;e.exports=function(t,e){var n,c,u,a=i(arguments.length,2);for(t=Object(o(t)),u=function(r){try{t[r]=e[r]}catch(o){n||(n=o)}},c=1;a>c;++c)e=arguments[c],r(e).forEach(u);if(void 0!==n)throw n;return t}},{"../keys":10,"../valid-value":14}],9:[function(t,e,n){"use strict";e.exports=function(t){return"function"==typeof t}},{}],10:[function(t,e,n){"use strict";e.exports=t("./is-implemented")()?Object.keys:t("./shim")},{"./is-implemented":11,"./shim":12}],11:[function(t,e,n){"use strict";e.exports=function(){try{return Object.keys("primitive"),!0}catch(t){return!1}}},{}],12:[function(t,e,n){"use strict";var r=Object.keys;e.exports=function(t){return r(null==t?t:Object(t))}},{}],13:[function(t,e,n){"use strict";var r=Array.prototype.forEach,o=Object.create,i=function(t,e){var n;for(n in t)e[n]=t[n]};e.exports=function(t){var e=o(null);return r.call(arguments,function(t){null!=t&&i(Object(t),e)}),e}},{}],14:[function(t,e,n){"use strict";e.exports=function(t){if(null==t)throw new TypeError("Cannot use null or undefined");return t}},{}],15:[function(t,e,n){"use strict";e.exports=t("./is-implemented")()?String.prototype.contains:t("./shim")},{"./is-implemented":16,"./shim":17}],16:[function(t,e,n){"use strict";var r="razdwatrzy";e.exports=function(){return"function"!=typeof r.contains?!1:r.contains("dwa")===!0&&r.contains("foo")===!1}},{}],17:[function(t,e,n){"use strict";var r=String.prototype.indexOf;e.exports=function(t){return r.call(this,t,arguments[1])>-1}},{}],18:[function(t,e,n){"use strict";var r,o,i=t("d"),c=t("./validate-symbol"),u=Object.create,a=Object.defineProperties,s=Object.defineProperty,l=Object.prototype,f=u(null),p=function(){var t=u(null);return function(e){for(var n,r=0;t[e+(r||"")];)++r;return e+=r||"",t[e]=!0,n="@@"+e,s(l,n,i.gs(null,function(t){s(this,n,i(t))})),n}}();o=function d(t){if(this instanceof o)throw new TypeError("TypeError: Symbol is not a constructor");return d(t)},e.exports=r=function y(t){var e;if(this instanceof y)throw new TypeError("TypeError: Symbol is not a constructor");return e=u(o.prototype),t=void 0===t?"":String(t),a(e,{__description__:i("",t),__name__:i("",p(t))})},a(r,{"for":i(function(t){return f[t]?f[t]:f[t]=r(String(t))}),keyFor:i(function(t){var e;c(t);for(e in f)if(f[e]===t)return e}),hasInstance:i("",r("hasInstance")),isConcatSpreadable:i("",r("isConcatSpreadable")),iterator:i("",r("iterator")),match:i("",r("match")),replace:i("",r("replace")),search:i("",r("search")),species:i("",r("species")),split:i("",r("split")),toPrimitive:i("",r("toPrimitive")),toStringTag:i("",r("toStringTag")),unscopables:i("",r("unscopables"))}),a(o.prototype,{constructor:i(r),toString:i("",function(){return this.__name__})}),a(r.prototype,{toString:i(function(){return"Symbol ("+c(this).__description__+")"}),valueOf:i(function(){return c(this)})}),s(r.prototype,r.toPrimitive,i("",function(){return c(this)})),s(r.prototype,r.toStringTag,i("c","Symbol")),s(o.prototype,r.toPrimitive,i("c",r.prototype[r.toPrimitive])),s(o.prototype,r.toStringTag,i("c",r.prototype[r.toStringTag]))},{"./validate-symbol":19,d:5}],19:[function(t,e,n){"use strict";var r=t("./is-symbol");e.exports=function(t){if(!r(t))throw new TypeError(t+" is not a symbol");return t}},{"./is-symbol":4}]},{},[1])(1)}); |
/* | ||
* The MIT License (MIT) | ||
* Copyright © 2014 Daniel K. (FredyC) | ||
* Copyright © 2015 Daniel K. (FredyC) | ||
* | ||
@@ -11,6 +11,6 @@ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* Version: 0.3.2 | ||
* Version: 0.4.0 | ||
*/ | ||
'use strict'; | ||
var LiLL, Symbol, add, attach, bData, bOwner, checkAttached, checkItem, clear, detach, each, each$noContext, each$withContext, getHead, getNext, getPrevious, getSize, getTail, has, idSequence, isAttached, remove; | ||
var LiLL, Symbol, add, attach, bData, bOwner, checkAttached, checkItem, clear, detach, each, find, func$noContext, func$withContext, getHead, getNext, getPrevious, getSize, getTail, has, idSequence, isAttached, remove; | ||
@@ -26,4 +26,4 @@ Symbol = require('es6-symbol'); | ||
attach = function(owner) { | ||
var data, _ref; | ||
if (!(owner && ((_ref = typeof owner) === 'object' || _ref === 'function'))) { | ||
var data, ref; | ||
if (!(owner && ((ref = typeof owner) === 'object' || ref === 'function'))) { | ||
throw new TypeError('LiLL.attach needs an object or function'); | ||
@@ -167,3 +167,3 @@ } | ||
} | ||
iterator = ctx !== void 0 ? each$withContext : each$noContext; | ||
iterator = ctx !== void 0 ? func$withContext : func$noContext; | ||
while (true) { | ||
@@ -180,7 +180,32 @@ next = item[data.next]; | ||
each$noContext = function(fn, item, i) { | ||
find = function(owner, predicate, ctx) { | ||
var data, func, i, item, next, result; | ||
data = checkAttached(owner); | ||
if (typeof predicate !== 'function') { | ||
throw new TypeError('LiLL.find method expects predicate function'); | ||
} | ||
if (!(item = data.head)) { | ||
return null; | ||
} | ||
func = ctx !== void 0 ? func$withContext : func$noContext; | ||
i = 0; | ||
while (true) { | ||
next = item[data.next]; | ||
result = func(predicate, item, i, ctx); | ||
if (result === true) { | ||
return item; | ||
} | ||
if (!(item = next)) { | ||
break; | ||
} | ||
i += 1; | ||
} | ||
return null; | ||
}; | ||
func$noContext = function(fn, item, i) { | ||
return fn(item, i); | ||
}; | ||
each$withContext = function(fn, item, i, ctx) { | ||
func$withContext = function(fn, item, i, ctx) { | ||
return fn.call(ctx, item, i); | ||
@@ -202,4 +227,4 @@ }; | ||
checkItem = function(owner, item, method) { | ||
var _ref; | ||
if (!(item && ((_ref = typeof item) === 'object' || _ref === 'function'))) { | ||
var ref; | ||
if (!(item && ((ref = typeof item) === 'object' || ref === 'function'))) { | ||
throw new TypeError("LiLL." + method + " needs an object or function to be added"); | ||
@@ -228,2 +253,3 @@ } | ||
each: each, | ||
find: find, | ||
isAttached: isAttached | ||
@@ -230,0 +256,0 @@ }; |
/* | ||
* The MIT License (MIT) | ||
* Copyright © 2014 Daniel K. (FredyC) | ||
* Copyright © 2015 Daniel K. (FredyC) | ||
* | ||
@@ -11,4 +11,4 @@ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* Version: 0.3.2 | ||
* Version: 0.4.0 | ||
*/ | ||
"use strict";var e,t,a,n,r,c,i,o,h,l,d,u,f,s,b,v,w,L,x,m,p,g;t=require("es6-symbol"),r=t("lill related data"),c=t("lill owner of item"),m=0,n=function(e){var a,n;if(!e||"object"!=(n=typeof e)&&"function"!==n)throw new TypeError("LiLL.attach needs an object or function");if(e[r])throw new TypeError("LiLL.attach cannot use already attached object");if(!Object.isExtensible(e))throw new TypeError("LiLL.attach needs extensible object");return e[r]=a={owner:t("lill parent owner"),next:t("lill next item"),prev:t("lill previous item"),head:null,tail:null,size:0,id:m},m+=1,Object.seal(a),e},l=function(e){return e[r]?(h(e),delete e[r],e):e},a=function(e,t){var a;return a=i(e),o(e,t,"add"),t[a.owner]===e?e:(t[a.next]=t[a.prev]=null,t[a.owner]=e,a.head?(a.tail[a.next]=t,t[a.prev]=a.tail,a.tail=t):a.head=a.tail=t,a.size+=1,e)},x=function(e,t){var a;return a=i(e),o(e,t,"has"),t[a.owner]===e},g=function(e,t){var a,n,r;return a=i(e),o(e,t,"remove"),t[a.owner]!==e?e:(a.head===t&&(a.head=a.head[a.next]),a.tail===t&&(a.tail=a.tail[a.prev]),(r=t[a.prev])&&(r[a.next]=t[a.next]),(n=t[a.next])&&(n[a.prev]=t[a.prev]),delete t[a.next],delete t[a.prev],delete t[a.owner],a.size-=1,e)},h=function(e){var t,a;for(t=i(e);a=t.head;)t.head=a[t.next],delete a[t.next],delete a[t.prev],delete a[t.owner];return t.head=t.tail=null,t.size=0,e},s=function(e){var t;return t=i(e),t.head},L=function(e){var t;return t=i(e),t.tail},b=function(e,t){var a;return a=i(e),null!=t?t[a.next]:void 0},v=function(e,t){var a;return a=i(e),null!=t?t[a.prev]:void 0},w=function(e){var t;return t=i(e),t.size},d=function(e,t,a){var n,r,c,o,h;if(n=i(e),"function"!=typeof t)throw new TypeError("LiLL.each method expects callback function");if(r=0,!(c=n.head))return r;for(o=void 0!==a?f:u;;){if(h=c[n.next],o(t,c,r,a),!(c=h))break;r+=1}return r},u=function(e,t,a){return e(t,a)},f=function(e,t,a,n){return e.call(n,t,a)},p=function(e){return null!=e[r]},i=function(e){var t;if(t=null!=e?e[r]:void 0)return t;throw new TypeError("use LiLL.attach() method on owner object")},o=function(e,t,a){var n;if(!t||"object"!=(n=typeof t)&&"function"!==n)throw new TypeError("LiLL."+a+" needs an object or function to be added");if(!Object.isExtensible(t))throw new TypeError("LiLL."+a+" method needs an extensible item");if(t[c]&&t[c]!==e)throw new TypeError("LiLL cannot "+a+" item that is managed by another list")},e={attach:n,detach:l,add:a,has:x,remove:g,clear:h,getHead:s,getTail:L,getNext:b,getPrevious:v,getSize:w,each:d,isAttached:p},module.exports=Object.freeze(e); | ||
"use strict";var e,t,n,r,i,o,a,l,u,c,d,f,h,v,s,p,w,L,x,b,y,m,j;t=require("es6-symbol"),i=t("lill related data"),o=t("lill owner of item"),y=0,r=function(e){var n,r;if(!e||"object"!=(r=typeof e)&&"function"!==r)throw new TypeError("LiLL.attach needs an object or function");if(e[i])throw new TypeError("LiLL.attach cannot use already attached object");if(!Object.isExtensible(e))throw new TypeError("LiLL.attach needs extensible object");return e[i]=n={owner:t("lill parent owner"),next:t("lill next item"),prev:t("lill previous item"),head:null,tail:null,size:0,id:y},y+=1,Object.seal(n),e},c=function(e){return e[i]?(u(e),delete e[i],e):e},n=function(e,t){var n;return n=a(e),l(e,t,"add"),t[n.owner]===e?e:(t[n.next]=t[n.prev]=null,t[n.owner]=e,n.head?(n.tail[n.next]=t,t[n.prev]=n.tail,n.tail=t):n.head=n.tail=t,n.size+=1,e)},b=function(e,t){var n;return n=a(e),l(e,t,"has"),t[n.owner]===e},j=function(e,t){var n,r,i;return n=a(e),l(e,t,"remove"),t[n.owner]!==e?e:(n.head===t&&(n.head=n.head[n.next]),n.tail===t&&(n.tail=n.tail[n.prev]),(i=t[n.prev])&&(i[n.next]=t[n.next]),(r=t[n.next])&&(r[n.prev]=t[n.prev]),delete t[n.next],delete t[n.prev],delete t[n.owner],n.size-=1,e)},u=function(e){var t,n;for(t=a(e);n=t.head;)t.head=n[t.next],delete n[t.next],delete n[t.prev],delete n[t.owner];return t.head=t.tail=null,t.size=0,e},s=function(e){var t;return t=a(e),t.head},x=function(e){var t;return t=a(e),t.tail},p=function(e,t){var n;return n=a(e),null!=t?t[n.next]:void 0},w=function(e,t){var n;return n=a(e),null!=t?t[n.prev]:void 0},L=function(e){var t;return t=a(e),t.size},d=function(e,t,n){var r,i,o,l,u;if(r=a(e),"function"!=typeof t)throw new TypeError("LiLL.each method expects callback function");if(i=0,!(o=r.head))return i;for(l=void 0!==n?v:h;;){if(u=o[r.next],l(t,o,i,n),!(o=u))break;i+=1}return i},f=function(e,t,n){var r,i,o,l,u,c;if(r=a(e),"function"!=typeof t)throw new TypeError("LiLL.find method expects predicate function");if(!(l=r.head))return null;for(i=void 0!==n?v:h,o=0;;){if(u=l[r.next],c=i(t,l,o,n),c===!0)return l;if(!(l=u))break;o+=1}return null},h=function(e,t,n){return e(t,n)},v=function(e,t,n,r){return e.call(r,t,n)},m=function(e){return null!=e[i]},a=function(e){var t;if(t=null!=e?e[i]:void 0)return t;throw new TypeError("use LiLL.attach() method on owner object")},l=function(e,t,n){var r;if(!t||"object"!=(r=typeof t)&&"function"!==r)throw new TypeError("LiLL."+n+" needs an object or function to be added");if(!Object.isExtensible(t))throw new TypeError("LiLL."+n+" method needs an extensible item");if(t[o]&&t[o]!==e)throw new TypeError("LiLL cannot "+n+" item that is managed by another list")},e={attach:r,detach:c,add:n,has:b,remove:j,clear:u,getHead:s,getTail:x,getNext:p,getPrevious:w,getSize:L,each:d,find:f,isAttached:m},module.exports=Object.freeze(e); |
{ | ||
"name": "lill", | ||
"description": "Lightweight linked list implementation with small memory footprint.", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"license": "MIT", | ||
@@ -29,13 +29,13 @@ "keywords": [ | ||
"devDependencies": { | ||
"coffee-script": "^1.7.1", | ||
"chai": "^1.9.1", | ||
"mocha": "^1.21.3", | ||
"sinon-chai": "^2.5.0", | ||
"browserify": "^10.2.1", | ||
"chai": "^2.3.0", | ||
"coffee-script": "^1.9.2", | ||
"mocha": "^2.2.5", | ||
"sinon": "^1.10.3", | ||
"uglify-js": "^2.4.15", | ||
"browserify": "^5.9.1" | ||
"sinon-chai": "^2.7.0", | ||
"uglify-js": "^2.4.15" | ||
}, | ||
"dependencies": { | ||
"es6-symbol": "^0.1.0" | ||
"es6-symbol": "^2.0.1" | ||
} | ||
} |
138
README.md
# LiLL - Light Linked List | ||
*Lightweight linked list implementation with small memory footprint.* | ||
*Lightweight linked list implementation with a small memory footprint.* | ||
@@ -9,25 +9,36 @@ [![Build Status](https://travis-ci.org/BlackDice/lill.svg)](https://travis-ci.org/BlackDice/lill)[![Dependencies status](https://david-dm.org/BlackDice/lill/status.svg)](https://david-dm.org/BlackDice/lill#info=dependencies)[![devDependency Status](https://david-dm.org/BlackDice/lill/dev-status.svg)](https://david-dm.org/BlackDice/lill#info=devDependencies) | ||
There are few implementation of the [linked-list structure](http://en.wikipedia.org/wiki/Linked_list), but most of them creates bunch of extra objects to store the information. We didn't like that so *LiLL* has been made. | ||
There are few implementation of the [linked-list structure](http://en.wikipedia.org/wiki/Linked_list) in the JavaScript ecosystem, but most of them create a bunch of extra objects to store metadata about the list. We didn't liked that, so we created *LiLL*. | ||
Linked list structure shines in situations when you need to iterate over some list very frequently while modifications of the list are not that frequent. Items of such list are simple linked together by referencing each other. This is much faster to iterate over than standard loops. | ||
The linked list data structure really shines in situations when you frequently need to iterate over a list of items, but only modify the list's structure infrequently. Linked lists are ordered simply by having each object in the list reference its previous and next siblings. Linked lists are much faster to iterate over than standard loops. | ||
## Using Symbol | ||
## Built With Symbol | ||
LiLL is using new ES6 feature called [Symbols](http://tc39wiki.calculist.org/es6/symbols/). That way everything can be stored on original objects that are supposed to be linked together. Thanks to the Symbol there are no collisions in property names and it doesn't interfere with your objects in any way. You can see this library as **proof-of-concept** of how can new Symbol be used. | ||
LiLL is using new ES6 feature called [Symbol](http://tc39wiki.calculist.org/es6/symbols/). This primitive makes it possible to store the linked list's metadata on original objects beinglinked together. There are no collisions in property names and it doesn't interfere with your objects in any way. You can see this library as **proof-of-concept** of how can new *Symbol* be used. | ||
### Warning about Symbol | ||
### A Warning About Symbol | ||
Please note, that Symbol is not officially supported by most of the environments so we had to use shim. Currently the [es6-symbol](https://www.npmjs.org/package/es6-symbol) implementation was chosen. If you know about better one, feel free to send in pull request. This is also only runtime dependency. Hopefully it will not be needed one day ;) | ||
Please note, that *Symbol* is not officially supported by most of the environments yet. As such LiLL shims this functionality with [es6-symbol](https://www.npmjs.org/package/es6-symbol). If you know about better one, feel free to send in pull request. This is also **only runtime dependency**. Hopefully it will not be needed one day ;) | ||
There is one limitation coming from using shim thou. Symbols are still added as standard properties using string identifier. Therefore calling for example `Object.getOwnPropertyNames` will return properties made by Symbol. That's clearly against specification, but we do believe, there is no clean way how to overcome this. We recommend to use LiLL just for objects that are not inspected on their properties. | ||
There is one notable limitation associated with this shim; Symbols are still assigned using the *String* primative. Therefore calling for example `Object.getOwnPropertyNames()` will return properties made by *Symbol*. This is a violation of the specification, but unfortunately there isn't a clean way to address this without native Symbol support. We recommend that you only use LiLL in situations where you won't be itterating over all of an object's properties. | ||
## Installation | ||
For the NodeJS environment simply run: | ||
npm install lill | ||
### Node.js | ||
To use LiLL in a Node environment simply run: | ||
```bash | ||
npm install lill | ||
``` | ||
and require *lill* in your application. | ||
### Browser | ||
If you are using Bower then run: | ||
bower install lill | ||
```bash | ||
bower install lill | ||
``` | ||
@@ -45,15 +56,19 @@ The `lib` folder contains various files: | ||
var Lill = require 'lill' | ||
var owner = {} | ||
Lill.attach(owner) === owner | ||
```js | ||
var Lill = require('lill'); | ||
var owner = {}; | ||
Lill.attach(owner) === owner; | ||
``` | ||
LiLL is designed to not create any state objects. Small disadvantage of such solution is that you have to pass *owner* object to every operation method. | ||
LiLL creates only single state object that is stored on the *owner* using Symbol. Basically it means that LiLL's public API is completely stateless. One small disadvantage this approach is that you must pass an *owner* object to every LiLL method call. | ||
### Adding to the list | ||
To keep the memory footprint low, information about neighbors are stored on added item using Symbols. That means you can add only items capable of this. No primitive values allows that. You can use objects and functions. | ||
To keep the memory footprint low, information about neighbors are stored on actual items using Symbols. That means you can add only items capable of this. No primitive values allows that. Similarly to *owner*, you can use *objects* or *functions* and item has to pass the check for `Object.isExtensible()`. | ||
var item = foo: 'bar' | ||
Lill.add owner, item | ||
```js | ||
var item = { foo: 'bar' }; | ||
Lill.add(owner, item); | ||
``` | ||
### Removing from the list | ||
@@ -63,3 +78,5 @@ | ||
Lill.remove owner, item | ||
```js | ||
Lill.remove(owner, item); | ||
``` | ||
@@ -70,53 +87,90 @@ ### Iterating the list | ||
iterate = (item, i) -> | ||
# do your work with item | ||
```js | ||
var iterate = function (item, i) { | ||
// do your work with item | ||
}; | ||
Lill.each owner, iterate, optionalContext | ||
Lill.each(owner, iterate, optionalContext); | ||
``` | ||
There is also internal counter of the items currently on the list. This can be used for example to randomly pick item from the list. | ||
Be warned that you should **not modify the list** during iterator invocation as it may cause unexpected behavior. This comes from nature of linked list structure as any changes in the chain of items could break iteration. | ||
Lill.getSize owner | ||
### Finding item in the list ### | ||
If you are looking for a particular item, using each means that it will iterate over every item. Using `find` quits the loop once the predicate function returns `true`. If no predicate is fulfilled, the `null` is returned. | ||
```js | ||
var predicate = function (item, i) { | ||
if (item.name == "correct") { | ||
return true; | ||
} | ||
}; | ||
item = Lill.find(owner, predicate, optionalContext); | ||
item.name == "correct" // true | ||
``` | ||
### Number of items in list | ||
There is internal counter of the items currently on the list. This can be used for example to randomly pick item from the list. | ||
```js | ||
Lill.getSize(owner); | ||
``` | ||
### Accessing the items | ||
Every items on the list keeps information about it's neighbors. You can access these informations like this. | ||
Every item on the list keeps information about it's neighbors. You can access such informations like this. | ||
Lill.getNext owner, item | ||
Lill.getPrevious owner, item | ||
```js | ||
Lill.getNext(owner, item); | ||
Lill.getPrevious(owner, item); | ||
``` | ||
You might want to know where the list begins too. This works very similar. | ||
Lill.getHead owner | ||
Lill.getTail owner | ||
```js | ||
Lill.getHead(owner); | ||
Lill.getTail(owner); | ||
``` | ||
Now you could iterate the list like this. | ||
item = Lill.getHead owner | ||
while item | ||
# do your work with the item | ||
item = Lill.getNext owner, item | ||
```js | ||
var item = Lill.getHead(owner); | ||
while (item) { | ||
// do your work with the item | ||
item = Lill.getNext(owner, item); | ||
} | ||
``` | ||
### Clearing the list | ||
To conveniently clear the list, just call the following. | ||
To conveniently remove all items from the list, just call the following. | ||
Lill.clear owner | ||
```js | ||
Lill.clear(owner); | ||
``` | ||
### Detach the list | ||
If you want remove all items from the list and pretty much dispose everything that LiLL was using, do it like this. | ||
If you want remove all items from the list and dispose of everything that LiLL was using, simply call `detach`. | ||
Lill.detach owner | ||
```js | ||
Lill.detach(owner); | ||
``` | ||
Detached object can be later attached again if you like. If you use any of the operation methods on detached object, error will be thrown. | ||
A detached object can be reattached later if necessary. If you use any of LiLL's operation methods on a detached object an error will be thrown. | ||
### Check for attached object | ||
If you want to check if some object is used as owner by Lill, simply call this. | ||
If you want to check if some object is used as owner by LiLL, simply call this. | ||
Lill.isAttached owner | ||
```js | ||
Lill.isAttached(owner); | ||
``` | ||
## Known limitation | ||
Due to simplicity of the solution, single object can be "owner" only once. Item can be present in multiple lists without influencing each other. | ||
Due to simplicity of the solution, single object can be "owner" only once. However item can be present **in multiple lists** without influencing each other. | ||
@@ -123,0 +177,0 @@ ## Tests |
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
45187
750
176
+ Addedes6-symbol@2.0.1(transitive)
- Removedes6-symbol@0.1.1(transitive)
Updatedes6-symbol@^2.0.1