code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function collapseTopology(topology, numPieces) { var geometries = topology.objects.triangles.geometries, bisect$$1 = bisector(function (d) { return d.area; }).left; while (geometries.length > numPieces) { mergeSmallestFeature(); } if (numPieces > geometries.length) { throw new RangeError( "C...
Compute the curve derivative (hodograph) at t.
collapseTopology
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function mergeSmallestFeature() { var smallest = geometries[0], neighborIndex = neighbors(geometries)[0][0], neighbor = geometries[neighborIndex], merged = mergeArcs(topology, [smallest, neighbor]); // MultiPolygon -> Polygon merged.area = smallest.area + neighbor.area; merged.type = ...
Compute the curve derivative (hodograph) at t.
mergeSmallestFeature
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
triangulate = function(ring, numPieces) { return collapseTopology(createTopology(cut(ring), ring), numPieces); }
Compute the curve derivative (hodograph) at t.
triangulate
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function cut(ring) { var cuts = earcut_1( ring.reduce(function (arr, point) { return arr.concat( [point[0]], [point[1]]); }, []) ), triangles = []; for (var i = 0, l = cuts.length; i < l; i += 3) { // Save each triangle as segments [a, b], [b, c], [c, a] triangles.push([ [cuts[i], cuts[...
Compute the curve derivative (hodograph) at t.
cut
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
pieceOrder = function(start, end) { if (start.length > 8) { return start.map(function (d, i) { return i; }); } var distances = start.map(function (p1) { return end.map(function (p2) { return squaredDistance(p1, p2); }); }); return bestOrder(start, end, distances); }
Compute the curve derivative (hodograph) at t.
pieceOrder
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function bestOrder(start, end, distances) { var min = Infinity, best = start.map(function (d, i) { return i; }); function permute(arr, order, sum) { if ( order === void 0 ) order = []; if ( sum === void 0 ) sum = 0; for (var i = 0; i < arr.length; i++) { var cur = arr.splice(i, 1), d...
Compute the curve derivative (hodograph) at t.
bestOrder
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function permute(arr, order, sum) { if ( order === void 0 ) order = []; if ( sum === void 0 ) sum = 0; for (var i = 0; i < arr.length; i++) { var cur = arr.splice(i, 1), dist = distances[cur[0]][order.length]; if (sum + dist < min) { if (arr.length) { permute(arr.slice...
Compute the curve derivative (hodograph) at t.
permute
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function squaredDistance(p1, p2) { var d = distance(polygonCentroid$$1(p1), polygonCentroid$$1(p2)); return d * d; }
Compute the curve derivative (hodograph) at t.
squaredDistance
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function separate( fromShape, toShapes, ref ) { if ( ref === void 0 ) ref = {}; var maxSegmentLength = ref.maxSegmentLength; if ( maxSegmentLength === void 0 ) maxSegmentLength = 10; var string = ref.string; if ( string === void 0 ) string = true; var single = ref.single; if ( single === void 0 ) single =...
Compute the curve derivative (hodograph) at t.
separate
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function combine$1( fromShapes, toShape, ref ) { if ( ref === void 0 ) ref = {}; var maxSegmentLength = ref.maxSegmentLength; if ( maxSegmentLength === void 0 ) maxSegmentLength = 10; var string = ref.string; if ( string === void 0 ) string = true; var single = ref.single; if ( single === void 0 ) single ...
Compute the curve derivative (hodograph) at t.
combine$1
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function interpolateAll( fromShapes, toShapes, ref ) { if ( ref === void 0 ) ref = {}; var maxSegmentLength = ref.maxSegmentLength; if ( maxSegmentLength === void 0 ) maxSegmentLength = 10; var string = ref.string; if ( string === void 0 ) string = true; var single = ref.single; if ( single === void 0 ) s...
Compute the curve derivative (hodograph) at t.
interpolateAll
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function interpolateSets( fromRings, toRings, ref ) { if ( ref === void 0 ) ref = {}; var string = ref.string; var single = ref.single; var t0 = ref.t0; var t1 = ref.t1; var match = ref.match; var order = match ? pieceOrder(fromRings, toRings) : fromRings.map(function (d, i) { return i;...
Compute the curve derivative (hodograph) at t.
interpolateSets
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function fromCircle(x, y, radius, toShape, options) { return fromShape( circlePoints(x, y, radius), toShape, circlePath(x, y, radius), 2 * Math.PI * radius, options ); }
Compute the curve derivative (hodograph) at t.
fromCircle
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function toCircle(fromShape, x, y, radius, options) { var interpolator = fromCircle(x, y, radius, fromShape, options); return function (t) { return interpolator(1 - t); }; }
Compute the curve derivative (hodograph) at t.
toCircle
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function fromRect(x, y, width, height, toShape, options) { return fromShape( rectPoints(x, y, width, height), toShape, rectPath(x, y, width, height), 2 * width + 2 * height, options ); }
Compute the curve derivative (hodograph) at t.
fromRect
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function toRect(fromShape, x, y, width, height, options) { var interpolator = fromRect(x, y, width, height, fromShape, options); return function (t) { return interpolator(1 - t); }; }
Compute the curve derivative (hodograph) at t.
toRect
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function fromShape( fromFn, toShape, original, perimeter, ref ) { if ( ref === void 0 ) ref = {}; var maxSegmentLength = ref.maxSegmentLength; if ( maxSegmentLength === void 0 ) maxSegmentLength = 10; var string = ref.string; if ( string === void 0 ) string = true; var toRing = normalizeRing(toShape,...
Compute the curve derivative (hodograph) at t.
fromShape
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function circlePoints(x, y, radius) { return function(ring) { var centroid = polygonCentroid$$1(ring), perimeter = polygonLength(ring.concat( [ring[0]])), startingAngle = Math.atan2( ring[0][1] - centroid[1], ring[0][0] - centroid[0] ), along = 0; return ring.map(funct...
Compute the curve derivative (hodograph) at t.
circlePoints
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function rectPoints(x, y, width, height) { return function(ring) { var centroid = polygonCentroid$$1(ring), perimeter = polygonLength(ring.concat( [ring[0]])), startingAngle = Math.atan2( ring[0][1] - centroid[1], ring[0][0] - centroid[0] ), along = 0; if (startingAngl...
Compute the curve derivative (hodograph) at t.
rectPoints
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function rectPoint(progress) { if (progress <= 1 / 8) { return [1, 0.5 + progress * 4]; } if (progress <= 3 / 8) { return [1.5 - 4 * progress, 1]; } if (progress <= 5 / 8) { return [0, 2.5 - 4 * progress]; } if (progress <= 7 / 8) { return [4 * progress - 2.5, 0]; } return [1, 4 * prog...
Compute the curve derivative (hodograph) at t.
rectPoint
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function circlePath(x, y, radius) { var l = x - radius + "," + y, r = x + radius + "," + y, pre = "A" + radius + "," + radius + ",0,1,1,"; return "M" + l + pre + r + pre + l + "Z"; }
Compute the curve derivative (hodograph) at t.
circlePath
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function rectPath(x, y, width, height) { var r = x + width, b = y + height; return ( "M" + x + "," + y + "L" + r + "," + y + "L" + r + "," + b + "L" + x + "," + b + "Z" ); }
Compute the curve derivative (hodograph) at t.
rectPath
javascript
veltman/flubber
build/flubber.js
https://github.com/veltman/flubber/blob/master/build/flubber.js
MIT
function bounceAnimation(direction) { slider.className = 'bounce-from-' + direction; setTimeout(function() { slider.className = ''; }, 400); }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
bounceAnimation
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function updateOffset() { var offset = -currentIndex * 100 + '%'; if (options.animation === 'fadeIn') { slider.style.opacity = 0; setTimeout(function() { supports.transforms ? slider.style.transform = slider.style.webkitTransform = 'translate3d...
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
updateOffset
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function testTransformsSupport() { var div = create('div'); return typeof div.style.perspective !== 'undefined' || typeof div.style.webkitPerspective !== 'undefined'; }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
testTransformsSupport
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function testSvgSupport() { var div = create('div'); div.innerHTML = '<svg/>'; return (div.firstChild && div.firstChild.namespaceURI) === 'http://www.w3.org/2000/svg'; }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
testSvgSupport
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function testPassiveEventsSupport() { var passiveEvents = false; try { var opts = Object.defineProperty({}, 'passive', { get: function() { passiveEvents = true; } }); window.addEventListener('test', null, opts); ...
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
testPassiveEventsSupport
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function preloadNext(index) { if (index - currentIndex >= options.preload) { return; } loadImage(index + 1, function() { preloadNext(index + 1); }); }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
preloadNext
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function preloadPrev(index) { if (currentIndex - index >= options.preload) { return; } loadImage(index - 1, function() { preloadPrev(index - 1); }); }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
preloadPrev
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function bind(element, event, callback, options) { if (element.addEventListener) { element.addEventListener(event, callback, options); } else { // IE8 fallback element.attachEvent('on' + event, function(event) { // `event` and `event.target` are not pr...
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
bind
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function unbind(element, event, callback, options) { if (element.removeEventListener) { element.removeEventListener(event, callback, options); } else { // IE8 fallback element.detachEvent('on' + event, callback); } }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
unbind
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function getByID(id) { return document.getElementById(id); }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
getByID
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function create(element) { return document.createElement(element); }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
create
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function destroyPlugin() { unbindEvents(); clearCachedData(); unbind(document, 'keydown', keyDownHandler); document.getElementsByTagName('body')[0].removeChild(document.getElementById('baguetteBox-overlay')); data = {}; currentGallery = []; currentIndex = 0; }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
destroyPlugin
javascript
feimosi/baguetteBox.js
dist/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/dist/baguetteBox.js
MIT
function bounceAnimation(direction) { slider.className = 'bounce-from-' + direction; setTimeout(function() { slider.className = ''; }, 400); }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
bounceAnimation
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function updateOffset() { var isRtl = document.querySelectorAll('html')[0].getAttribute('dir') === 'rtl'; var percentage = isRtl ? -100 : 100; var offset = -currentIndex * percentage + '%'; if (options.animation === 'fadeIn') { slider.style.opacity = 0; setTimeou...
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
updateOffset
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function testTransformsSupport() { var div = create('div'); return typeof div.style.perspective !== 'undefined' || typeof div.style.webkitPerspective !== 'undefined'; }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
testTransformsSupport
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function testSvgSupport() { var div = create('div'); div.innerHTML = '<svg/>'; return (div.firstChild && div.firstChild.namespaceURI) === 'http://www.w3.org/2000/svg'; }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
testSvgSupport
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function testPassiveEventsSupport() { var passiveEvents = false; try { var opts = Object.defineProperty({}, 'passive', { get: function() { passiveEvents = true; } }); window.addEventListener('test', null, opts); ...
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
testPassiveEventsSupport
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function preloadNext(index) { if (index - currentIndex >= options.preload) { return; } loadImage(index + 1, function() { preloadNext(index + 1); }); }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
preloadNext
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function preloadPrev(index) { if (currentIndex - index >= options.preload) { return; } loadImage(index - 1, function() { preloadPrev(index - 1); }); }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
preloadPrev
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function bind(element, event, callback, options) { if (element.addEventListener) { element.addEventListener(event, callback, options); } else { // IE8 fallback element.attachEvent('on' + event, function(event) { // `event` and `event.target` are not pr...
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
bind
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function unbind(element, event, callback, options) { if (element.removeEventListener) { element.removeEventListener(event, callback, options); } else { // IE8 fallback element.detachEvent('on' + event, callback); } }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
unbind
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function getByID(id) { return document.getElementById(id); }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
getByID
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function create(element) { return document.createElement(element); }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
create
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function destroyPlugin() { unbindEvents(); clearCachedData(); unbind(document, 'keydown', keyDownHandler); document.getElementsByTagName('body')[0].removeChild(document.getElementById('baguetteBox-overlay')); data = {}; currentGallery = []; currentIndex = 0; }
Triggers the bounce animation @param {('left'|'right')} direction - Direction of the movement
destroyPlugin
javascript
feimosi/baguetteBox.js
src/baguetteBox.js
https://github.com/feimosi/baguetteBox.js/blob/master/src/baguetteBox.js
MIT
function getRandomArray (n) { var res = [] , i, j, temp ; for (i = 0; i < n; i += 1) { res[i] = i; } for (i = n - 1; i >= 1; i -= 1) { j = Math.floor((i + 1) * Math.random()); temp = res[i]; res[i] = res[j]; res[j] = temp; } return res; }
Return an array with the numbers from 0 to n-1, in a random order Uses Fisher Yates algorithm Useful to get fair tests
getRandomArray
javascript
louischatriot/nedb
benchmarks/commonUtilities.js
https://github.com/louischatriot/nedb/blob/master/benchmarks/commonUtilities.js
MIT
function runFrom(i) { if (i === n) { // Finished var opsPerSecond = Math.floor(1000* n / profiler.elapsedSinceLastStep()); console.log("===== RESULT (insert) ===== " + opsPerSecond + " ops/s"); profiler.step('Finished inserting ' + n + ' docs'); profiler.insertOpsPerSecond = opsPerSecond; ...
Insert a certain number of documents for testing
runFrom
javascript
louischatriot/nedb
benchmarks/commonUtilities.js
https://github.com/louischatriot/nedb/blob/master/benchmarks/commonUtilities.js
MIT
function runFrom(i) { if (i === n) { // Finished console.log("===== RESULT (find with in selector) ===== " + Math.floor(1000* n / profiler.elapsedSinceLastStep()) + " ops/s"); profiler.step('Finished finding ' + n + ' docs'); return cb(); } d.find({ docNumber: { $in: ins[i] } }, functio...
Find documents with find and the $in operator
runFrom
javascript
louischatriot/nedb
benchmarks/commonUtilities.js
https://github.com/louischatriot/nedb/blob/master/benchmarks/commonUtilities.js
MIT
function runFrom(i) { if (i === n) { // Finished console.log("===== RESULT (update) ===== " + Math.floor(1000* n / profiler.elapsedSinceLastStep()) + " ops/s"); profiler.step('Finished updating ' + n + ' docs'); return cb(); } // Will not actually modify the document but will take the s...
Update documents options is the same as the options object for update
runFrom
javascript
louischatriot/nedb
benchmarks/commonUtilities.js
https://github.com/louischatriot/nedb/blob/master/benchmarks/commonUtilities.js
MIT
function runFrom(i) { if (i === n) { // Finished // opsPerSecond corresponds to 1 insert + 1 remove, needed to keep collection size at 10,000 // We need to subtract the time taken by one insert to get the time actually taken by one remove var opsPerSecond = Math.floor(1000 * n / profiler.elapsed...
Remove documents options is the same as the options object for update
runFrom
javascript
louischatriot/nedb
benchmarks/commonUtilities.js
https://github.com/louischatriot/nedb/blob/master/benchmarks/commonUtilities.js
MIT
function ensureDirExists (name) { try { fs.mkdirSync(path.join(__dirname, name)); } catch (e) { if (e.code !== 'EEXIST') { console.log("Error ensuring that node_modules exists"); process.exit(1); } } }
Build the browser version of nedb
ensureDirExists
javascript
louischatriot/nedb
browser-version/build.js
https://github.com/louischatriot/nedb/blob/master/browser-version/build.js
MIT
function randomBytes (size) { var bytes = new Array(size); var r; for (var i = 0, r; i < size; i++) { if ((i & 0x03) == 0) r = Math.random() * 0x100000000; bytes[i] = r >>> ((i & 0x03) << 3) & 0xff; } return bytes; }
Taken from the crypto-browserify module https://github.com/dominictarr/crypto-browserify NOTE: Math.random() does not guarantee "cryptographic quality" but we actually don't need it
randomBytes
javascript
louischatriot/nedb
browser-version/browser-specific/lib/customUtils.js
https://github.com/louischatriot/nedb/blob/master/browser-version/browser-specific/lib/customUtils.js
MIT
function uid (len) { return byteArrayToBase64(randomBytes(Math.ceil(Math.max(8, len * 2)))).replace(/[+\/]/g, '').slice(0, len); }
Return a random alphanumerical string of length len There is a very small probability (less than 1/1,000,000) for the length to be less than len (il the base64 conversion yields too many pluses and slashes) but that's not an issue here The probability of a collision is extremely small (need 3*10^12 documents to have on...
uid
javascript
louischatriot/nedb
browser-version/browser-specific/lib/customUtils.js
https://github.com/louischatriot/nedb/blob/master/browser-version/browser-specific/lib/customUtils.js
MIT
function exists (filename, callback) { localforage.getItem(filename, function (err, value) { if (value !== null) { // Even if value is undefined, localforage returns null return callback(true); } else { return callback(false); } }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
exists
javascript
louischatriot/nedb
browser-version/browser-specific/lib/storage.js
https://github.com/louischatriot/nedb/blob/master/browser-version/browser-specific/lib/storage.js
MIT
function rename (filename, newFilename, callback) { localforage.getItem(filename, function (err, value) { if (value === null) { localforage.removeItem(newFilename, function () { return callback(); }); } else { localforage.setItem(newFilename, value, function () { localforage.removeItem(fil...
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
rename
javascript
louischatriot/nedb
browser-version/browser-specific/lib/storage.js
https://github.com/louischatriot/nedb/blob/master/browser-version/browser-specific/lib/storage.js
MIT
function writeFile (filename, contents, options, callback) { // Options do not matter in browser setup if (typeof options === 'function') { callback = options; } localforage.setItem(filename, contents, function () { return callback(); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
writeFile
javascript
louischatriot/nedb
browser-version/browser-specific/lib/storage.js
https://github.com/louischatriot/nedb/blob/master/browser-version/browser-specific/lib/storage.js
MIT
function appendFile (filename, toAppend, options, callback) { // Options do not matter in browser setup if (typeof options === 'function') { callback = options; } localforage.getItem(filename, function (err, contents) { contents = contents || ''; contents += toAppend; localforage.setItem(filename, co...
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
appendFile
javascript
louischatriot/nedb
browser-version/browser-specific/lib/storage.js
https://github.com/louischatriot/nedb/blob/master/browser-version/browser-specific/lib/storage.js
MIT
function readFile (filename, options, callback) { // Options do not matter in browser setup if (typeof options === 'function') { callback = options; } localforage.getItem(filename, function (err, contents) { return callback(null, contents || ''); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
readFile
javascript
louischatriot/nedb
browser-version/browser-specific/lib/storage.js
https://github.com/louischatriot/nedb/blob/master/browser-version/browser-specific/lib/storage.js
MIT
function unlink (filename, callback) { localforage.removeItem(filename, function () { return callback(); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
unlink
javascript
louischatriot/nedb
browser-version/browser-specific/lib/storage.js
https://github.com/louischatriot/nedb/blob/master/browser-version/browser-specific/lib/storage.js
MIT
function mkdirp (dir, callback) { return callback(); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
mkdirp
javascript
louischatriot/nedb
browser-version/browser-specific/lib/storage.js
https://github.com/louischatriot/nedb/blob/master/browser-version/browser-specific/lib/storage.js
MIT
function ensureDatafileIntegrity (filename, callback) { return callback(null); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
ensureDatafileIntegrity
javascript
louischatriot/nedb
browser-version/browser-specific/lib/storage.js
https://github.com/louischatriot/nedb/blob/master/browser-version/browser-specific/lib/storage.js
MIT
function Cursor (db, query, execFn) { this.db = db; this.query = query || {}; if (execFn) { this.execFn = execFn; } }
Create a new cursor for this collection @param {Datastore} db - The datastore this cursor is bound to @param {Query} query - The query this cursor will operate on @param {Function} execFn - Handler to be executed after cursor has found the results and before the callback passed to find/findOne/update/remove
Cursor
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function callback (error, res) { if (self.execFn) { return self.execFn(error, res, _callback); } else { return _callback(error, res); } }
Get all matching elements Will return pointers to matched elements (shallow copies), returning full copies is the role of find or findOne This is an internal function, use exec which uses the executor @param {Function} callback - Signature: err, results
callback
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function randomBytes (size) { var bytes = new Array(size); var r; for (var i = 0, r; i < size; i++) { if ((i & 0x03) == 0) r = Math.random() * 0x100000000; bytes[i] = r >>> ((i & 0x03) << 3) & 0xff; } return bytes; }
Taken from the crypto-browserify module https://github.com/dominictarr/crypto-browserify NOTE: Math.random() does not guarantee "cryptographic quality" but we actually don't need it
randomBytes
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function uid (len) { return byteArrayToBase64(randomBytes(Math.ceil(Math.max(8, len * 2)))).replace(/[+\/]/g, '').slice(0, len); }
Return a random alphanumerical string of length len There is a very small probability (less than 1/1,000,000) for the length to be less than len (il the base64 conversion yields too many pluses and slashes) but that's not an issue here The probability of a collision is extremely small (need 3*10^12 documents to have on...
uid
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function Executor () { this.buffer = []; this.ready = false; // This queue will execute all commands, one-by-one in order this.queue = async.queue(function (task, cb) { var newArguments = []; // task.arguments is an array-like object on which adding a new field doesn't work, so we transform it into a ...
Responsible for sequentially executing actions on the database
Executor
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function checkValueEquality (a, b) { return a === b; }
Two indexed pointers are equal iif they point to the same place
checkValueEquality
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function Index (options) { this.fieldName = options.fieldName; this.unique = options.unique || false; this.sparse = options.sparse || false; this.treeOptions = { unique: this.unique, compareKeys: model.compareThings, checkValueEquality: checkValueEquality }; this.reset(); // No data in the beginning }
Create a new index All methods on an index guarantee that either the whole operation was successful and the index changed or the operation was unsuccessful and an error is thrown while the index is unchanged @param {String} options.fieldName On which field should the index apply (can use dot notation to index on sub fi...
Index
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function checkKey (k, v) { if (typeof k === 'number') { k = k.toString(); } if (k[0] === '$' && !(k === '$$date' && typeof v === 'number') && !(k === '$$deleted' && v === true) && !(k === '$$indexCreated') && !(k === '$$indexRemoved')) { throw new Error('Field names cannot begin with the $ character'); ...
Check a key, throw an error if the key is non valid @param {String} k key @param {Model} v value, needed to treat the Date edge case Non-treatable edge cases here: if part of the object if of the form { $$date: number } or { $$deleted: true } Its serialized-then-deserialized version it will transformed into a Date obje...
checkKey
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function checkObject (obj) { if (util.isArray(obj)) { obj.forEach(function (o) { checkObject(o); }); } if (typeof obj === 'object' && obj !== null) { Object.keys(obj).forEach(function (k) { checkKey(k, obj[k]); checkObject(obj[k]); }); } }
Check a DB object and throw an error if it's not valid Works by applying the above checkKey function to all fields recursively
checkObject
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function deserialize (rawData) { return JSON.parse(rawData, function (k, v) { if (k === '$$date') { return new Date(v); } if (typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean' || v === null) { return v; } if (v && v.$$date) { return v.$$date; } return v; }); }
From a one-line representation of an object generate by the serialize function Return the object itself
deserialize
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function deepCopy (obj, strictKeys) { var res; if ( typeof obj === 'boolean' || typeof obj === 'number' || typeof obj === 'string' || obj === null || (util.isDate(obj)) ) { return obj; } if (util.isArray(obj)) { res = []; obj.forEach(function (o) { res.push(deepCopy(o, ...
Deep copy a DB object The optional strictKeys flag (defaulting to false) indicates whether to copy everything or only fields where the keys are valid, i.e. don't begin with $ and don't contain a .
deepCopy
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function compareNSB (a, b) { if (a < b) { return -1; } if (a > b) { return 1; } return 0; }
Utility functions for comparing things Assumes type checking was already done (a and b already have the same type) compareNSB works for numbers, strings and booleans
compareNSB
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function compareArrays (a, b) { var i, comp; for (i = 0; i < Math.min(a.length, b.length); i += 1) { comp = compareThings(a[i], b[i]); if (comp !== 0) { return comp; } } // Common section was identical, longest one wins return compareNSB(a.length, b.length); }
Utility functions for comparing things Assumes type checking was already done (a and b already have the same type) compareNSB works for numbers, strings and booleans
compareArrays
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function compareThings (a, b, _compareStrings) { var aKeys, bKeys, comp, i , compareStrings = _compareStrings || compareNSB; // undefined if (a === undefined) { return b === undefined ? 0 : -1; } if (b === undefined) { return a === undefined ? 0 : 1; } // null if (a === null) { return b === null ? 0 :...
Compare { things U undefined } Things are defined as any native types (string, number, boolean, null, date) and objects We need to compare with undefined as it will be used in indexes In the case of objects and arrays, we deep-compare If two objects dont have the same type, the (arbitrary) type hierarchy is: undefined,...
compareThings
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function createModifierFunction (modifier) { return function (obj, field, value) { var fieldParts = typeof field === 'string' ? field.split('.') : field; if (fieldParts.length === 1) { lastStepModifierFunctions[modifier](obj, field, value); } else { if (obj[fieldParts[0]] === undefined) { ...
Updates the value of the field, only if specified field is smaller than the current value of the field
createModifierFunction
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function modify (obj, updateQuery) { var keys = Object.keys(updateQuery) , firstChars = _.map(keys, function (item) { return item[0]; }) , dollarFirstChars = _.filter(firstChars, function (c) { return c === '$'; }) , newDoc, modifiers ; if (keys.indexOf('_id') !== -1 && updateQuery._id !== obj._id)...
Modify a DB object according to an update query
modify
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function getDotValue (obj, field) { var fieldParts = typeof field === 'string' ? field.split('.') : field , i, objs; if (!obj) { return undefined; } // field cannot be empty so that means we should return undefined so that nothing can match if (fieldParts.length === 0) { return obj; } if (fieldParts.le...
Get a value from object with dot notation @param {Object} obj @param {String} field
getDotValue
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function areThingsEqual (a, b) { var aKeys , bKeys , i; // Strings, booleans, numbers, null if (a === null || typeof a === 'string' || typeof a === 'boolean' || typeof a === 'number' || b === null || typeof b === 'string' || typeof b === 'boolean' || typeof b === 'number') { return a === b; } // Dates ...
Check whether 'things' are equal Things are defined as any native types (string, number, boolean, null, date) and objects In the case of object, we check deep equality Returns true if they are, false otherwise
areThingsEqual
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function areComparable (a, b) { if (typeof a !== 'string' && typeof a !== 'number' && !util.isDate(a) && typeof b !== 'string' && typeof b !== 'number' && !util.isDate(b)) { return false; } if (typeof a !== typeof b) { return false; } return true; }
Check that two values are comparable
areComparable
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function match (obj, query) { var queryKeys, queryKey, queryValue, i; // Primitive query against a primitive type // This is a bit of a hack since we construct an object with an arbitrary key only to dereference it later // But I don't have time for a cleaner implementation now if (isPrimitiveType(obj) || is...
Tell if a given document matches a query @param {Object} obj Document to check @param {Object} query
match
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function matchQueryPart (obj, queryKey, queryValue, treatObjAsValue) { var objValue = getDotValue(obj, queryKey) , i, keys, firstChars, dollarFirstChars; // Check if the value is an array if we don't force a treatment as value if (util.isArray(objValue) && !treatObjAsValue) { // If the queryValue is an a...
Match an object against a specific { key: value } part of a query if the treatObjAsValue flag is set, don't try to match every part separately, but the array as a whole
matchQueryPart
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function Persistence (options) { var i, j, randomString; this.db = options.db; this.inMemoryOnly = this.db.inMemoryOnly; this.filename = this.db.filename; this.corruptAlertThreshold = options.corruptAlertThreshold !== undefined ? options.corruptAlertThreshold : 0.1; if (!this.inMemoryOnly && this.filename...
Create a new Persistence object for database options.db @param {Datastore} options.db @param {Boolean} options.nodeWebkitAppName Optional, specify the name of your NW app if you want options.filename to be relative to the directory where Node Webkit stores application data suc...
Persistence
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function exists (filename, callback) { localforage.getItem(filename, function (err, value) { if (value !== null) { // Even if value is undefined, localforage returns null return callback(true); } else { return callback(false); } }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
exists
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function rename (filename, newFilename, callback) { localforage.getItem(filename, function (err, value) { if (value === null) { localforage.removeItem(newFilename, function () { return callback(); }); } else { localforage.setItem(newFilename, value, function () { localforage.removeItem(fil...
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
rename
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function writeFile (filename, contents, options, callback) { // Options do not matter in browser setup if (typeof options === 'function') { callback = options; } localforage.setItem(filename, contents, function () { return callback(); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
writeFile
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function appendFile (filename, toAppend, options, callback) { // Options do not matter in browser setup if (typeof options === 'function') { callback = options; } localforage.getItem(filename, function (err, contents) { contents = contents || ''; contents += toAppend; localforage.setItem(filename, co...
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
appendFile
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function readFile (filename, options, callback) { // Options do not matter in browser setup if (typeof options === 'function') { callback = options; } localforage.getItem(filename, function (err, contents) { return callback(null, contents || ''); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
readFile
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function unlink (filename, callback) { localforage.removeItem(filename, function () { return callback(); }); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
unlink
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function mkdirp (dir, callback) { return callback(); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
mkdirp
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function ensureDatafileIntegrity (filename, callback) { return callback(null); }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
ensureDatafileIntegrity
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
function only_once(fn) { var called = false; return function() { if (called) throw new Error("Callback was already called."); called = true; fn.apply(root, arguments); } }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
only_once
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_each = function (arr, iterator) { if (arr.forEach) { return arr.forEach(iterator); } for (var i = 0; i < arr.length; i += 1) { iterator(arr[i], i, arr); } }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_each
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_map = function (arr, iterator) { if (arr.map) { return arr.map(iterator); } var results = []; _each(arr, function (x, i, a) { results.push(iterator(x, i, a)); }); return results; }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_map
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_reduce = function (arr, iterator, memo) { if (arr.reduce) { return arr.reduce(iterator, memo); } _each(arr, function (x, i, a) { memo = iterator(memo, x, i, a); }); return memo; }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_reduce
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_keys = function (obj) { if (Object.keys) { return Object.keys(obj); } var keys = []; for (var k in obj) { if (obj.hasOwnProperty(k)) { keys.push(k); } } return keys; }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_keys
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
iterate = function () { iterator(arr[completed], function (err) { if (err) { callback(err); callback = function () {}; } else { completed += 1; if (completed >= arr.length) { ...
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
iterate
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
_eachLimit = function (limit) { return function (arr, iterator, callback) { callback = callback || function () {}; if (!arr.length || limit <= 0) { return callback(); } var completed = 0; var started = 0; var running = 0; ...
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
_eachLimit
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT
doParallel = function (fn) { return function () { var args = Array.prototype.slice.call(arguments); return fn.apply(null, [async.each].concat(args)); }; }
Way data is stored for this database For a Node.js/Node Webkit database it's the file system For a browser-side database it's localforage, which uses the best backend available (IndexedDB then WebSQL then localStorage) This version is the browser version
doParallel
javascript
louischatriot/nedb
browser-version/out/nedb.js
https://github.com/louischatriot/nedb/blob/master/browser-version/out/nedb.js
MIT