cassandraMAP
CassandraMAP is a JavaScript implementation of Cassandra's Map type based on JSON3, compatible with a variety of platforms, including Internet Explorer 6, Opera 7, Safari 2, and Netscape 6. The current version is 0.1.7.
- Development Version (32 KB; uncompressed with comments)
- Production Version (8 KB; compressed)
This code is based on JSON 3, created by bestiejs.
Apache Cassandra is an open-source distributed database managment system designed to handle large amounts of data. Within its query language, CQL, there is a map data type, which is equivalent to a JavaScript object. In order to query a database with CQL, a JavaScript object must be encoded into a JSON-like string that uses single quotes instead of the JSON standard double quotes. cassandraMAP provides a reliable, yet simple, way to encode objects into CQL-compilant map strings and decode them back to objects.
cassandraMAP exposes two functions: stringify()
for serializing a JavaScript value to a CQL Map, and parse()
for producing a JavaScript value from a CQL Map source string. Note: the links provided above are based on the JSON specification, and are provided only for reference purposes; cassandraMAP does not produce JSON-compilant results.
Portions of the date serialization code are adapted from the date-shim
project.
Usage
Web Browsers
Asynchronous Module Loaders
Just like JSON 3, cassandraMAP is defined as an anonymous module for compatibility with RequireJS, curl.js
, and other asynchronous module loaders.
CommonJS Environments
var cassandraMAP = ;cassandraMAP;// => [1, 2, 3]
Node.js
Installation
$ npm install cassandra-map
Usage
var cassandraMAP = ;cassandraMAP;
JavaScript Engines
;cassandraMAP;// => "{\n\t'Hello': 123\n}"
Known Incompatibilities
- Attempting to serialize the
arguments
object may produce inconsistent results across environments due to specification version differences. As a workaround, please convert thearguments
object to an array first:cassandraMAP.stringify([].slice.call(arguments, 0))
.
Required Native Methods
Just like JSON 3, cassandraMAP assumes that the following methods exist and function as described in the ECMAScript specification:
- The
Number
,String
,Array
,Object
,Date
,SyntaxError
, andTypeError
constructors. String.fromCharCode
Object#toString
Function#call
Math.floor
Number#toString
Date#valueOf
String.prototype
:indexOf
,charCodeAt
,charAt
,slice
.Array.prototype
:push
,pop
,join
.
Contribute
If you’d like to contribute a feature or bug fix, you can fork cassandraMAP, commit your changes, and send a pull request. Please make sure to update the unit tests in the test
directory as well.
Alternatively, you can use the GitHub issue tracker to submit bug reports, feature requests, and questions, or send tweets to @jcoc611.
cassandraMAP is released under the MIT License.