{"_id":"compute-indexspace","_rev":"8-cc33ecbca40c3e2da073476d794b23c4","name":"compute-indexspace","description":"Generates a linearly spaced index array from a subsequence string.","dist-tags":{"latest":"1.0.1"},"versions":{"0.0.0":{"name":"compute-indexspace","version":"0.0.0","description":"Generates a linearly spaced index array from a subsequence string.","author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"}],"scripts":{"test":"mocha","test-cov":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coverage -- -R spec","coveralls":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coveralls/coverage --report lcovonly -- -R spec && cat ./reports/coveralls/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./reports/coveralls"},"main":"./lib","repository":{"type":"git","url":"git://github.com/compute-io/indexspace.git"},"keywords":["compute.io","compute","computation","mathematics","math","array","index","slice","subsequence","indexarray","linear","utils","utilities"],"bugs":{"url":"https://github.com/compute-io/indexspace/issues"},"dependencies":{"validate.io-nonnegative-integer":"^1.0.0","validate.io-string-primitive":"^1.0.0"},"devDependencies":{"chai":"2.x.x","mocha":"2.x.x","coveralls":"^2.11.1","istanbul":"^0.3.0","jshint":"2.x.x","jshint-stylish":"^1.0.0"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"gitHead":"b65ef574e43e8df222420e2e9d9bd0cacea10609","homepage":"https://github.com/compute-io/indexspace","_id":"compute-indexspace@0.0.0","_shasum":"b3bc8e6ad3ec6fb7272fa806ca48ea9676a536f3","_from":".","_npmVersion":"1.5.0-alpha-1","_npmUser":{"name":"kgryte","email":"kgryte@gmail.com"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"dist":{"shasum":"b3bc8e6ad3ec6fb7272fa806ca48ea9676a536f3","tarball":"https://registry.npmjs.org/compute-indexspace/-/compute-indexspace-0.0.0.tgz","integrity":"sha512-6ZTDO6uP6qDIUcIO1i0jw9SiB6vf8mpUMix92OK5EBSos15TaqZZ+gcPD3tavMikllFsTDJDGVyOr0Jrtbl7pA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIExeemMNCKzn7gX/kx2P6GlYgyPUx5qAPgpWThBL9tn6AiBcKLocXGNtKmZJkdTPHxhWf0g4y4wCZxOreyIw1JZEiQ=="}]}},"1.0.0":{"name":"compute-indexspace","version":"1.0.0","description":"Generates a linearly spaced index array from a subsequence string.","author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"}],"scripts":{"test":"mocha","test-cov":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coverage -- -R spec","coveralls":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coveralls/coverage --report lcovonly -- -R spec && cat ./reports/coveralls/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./reports/coveralls"},"main":"./lib","repository":{"type":"git","url":"git://github.com/compute-io/indexspace.git"},"keywords":["compute.io","compute","computation","mathematics","math","array","index","slice","subsequence","indexarray","linear","utils","utilities"],"bugs":{"url":"https://github.com/compute-io/indexspace/issues"},"dependencies":{"validate.io-nonnegative-integer":"^1.0.0","validate.io-string-primitive":"^1.0.0"},"devDependencies":{"chai":"2.x.x","mocha":"2.x.x","coveralls":"^2.11.1","istanbul":"^0.3.0","jshint":"2.x.x","jshint-stylish":"^1.0.0"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"gitHead":"6209e5306bd54ae992df953b4f5b25d2995a152b","homepage":"https://github.com/compute-io/indexspace","_id":"compute-indexspace@1.0.0","_shasum":"f35653a37239ac63370e81eb4670140db01d232a","_from":".","_npmVersion":"1.5.0-alpha-1","_npmUser":{"name":"kgryte","email":"kgryte@gmail.com"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"dist":{"shasum":"f35653a37239ac63370e81eb4670140db01d232a","tarball":"https://registry.npmjs.org/compute-indexspace/-/compute-indexspace-1.0.0.tgz","integrity":"sha512-ECnYDIiSqnp4c5TwtsrTuYMwY+R6FzPvsNDJuEg87Uq979M8QJlX1Rg3Emxve6Ssz+xR9KDN82OfVkn40D/1bg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBAzx6mxF2k7pFitBvDO33v5988vuOfkwYiyCORXIDVJAiAn5HY6i6zdQcbEmQqDkzMYItEgP05Zo0SzUcCpvKxeHg=="}]}},"1.0.1":{"name":"compute-indexspace","version":"1.0.1","description":"Generates a linearly spaced index array from a subsequence string.","author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"}],"scripts":{"test":"mocha","test-cov":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coverage -- -R spec","coveralls":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coveralls/coverage --report lcovonly -- -R spec && cat ./reports/coveralls/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./reports/coveralls"},"main":"./lib","repository":{"type":"git","url":"git://github.com/compute-io/indexspace.git"},"keywords":["compute.io","compute","computation","mathematics","math","array","index","slice","subsequence","indexarray","linear","utils","utilities"],"bugs":{"url":"https://github.com/compute-io/indexspace/issues"},"dependencies":{"validate.io-nonnegative-integer":"^1.0.0","validate.io-string-primitive":"^1.0.0"},"devDependencies":{"chai":"2.x.x","mocha":"2.x.x","coveralls":"^2.11.1","istanbul":"^0.3.0","jshint":"2.x.x","jshint-stylish":"^1.0.0"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"gitHead":"de4895d8c4f78c5a03359427399dcd1166ebd948","homepage":"https://github.com/compute-io/indexspace","_id":"compute-indexspace@1.0.1","_shasum":"d81d0a582145c96e4bb39936aebdae6cc57e857f","_from":".","_npmVersion":"1.5.0-alpha-1","_npmUser":{"name":"kgryte","email":"kgryte@gmail.com"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"dist":{"shasum":"d81d0a582145c96e4bb39936aebdae6cc57e857f","tarball":"https://registry.npmjs.org/compute-indexspace/-/compute-indexspace-1.0.1.tgz","integrity":"sha512-8OufzDCPYqednk4OpkasFqiHULJSSKRO1kbL/sjLsVYX1qVe9IgzvVKnjelkv1XtAhntQ+rPPrtWy+A9H4y4ig==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCJ6X+JgmNk/8c5dg3lvteSFjOQOFqNz+JoSAAiKq/kHQIgVZp/bGMxRle12NF15OJT3ke+iMHKiFs7g2tH9zpALd4="}]}}},"readme":"indexspace\n===\n[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependencies][dependencies-image]][dependencies-url]\n\n> Generates a linearly spaced index array from a subsequence string.\n\n\n## Installation\n\n``` bash\n$ npm install compute-indexspace\n```\n\nFor use in the browser, use [browserify](https://github.com/substack/node-browserify).\n\n\n## Usage\n\n``` javascript\nvar indexspace = require( 'compute-indexspace' );\n```\n\n#### indexspace( str, len )\n\nGenerates a linearly spaced index `array` from a subsequence `string`. `len` specifies the reference `array` length, which is needed to properly interpret the subsequence `string`. If `len = 0`, the function returns an empty `array`.\n\n``` javascript\nvar arr = indexspace( ':', 5 );\n// returns [ 0, 1, 2, 3, 4 ]\n\narr = indexspace( ':', 0 );\n// returns []\n```\n\nThe subsequence `string` syntax is similar to Python's [slice](https://docs.python.org/2/tutorial/introduction.html) notation.\n\n``` javascript\nvar str = '<start>:<stop>:<increment>';\n```\n\nNotes about the notation:\n* \tIf an `increment` is not specified, the default increment is `1`. An `increment` of zero is __not__ allowed.\n*\tThe `start` index is __inclusive__, while the `stop` index is __exclusive__.\n* \tBoth `start` and `stop` indices are *optional*. If not provided, `start` and `stop` default to index extremes.\n* \tBoth `start` and `stop` can be negative, in which case the index is subtracted from `len`.\n\n``` javascript\nvar arr = indexspace( '-3:', 5 );\n// returns [ 2, 3, 4 ];\n\narr = indexspace( ':-2', 5 );\n// returns [ 0, 1, 2 ]\n```\n\nThe function also recognizes the `end` keyword, which refers to the last index; i.e., `len-1`. If specified as the `stop` index, `end` is __inclusive__ and equivalent to `<start>::<increment>`.\n\n``` javascript\nvar arr = indexspace( 'end::-1', 5 );\n// returns [ 4, 3, 2, 1, 0 ]\n\narr = indexspace( ':end', 5 );\n// returns [ 0, 1, 2, 3, 4 ]\n```\n\nBasic arithmetic (subtraction and division) may be performed on the `end` keyword. The result from division is __rounded up__ to the next integer.\n\n``` javascript\nvar arr = indexspace( 'end-2::-1', 5 );\n// returns [ 2, 1, 0 ];\n\narr = indexspace( ':end/2', 5 );\n// returns [ 0, 1 ]\n\narr = indexspace( 'end/2:', 5 );\n// returns [ 2, 3, 4 ]\n\narr = indexspace( 'end/3::-1', 5 );\n// returns [ 2, 1, 0 ];\n\narr = indexspace( '1:end:2', 5 );\n// returns [ 1, 3 ];\n```\n\n\n\n__Note__: unlike Matlab, but like Python, the subsequence `string` is upper-bound __exclusive__. For example, in Python, `0:2` corresponds to the index array `[0,1]`. In Matlab, `1:3` corresponds to `[1,2,3]`.\n\nThis implementation chooses to follow the Python convention such that `:n` combined with `n:` is equivalent to `:`. Using the Matlab convention, the two subsequences would overlap by one element.\n\n\n\n\n## Examples\n\n``` javascript\nvar indexspace = require( 'compute-indexspace' );\n\nvar arr = indexspace( ':', 5 );\n// returns [ 0, 1, 2, 3, 4 ] \n\narr = indexspace( '2:', 5 );\n// returns [ 2, 3, 4 ]\n\narr = indexspace( ':3', 5 );\n// returns [ 0, 1, 2 ]\n\narr = indexspace( '2:4', 5 );\n// returns [ 2, 3 ]\n\narr = indexspace( '1:4:2', 5 );\n// returns [ 1, 3 ]\n\narr = indexspace( '2::2', 5 );\n// returns [ 2, 4 ]\n\narr =  indexspace( ':10:3', 20 );\n// returns [ 0, 3, 6, 9 ]\n\narr = indexspace( ':-2', 5 );\n// returns [ 0, 1, 2 ]\n\narr = indexspace( ':-1:2', 5 );\n// returns [ 0, 2 ]\n\narr = indexspace( '-4:-1:2', 5 );\n// returns [ 1, 3 ]\n\narr = indexspace( '-5:-1', 5 );\n// returns [ 0, 1, 2, 3 ]\n\narr = indexspace( '::-1', 5 );\n// returns [ 4, 3, 2, 1, 0 ]\n\narr = indexspace( ':0:-1', 5 );\n// returns [ 4, 3, 2, 1 ]\n\narr = indexspace( '3:0:-1', 5 );\n// returns [ 3, 2, 1 ]\n\narr = indexspace( '-1:-4:-2', 5 );\n// returns [ 4, 2 ]\n\narr = indexspace( ':end', 5 );\n// returns [ 0, 1, 2, 3, 4 ]\n\narr = indexspace( ':end-1', 5 );\n// returns [ 0, 1, 2, 3 ]\n\narr = indexspace( ':end/2', 5 );\n// returns [ 0, 1 ]\n\narr = indexspace( 'end-2::-1', 5 );\n// returns [ 2, 1, 0 ]\n\narr = indexspace( 'end/2:', 5 );\n// returns [ 2, 3, 4 ]\n```\n\nTo run the example code from the top-level application directory,\n\n``` bash\n$ node ./examples/index.js\n```\n\n\n## Notes\n\nThe motivation for this module stems from wanting to create an API for `arrays` similar to Python and Matlab; e.g., `A = B[1:6:2];`. JavaScript only supports basic indexing; e.g., `A = B[3];`.\n\nThe workaround provided by this module is to express the subsequence syntax as a `string`, which, when provided with a reference `array` length, is parsed and then converted into an index `array`. A consumer can then iterate through the index `array` to extract the desired elements.\n\n``` javascript\nvar indexspace = require( 'compute-indexspace' );\n\n// Create an array...\nvar len = 10,\n\tarr;\n\narr = new Array( len );\nfor ( var i = 0; i < len; i++ ) {\n\tarr[ i ] = i;\n}\n\n// Create an index array...\nvar idx = indexspace( '::-1', len );\n\n// From the original array, create a reversed array...\nvar rev = new Array( len );\nfor ( var j = 0; j < len; j++ ) {\n\trev[ j ] = arr[ idx[j] ];\n}\nconsole.log( arr.join( ',' ) );\nconsole.log( rev.join( ',' ) );\n```\n\n\n\n\n## Tests\n\n### Unit\n\nUnit tests use the [Mocha](http://mochajs.org/) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory:\n\n``` bash\n$ make test\n```\n\nAll new feature development should have corresponding unit tests to validate correct functionality.\n\n\n### Test Coverage\n\nThis repository uses [Istanbul](https://github.com/gotwarlost/istanbul) as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:\n\n``` bash\n$ make test-cov\n```\n\nIstanbul creates a `./reports/coverage` directory. To access an HTML version of the report,\n\n``` bash\n$ make view-cov\n```\n\n\n---\n## License\n\n[MIT license](http://opensource.org/licenses/MIT). \n\n\n## Copyright\n\nCopyright &copy; 2015. Athan Reines.\n\n\n[npm-image]: http://img.shields.io/npm/v/compute-indexspace.svg\n[npm-url]: https://npmjs.org/package/compute-indexspace\n\n[travis-image]: http://img.shields.io/travis/compute-io/indexspace/master.svg\n[travis-url]: https://travis-ci.org/compute-io/indexspace\n\n[coveralls-image]: https://img.shields.io/coveralls/compute-io/indexspace/master.svg\n[coveralls-url]: https://coveralls.io/r/compute-io/indexspace?branch=master\n\n[dependencies-image]: http://img.shields.io/david/compute-io/indexspace.svg\n[dependencies-url]: https://david-dm.org/compute-io/indexspace\n\n[dev-dependencies-image]: http://img.shields.io/david/dev/compute-io/indexspace.svg\n[dev-dependencies-url]: https://david-dm.org/dev/compute-io/indexspace\n\n[github-issues-image]: http://img.shields.io/github/issues/compute-io/indexspace.svg\n[github-issues-url]: https://github.com/compute-io/indexspace/issues\n","maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"time":{"modified":"2022-06-13T20:29:10.348Z","created":"2015-03-20T23:59:14.017Z","0.0.0":"2015-03-20T23:59:14.017Z","1.0.0":"2015-03-20T23:59:46.845Z","1.0.1":"2015-03-21T10:05:38.622Z"},"homepage":"https://github.com/compute-io/indexspace","keywords":["compute.io","compute","computation","mathematics","math","array","index","slice","subsequence","indexarray","linear","utils","utilities"],"repository":{"type":"git","url":"git://github.com/compute-io/indexspace.git"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"}],"author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"bugs":{"url":"https://github.com/compute-io/indexspace/issues"},"readmeFilename":"README.md"}