Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2015-05-22 11:33:46 +0300
committerRebecca Turner <me@re-becca.org>2015-06-26 03:27:03 +0300
commitd3c858ce4cfb3aee515bb299eb034fe1b5e44344 (patch)
treee7714c839934a729b68038f4c7dc5ec3ed877638 /node_modules/array-index
parent24564b9654528d23c726cf9ea82b1aef2044b692 (diff)
deps: deduplicate npm@3 style
Diffstat (limited to 'node_modules/array-index')
-rw-r--r--node_modules/array-index/.npmignore1
-rw-r--r--node_modules/array-index/.travis.yml5
-rw-r--r--node_modules/array-index/History.md39
-rw-r--r--node_modules/array-index/Makefile11
-rw-r--r--node_modules/array-index/README.md156
-rw-r--r--node_modules/array-index/component.json22
-rw-r--r--node_modules/array-index/index.js180
-rw-r--r--node_modules/array-index/package.json82
-rw-r--r--node_modules/array-index/test.js76
9 files changed, 572 insertions, 0 deletions
diff --git a/node_modules/array-index/.npmignore b/node_modules/array-index/.npmignore
new file mode 100644
index 000000000..3c3629e64
--- /dev/null
+++ b/node_modules/array-index/.npmignore
@@ -0,0 +1 @@
+node_modules
diff --git a/node_modules/array-index/.travis.yml b/node_modules/array-index/.travis.yml
new file mode 100644
index 000000000..99cdc7439
--- /dev/null
+++ b/node_modules/array-index/.travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+ - "0.8"
+ - "0.10"
+ - "0.11"
diff --git a/node_modules/array-index/History.md b/node_modules/array-index/History.md
new file mode 100644
index 000000000..20b03e9a8
--- /dev/null
+++ b/node_modules/array-index/History.md
@@ -0,0 +1,39 @@
+
+0.1.1 / 2014-11-03
+==================
+
+ * index: use `%o` debug formatters
+ * .travis: don't test node v0.9.x
+ * README: use svg for Travis badge
+ * add .jshintrc file
+
+0.1.0 / 2013-12-01
+==================
+
+ * add `History.md` file
+ * .travis.yml: test node v0.8-v0.11
+ * add component.json
+ * package: update "main" field
+ * package: beautify
+
+0.0.4 / 2013-09-27
+==================
+
+ * ensure that the `length` property has the same maximum as regular Arrays
+
+0.0.3 / 2013-09-15
+==================
+
+ * add `toArray()`, `toJSON()`, and `toString()` functions
+ * add an `inspect()` function
+
+0.0.2 / 2013-09-15
+==================
+
+ * use "configurable: true"
+ * add `travis.yml` file
+
+0.0.1 / 2013-06-14
+==================
+
+ * Initial release
diff --git a/node_modules/array-index/Makefile b/node_modules/array-index/Makefile
new file mode 100644
index 000000000..0f14dac30
--- /dev/null
+++ b/node_modules/array-index/Makefile
@@ -0,0 +1,11 @@
+
+build: components index.js
+ @component build --dev
+
+components: component.json
+ @component install --dev
+
+clean:
+ rm -fr build components template.js
+
+.PHONY: clean
diff --git a/node_modules/array-index/README.md b/node_modules/array-index/README.md
new file mode 100644
index 000000000..ecd3498dd
--- /dev/null
+++ b/node_modules/array-index/README.md
@@ -0,0 +1,156 @@
+array-index
+===========
+### Invoke getter/setter functions on array-like objects
+[![Build Status](https://secure.travis-ci.org/TooTallNate/array-index.svg)](http://travis-ci.org/TooTallNate/array-index)
+
+
+This little module provides an `ArrayIndex` constructor function that you can
+inherit from with your own objects. When a numbered property gets read, then the
+`__get__` function on the object will be invoked. When a numbered property gets
+set, then the `__set__` function on the object will be invoked.
+
+
+Installation
+------------
+
+Install with `npm`:
+
+``` bash
+$ npm install array-index
+```
+
+
+Examples
+--------
+
+A quick silly example, using `Math.sqrt()` for the "getter":
+
+``` js
+var ArrayIndex = require('array-index')
+
+// let's just create a singleton instance.
+var a = new ArrayIndex()
+
+// the "__get__" function is invoked for each "a[n]" access.
+// it is given a single argument, the "index" currently being accessed.
+// so here, we're passing in the `Math.sqrt()` function, so accessing
+// "a[9]" will return `Math.sqrt(9)`.
+a.__get__ = Math.sqrt
+
+// the "__get__" and "__set__" functions are only invoked up
+// to "a.length", so we must set that manually.
+a.length = 10
+
+console.log(a)
+// [ 0,
+// 1,
+// 1.4142135623730951,
+// 1.7320508075688772,
+// 2,
+// 2.23606797749979,
+// 2.449489742783178,
+// 2.6457513110645907,
+// 2.8284271247461903,
+// 3,
+// __get__: [Function: sqrt] ]
+```
+
+Here's an example of creating a subclass of `ArrayIndex` using `util.inherits()`:
+
+``` js
+var ArrayIndex = require('array-index')
+var inherits = require('util').inherits
+
+function MyArray (length) {
+ // be sure to call the ArrayIndex constructor in your own constructor
+ ArrayIndex.call(this, length)
+
+ // the "set" object will contain values at indexes previously set,
+ // so that they can be returned in the "getter" function. This is just a
+ // silly example, your subclass will have more meaningful logic.
+ Object.defineProperty(this, 'set', {
+ value: Object.create(null),
+ enumerable: false
+ })
+}
+
+// inherit from the ArrayIndex's prototype
+inherits(MyArray, ArrayIndex)
+
+MyArray.prototype.__get__ = function (index) {
+ if (index in this.set) return this.set[index]
+ return index * 2
+}
+
+MyArray.prototype.__set__ = function (index, v) {
+ this.set[index] = v
+}
+
+
+// and now you can create some instances
+var a = new MyArray(15)
+a[9] = a[10] = a[14] = '_'
+a[0] = 'nate'
+
+console.log(a)
+// [ 'nate', 2, 4, 6, 8, 10, 12, 14, 16, '_', '_', 22, 24, 26, '_' ]
+```
+
+API
+---
+
+The `ArrayIndex` base class is meant to be subclassed, but it also has a few
+convenient functions built-in.
+
+### "length" -> Number
+
+The length of the ArrayIndex instance. The `__get__` and `__set__` functions will
+only be invoked on the object up to this "length". You may set this length at any
+time to adjust the amount range where the getters/setters will be invoked.
+
+### "toArray()" -> Array
+
+Returns a new regular Array instance with the same values that this ArrayIndex
+class would have. This function calls the `__get__` function repeatedly from
+`0...length-1` and returns the "flattened" array instance.
+
+### "toJSON()" -> Array
+
+All `ArrayIndex` instances get basic support for `JSON.stringify()`, which is
+the same as a "flattened" Array being stringified.
+
+### "toString()" -> String
+
+The `toString()` override is basically just `array.toArray().toString()`.
+
+### "format()" -> String
+
+The `inspect()` implementation for the REPL attempts to mimic what a regular
+Array looks like in the REPL.
+
+
+License
+-------
+
+(The MIT License)
+
+Copyright (c) 2012 Nathan Rajlich &lt;nathan@tootallnate.net&gt;
+
+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.
diff --git a/node_modules/array-index/component.json b/node_modules/array-index/component.json
new file mode 100644
index 000000000..390d7a7fe
--- /dev/null
+++ b/node_modules/array-index/component.json
@@ -0,0 +1,22 @@
+{
+ "name": "array-index",
+ "repo": "TooTallNate/array-index",
+ "description": "Invoke getter/setter functions on array-like objects",
+ "keywords": [
+ "index",
+ "array",
+ "getter",
+ "setter",
+ "proxy"
+ ],
+ "version": "0.1.1",
+ "dependencies": {
+ "visionmedia/debug": "*"
+ },
+ "development": {},
+ "license": "MIT",
+ "main": "index.js",
+ "scripts": [
+ "index.js"
+ ]
+}
diff --git a/node_modules/array-index/index.js b/node_modules/array-index/index.js
new file mode 100644
index 000000000..18069c6bc
--- /dev/null
+++ b/node_modules/array-index/index.js
@@ -0,0 +1,180 @@
+
+/**
+ * Module dependencies.
+ */
+
+var util = require('util')
+var debug = require('debug')('array-index')
+
+/**
+ * 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
+
+/**
+ * Subclass this.
+ */
+
+function ArrayIndex (length) {
+ Object.defineProperty(this, 'length', {
+ get: getLength,
+ set: setLength,
+ enumerable: false,
+ configurable: true
+ })
+
+ Object.defineProperty(this, '__length', {
+ value: 0,
+ writable: true,
+ enumerable: false,
+ configurable: true
+ })
+
+ if (arguments.length > 0) {
+ this.length = length
+ }
+}
+
+/**
+ * You overwrite the "__get__" function in your subclass.
+ */
+
+ArrayIndex.prototype.__get__ = function () {
+ throw new Error('you must implement the __get__ function')
+}
+
+/**
+ * You overwrite the "__set__" function in your subclass.
+ */
+
+ArrayIndex.prototype.__set__ = function () {
+ throw new Error('you must implement the __set__ function')
+}
+
+/**
+ * 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, l = this.length, 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 util.inspect(a)
+}
+
+/**
+ * Getter for the "length" property.
+ * Returns the value of the "__length" property.
+ */
+
+function getLength () {
+ debug('getting "length": %o', this.__length)
+ return this.__length
+}
+
+/**
+ * Setter for the "length" property.
+ * Calls "ensureLength()", then sets the "__length" property.
+ */
+
+function setLength (v) {
+ debug('setting "length": %o', v)
+ return this.__length = ensureLength(v)
+}
+
+/**
+ * Ensures that getters/setters from 0 up to "_length" have been defined
+ * on `ArrayIndex.prototype`.
+ *
+ * @api private
+ */
+
+function ensureLength (_length) {
+ var length
+ if (_length > MAX_LENGTH) {
+ length = MAX_LENGTH
+ } else {
+ length = _length | 0
+ }
+ var cur = ArrayIndex.prototype.__length__ | 0
+ var num = length - cur
+ if (num > 0) {
+ var desc = {}
+ debug('creating a descriptor object with %o entries', num)
+ for (var i = cur; i < length; i++) {
+ desc[i] = setup(i)
+ }
+ debug('done creating descriptor object')
+ debug('calling `Object.defineProperties()` with %o entries', num)
+ Object.defineProperties(ArrayIndex.prototype, desc)
+ debug('finished `Object.defineProperties()`')
+ ArrayIndex.prototype.__length__ = length
+ }
+ return length
+}
+
+/**
+ * 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.__get__(index)
+ }
+ function set (v) {
+ return this.__set__(index, v)
+ }
+ return {
+ enumerable: true
+ , configurable: true
+ , get: get
+ , set: set
+ }
+}
diff --git a/node_modules/array-index/package.json b/node_modules/array-index/package.json
new file mode 100644
index 000000000..a30106a99
--- /dev/null
+++ b/node_modules/array-index/package.json
@@ -0,0 +1,82 @@
+{
+ "_args": [
+ [
+ "array-index@~0.1.0",
+ "/Users/rebecca/code/npm/node_modules/path-array"
+ ]
+ ],
+ "_from": "array-index@>=0.1.0 <0.2.0",
+ "_id": "array-index@0.1.1",
+ "_inCache": true,
+ "_location": "/array-index",
+ "_nodeVersion": "0.10.32",
+ "_npmUser": {
+ "email": "nathan@tootallnate.net",
+ "name": "tootallnate"
+ },
+ "_npmVersion": "2.1.3",
+ "_phantomChildren": {},
+ "_requested": {
+ "name": "array-index",
+ "raw": "array-index@~0.1.0",
+ "rawSpec": "~0.1.0",
+ "scope": null,
+ "spec": ">=0.1.0 <0.2.0",
+ "type": "range"
+ },
+ "_requiredBy": [
+ "/path-array"
+ ],
+ "_resolved": "https://registry.npmjs.org/array-index/-/array-index-0.1.1.tgz",
+ "_shasum": "4d5eaf06cc3d925847cd73d1535c217ba306d3e1",
+ "_shrinkwrap": null,
+ "_spec": "array-index@~0.1.0",
+ "_where": "/Users/rebecca/code/npm/node_modules/path-array",
+ "author": {
+ "email": "nathan@tootallnate.net",
+ "name": "Nathan Rajlich",
+ "url": "http://tootallnate.net"
+ },
+ "bugs": {
+ "url": "https://github.com/TooTallNate/array-index/issues"
+ },
+ "dependencies": {
+ "debug": "*"
+ },
+ "description": "Invoke getter/setter functions on array-like objects",
+ "devDependencies": {},
+ "directories": {},
+ "dist": {
+ "shasum": "4d5eaf06cc3d925847cd73d1535c217ba306d3e1",
+ "tarball": "http://registry.npmjs.org/array-index/-/array-index-0.1.1.tgz"
+ },
+ "engines": {
+ "node": "*"
+ },
+ "gitHead": "65a5d884f25b4b7a1608e367d715d713dbd3b3d6",
+ "homepage": "https://github.com/TooTallNate/array-index",
+ "keywords": [
+ "array",
+ "getter",
+ "index",
+ "proxy",
+ "setter"
+ ],
+ "main": "index.js",
+ "maintainers": [
+ {
+ "name": "tootallnate",
+ "email": "nathan@tootallnate.net"
+ }
+ ],
+ "name": "array-index",
+ "optionalDependencies": {},
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/TooTallNate/array-index.git"
+ },
+ "scripts": {
+ "test": "node test"
+ },
+ "version": "0.1.1"
+}
diff --git a/node_modules/array-index/test.js b/node_modules/array-index/test.js
new file mode 100644
index 000000000..d9e9c1828
--- /dev/null
+++ b/node_modules/array-index/test.js
@@ -0,0 +1,76 @@
+
+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.throws(function () {
+ a[0]
+}, /__get__/)
+
+assert.throws(function () {
+ a[0] = 0
+}, /__set__/)
+
+
+/**
+ * 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.__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.__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))