Commit b6f092c5 authored by Χάρης Παπαδόπουλος's avatar Χάρης Παπαδόπουλος
Browse files

smart table installed. Two examples working

parent 26def32d

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.
{
"name": "array-index",
"repo": "TooTallNate/array-index",
"description": "Invoke getter/setter functions on array-like objects",
"keywords": [
"index",
"array",
"getter",
"setter",
"proxy"
],
"version": "1.0.0",
"dependencies": {
"visionmedia/debug": "*"
},
"development": {},
"license": "MIT",
"main": "index.js",
"scripts": [
"index.js"
]
}
/**
* Module dependencies.
*/
var Symbol = require('es6-symbol');
var debug = require('debug')('array-index');
var get = Symbol('get');
var set = Symbol('set');
var length = Symbol('length');
/**
* JavaScript Array "length" is bound to an unsigned 32-bit int.
* See: http://stackoverflow.com/a/6155063/376773
*/
var MAX_LENGTH = Math.pow(2, 32);
/**
* Module exports.
*/
module.exports = ArrayIndex;
ArrayIndex.get = get;
ArrayIndex.set = set;
/**
* Subclass this.
*/
function ArrayIndex (_length) {
Object.defineProperty(this, 'length', {
get: getLength,
set: setLength,
enumerable: false,
configurable: true
});
this[length] = 0;
if (arguments.length > 0) {
setLength.call(this, _length);
}
}
/**
* You overwrite the "get" Symbol in your subclass.
*/
ArrayIndex.prototype[ArrayIndex.get] = function () {
throw new Error('you must implement the `ArrayIndex.get` Symbol');
};
/**
* You overwrite the "set" Symbol in your subclass.
*/
ArrayIndex.prototype[ArrayIndex.set] = function () {
throw new Error('you must implement the `ArrayIndex.set` Symbol');
};
/**
* Converts this array class into a real JavaScript Array. Note that this
* is a "flattened" array and your defined getters and setters won't be invoked
* when you interact with the returned Array. This function will call the
* getter on every array index of the object.
*
* @return {Array} The flattened array
* @api public
*/
ArrayIndex.prototype.toArray = function toArray () {
var i = 0;
var l = this.length;
var array = new Array(l);
for (; i < l; i++) {
array[i] = this[i];
}
return array;
};
/**
* Basic support for `JSON.stringify()`.
*/
ArrayIndex.prototype.toJSON = function toJSON () {
return this.toArray();
};
/**
* toString() override. Use Array.prototype.toString().
*/
ArrayIndex.prototype.toString = function toString () {
var a = this.toArray();
return a.toString.apply(a, arguments);
};
/**
* inspect() override. For the REPL.
*/
ArrayIndex.prototype.inspect = function inspect () {
var a = this.toArray();
Object.keys(this).forEach(function (k) {
a[k] = this[k];
}, this);
return a;
};
/**
* Getter for the "length" property.
* Returns the value of the "length" Symbol.
*/
function getLength () {
debug('getting "length": %o', this[length]);
return this[length];
};
/**
* Setter for the "length" property.
* Calls "ensureLength()", then sets the "length" Symbol.
*/
function setLength (v) {
debug('setting "length": %o', v);
return this[length] = ensureLength(this, v);
};
/**
* Ensures that getters/setters from 0 up to "_newLength" have been defined
* on `Object.getPrototypeOf(this)`.
*
* @api private
*/
function ensureLength (self, _newLength) {
var newLength;
if (_newLength > MAX_LENGTH) {
newLength = MAX_LENGTH;
} else {
newLength = _newLength | 0;
}
var proto = Object.getPrototypeOf(self);
var cur = proto[length] | 0;
var num = newLength - cur;
if (num > 0) {
var desc = {};
debug('creating a descriptor object with %o entries', num);
for (var i = cur; i < newLength; i++) {
desc[i] = setup(i);
}
debug('calling `Object.defineProperties()` with %o entries', num);
Object.defineProperties(proto, desc);
proto[length] = newLength;
}
return newLength;
}
/**
* Returns a property descriptor for the given "index", with "get" and "set"
* functions created within the closure.
*
* @api private
*/
function setup (index) {
function get () {
return this[ArrayIndex.get](index);
}
function set (v) {
return this[ArrayIndex.set](index, v);
}
return {
enumerable: true,
configurable: true,
get: get,
set: set
};
}
{
"_args": [
[
{
"raw": "array-index@^1.0.0",
"scope": null,
"escapedName": "array-index",
"name": "array-index",
"rawSpec": "^1.0.0",
"spec": ">=1.0.0 <2.0.0",
"type": "range"
},
"/home/haris/devel/eepal/node_modules/path-array"
]
],
"_from": "array-index@>=1.0.0 <2.0.0",
"_id": "array-index@1.0.0",
"_inCache": true,
"_location": "/array-index",
"_nodeVersion": "5.3.0",
"_npmUser": {
"name": "tootallnate",
"email": "nathan@tootallnate.net"
},
"_npmVersion": "3.3.12",
"_phantomChildren": {},
"_requested": {
"raw": "array-index@^1.0.0",
"scope": null,
"escapedName": "array-index",
"name": "array-index",
"rawSpec": "^1.0.0",
"spec": ">=1.0.0 <2.0.0",
"type": "range"
},
"_requiredBy": [
"/path-array"
],
"_resolved": "https://registry.npmjs.org/array-index/-/array-index-1.0.0.tgz",
"_shasum": "ec56a749ee103e4e08c790b9c353df16055b97f9",
"_shrinkwrap": null,
"_spec": "array-index@^1.0.0",
"_where": "/home/haris/devel/eepal/node_modules/path-array",
"author": {
"name": "Nathan Rajlich",
"email": "nathan@tootallnate.net",
"url": "http://tootallnate.net"
},
"bugs": {
"url": "https://github.com/TooTallNate/array-index/issues"
},
"dependencies": {
"debug": "^2.2.0",
"es6-symbol": "^3.0.2"
},
"description": "Invoke getter/setter functions on array-like objects",
"devDependencies": {},
"directories": {},
"dist": {
"shasum": "ec56a749ee103e4e08c790b9c353df16055b97f9",
"tarball": "https://registry.npmjs.org/array-index/-/array-index-1.0.0.tgz"
},
"engines": {
"node": "*"
},
"gitHead": "4b3cc059c70eefd8ef2a0d4213d681b671eb3d11",
"homepage": "https://github.com/TooTallNate/array-index#readme",
"keywords": [
"index",
"array",
"getter",
"setter",
"proxy"
],
"license": "MIT",
"main": "index.js",
"maintainers": [
{
"name": "tootallnate",
"email": "nathan@tootallnate.net"
}
],
"name": "array-index",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git://github.com/TooTallNate/array-index.git"
},
"scripts": {
"test": "node test"
},
"version": "1.0.0"
}
var ArrayIndex = require('./')
var inherits = require('util').inherits
var assert = require('assert')
/**
* Create a "subclass".
*/
function Arrayish (length) {
ArrayIndex.call(this, length)
this.sets = Object.create(null)
}
// inherit from `ArrayIndex`
inherits(Arrayish, ArrayIndex)
// create an instance and run some tests
var a = new Arrayish(11)
assert.equal(a.length, 11);
assert.throws(function () {
a[0]
}, /you must implement the `ArrayIndex.get` Symbol/)
assert.throws(function () {
a[0] = 0
}, /you must implement the `ArrayIndex.set` Symbol/)
/**
* This "getter" function checks if the index has previosly been "set", and if so
* returns the index * the value previously set. If the index hasn't been set,
* return the index as-is.
*/
Arrayish.prototype[ArrayIndex.get] = function get (index) {
if (index in this.sets) {
return +this.sets[index] * index
} else {
return index
}
}
/**
* Store the last value set for this index.
*/
Arrayish.prototype[ArrayIndex.set] = function set (index, value) {
this.sets[index] = value
}
// test getters without being "set"
assert.equal(0, a[0])
assert.equal(1, a[1])
assert.equal(2, a[2])
assert.equal(3, a[3])
assert.equal(4, a[4])
// test setters, followed by getters
a[10] = 1
assert.equal(10, a[10])
a[10] = 2
assert.equal(20, a[10])
a[10] = 3
assert.equal(30, a[10])
// test "length"
assert.equal(11, a.length)
a[4] = 20
a[6] = 5.55432
var b = [0, 1, 2, 3, 80, 5, 33.325919999999996, 7, 8, 9, 30]
assert.equal(JSON.stringify(b), JSON.stringify(a))
/**
* It should work when invoking as a Mixin.
*/
function Foo () {
ArrayIndex.call(this, 5);
}
var f = new Foo();
// these throw because there's no __get__ and __set__ function defined
assert.throws(function () {
f[0];
});
assert.throws(function () {
f[0] = 0
});
f[ArrayIndex.get] = function (index) {
return index * 2;
};
assert.equal(f[0], 0);
assert.equal(f[1], 2);
assert.equal(f[2], 4);
assert.equal(f[3], 6);
f[ArrayIndex.set] = function (index, value) {
this['foo' + index] = value;
};
f[1] = 'bar';
assert.equal(f.foo1, 'bar');
language: node_js
node_js:
- 0.8
- 0.10
Copyright (c) 2011 Mark Cavage, All rights reserved.
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:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE
node-asn1 is a library for encoding and decoding ASN.1 datatypes in pure JS.
Currently BER encoding is supported; at some point I'll likely have to do DER.
## Usage
Mostly, if you're *actually* needing to read and write ASN.1, you probably don't
need this readme to explain what and why. If you have no idea what ASN.1 is,
see this: ftp://ftp.rsa.com/pub/pkcs/ascii/layman.asc
The source is pretty much self-explanatory, and has read/write methods for the
common types out there.
### Decoding
The following reads an ASN.1 sequence with a boolean.
var Ber = require('asn1').Ber;
var reader = new Ber.Reader(new Buffer([0x30, 0x03, 0x01, 0x01, 0xff]));
reader.readSequence();
console.log('Sequence len: ' + reader.length);
if (reader.peek() === Ber.Boolean)
console.log(reader.readBoolean());
### Encoding
The following generates the same payload as above.
var Ber = require('asn1').Ber;
var writer = new Ber.Writer();
writer.startSequence();
writer.writeBoolean(true);
writer.endSequence();
console.log(writer.buffer);
## Installation
npm install asn1
## License
MIT.
## Bugs
See <https://github.com/mcavage/node-asn1/issues>.
// Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
module.exports = {
newInvalidAsn1Error: function(msg) {
var e = new Error();
e.name = 'InvalidAsn1Error';
e.message = msg || '';
return e;
}
};
// Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
var errors = require('./errors');
var types = require('./types');
var Reader = require('./reader');
var Writer = require('./writer');
///--- Exports
module.exports = {
Reader: Reader,
Writer: Writer
};
for (var t in types) {
if (types.hasOwnProperty(t))
module.exports[t] = types[t];
}
for (var e in errors) {
if (errors.hasOwnProperty(e))
module.exports[e] = errors[e];
}
// Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
var assert = require('assert');
var ASN1 = require('./types');
var errors = require('./errors');
///--- Globals
var newInvalidAsn1Error = errors.newInvalidAsn1Error;
///--- API
function Reader(data) {
if (!data || !Buffer.isBuffer(data))
throw new TypeError('data must be a node Buffer');
this._buf = data;
this._size = data.length;
// These hold the "current" state
this._len = 0;
this._offset = 0;
}
Object.defineProperty(Reader.prototype, 'length', {
enumerable: true,
get: function () { return (this._len); }
});
Object.defineProperty(Reader.prototype, 'offset', {
enumerable: true,
get: function () { return (this._offset); }
});
Object.defineProperty(Reader.prototype, 'remain', {
get: function () { return (this._size - this._offset); }
});
Object.defineProperty(Reader.prototype, 'buffer', {
get: function () { return (this._buf.slice(this._offset)); }
});
/**
* Reads a single byte and advances offset; you can pass in `true` to make this
* a "peek" operation (i.e., get the byte, but don't advance the offset).
*
* @param {Boolean} peek true means don't move offset.
* @return {Number} the next byte, null if not enough data.
*/
Reader.prototype.readByte = function(peek) {
if (this._size - this._offset < 1)
return null;
var b = this._buf[this._offset] & 0xff;
if (!peek)
this._offset += 1;
return b;
};
Reader.prototype.peek = function() {
return this.readByte(true);
};
/**