cowarray
Implementation of copy-on-write for JavaScript arrays using ES2015 Proxy Objects
cowarray is an experimental project written in TypeScript. It seeks to completely decouple test source code from the actual library source code and just happens to provide an implementation of copy-on-write for JavaScript arrays using ES2015 Proxy Objects for something to do.
If you are looking for a way to architect your own TypeScript project, this project might give you some ideas. That being the case, you are probably best off cloning or forking the development project off GitHub and studying the source.
cowarray was created and is maintained by me, Justin Johansson, just out of curiosity about ES2015 Proxy Objects.
Features
- Fully and transparently supports all ES3, ES5 and ES2015 Array properties and methods via a Proxy
- Proxied subject array is only ever copied when an attempt is made to write to it
- TypeScript source, compiled to and delivered as readable JavaScript
- Library module shipped with TypeScript type declaration file(s) for benefit of TypeScript application consumers
- cowarray API uses TypeScript generic function signatures to preserve array semantics
Requirements
- JavaScript engine with ES2015 Proxy support (e.g. Node >= 6.5.0, up-to-date standards-compliant browsers). Check MDN.
Installation
Via NPM
npm install --save cowarray
API
From JavaScript with CommonJS require
// Choose cowarrayLax or cowarrayStrict as documented in the source code.// cowarrayLax is best choice for most applications.var cowarray = cowarrayLax;//var cowarray = require('cowarray').cowarrayStrict; const input_array_not_to_be_modified = 'the' 'quick' 'red' 'fox'; const working_array_which_may_be_modified = ;working_array_which_may_be_modified2 = 'brown'; // working_array_which_may_be_modified is now [ 'the', 'quick', 'brown', 'fox' ]console; // input_array_not_to_be_modified is still [ 'the', 'quick', 'red', 'fox' ]console;
Testcode in TypeScript or JavaScript/ES2015 with ES2015 import
// Choose cowarrayLax or cowarrayStrict as documented in the source code.// cowarrayLax is best choice for most applications.;//import { cowarrayStrict as cowarray } from 'cowarray'; ; test'cowarray test', ;
Feedback
cowarray is currently a work-in-progress as far as it strives to be an exemplary TypeScript project. Feedback, especially suggestions for documentation & development workflow improvement, is most welcome via the project's issues pages on GitHub.