Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Update files to reflect new project name.

  • Loading branch information...
commit 0676476019793ade24ac9e25da497eadee4ac6a2 1 parent 97b6ce0
@coreh authored
View
8 lib/date.js
@@ -1,5 +1,5 @@
/**
- * Create a date from an OpenAnything representation.
+ * Create a date from a WebD representation.
* @param {Object} input
* @returns {Date}
* @api public
@@ -9,12 +9,12 @@ exports.parse = function(input) {
}
/**
- * Convert a Date to an OpenAnything representation
+ * Convert a Date to a WebD representation
* @returns {Object}
* @api public
*/
-Date.prototype.toOA = function() {
- return { _: 'oa:date'
+Date.prototype.toWebD = function() {
+ return { _: 'webd:date'
, value: this.toJSON()
}
}
View
10 lib/measure.js
@@ -56,19 +56,19 @@ Measure.prototype.toString = function() {
}
/**
- * Convert this measurement to an OpenAnything representation
+ * Convert this measurement to a WebD representation
* @returns {Object}
* @api public
*/
-Measure.prototype.toOA = function() {
- return { _: 'oa:measure'
+Measure.prototype.toWebD = function() {
+ return { _: 'webd:measure'
, value: this.value
- , unit: this.unit.toOA()
+ , unit: this.unit.toWebD()
}
}
/**
- * Create an Measure object from an OpenAnything representation
+ * Create an Measure object from a WebD representation
* @param {Object} input the input
* @returns {Measure}
* @api public
View
8 lib/regexp.js
@@ -1,5 +1,5 @@
/**
- * Create a regular expression from an OpenAnything representation.
+ * Create a regular expression from a WebD representation.
* @param {Object} input
* @returns {RegExp}
* @api public
@@ -9,12 +9,12 @@ exports.parse = function(input) {
}
/**
- * Convert a regular expression to an OpenAnything representation
+ * Convert a regular expression to a WebD representation
* @returns {Object}
* @api public
*/
-RegExp.prototype.toOA = function() {
- return { _: 'oa:regexp'
+RegExp.prototype.toWebD = function() {
+ return { _: 'webd:regexp'
, value: this.source
}
}
View
4 lib/undefined.js
@@ -1,5 +1,5 @@
/**
- * "Create" `undefined` from it's OpenAnything representation
+ * "Create" `undefined` from its WebD representation
* @param {Object} input
* @returns {undefined}
* @api public
@@ -8,4 +8,4 @@ exports.parse = function(input) {
// return undefined
}
-exports.singleton = { _: 'oa:undefined' }
+exports.singleton = { _: 'webd:undefined' }
View
8 lib/unit.js
@@ -87,14 +87,14 @@ Unit.prototype.equals = function(that) {
}
/**
- * Return the OpenAnything representation of this object
+ * Return the WebD representation of this object
*
- * @returns {Object} OpenAnything representation
+ * @returns {Object} WebD representation
* @api public
*/
-Unit.prototype.toOA = function() {
- var result = { _: 'oa:unit' }
+Unit.prototype.toWebD = function() {
+ var result = { _: 'webd:unit' }
if (this.numerator.length > 0) {
result.numerator = this.numerator
}
View
36 lib/oa.js → lib/webd.js
@@ -3,22 +3,22 @@
*/
var parsers =
- { 'oa:date': require('./date')
- , 'oa:measure': require('./measure')
- , 'oa:unit': require('./unit')
- , 'oa:undefined': require('./undefined')
- , 'oa:regexp': require('./regexp')
+ { 'webd:date': require('./date')
+ , 'webd:measure': require('./measure')
+ , 'webd:unit': require('./unit')
+ , 'webd:undefined': require('./undefined')
+ , 'webd:regexp': require('./regexp')
}
/**
* Register a new parsing function
*
* @param {String} uri An uri used to uniquely identify this format.
- * The protocol of the URI should be either `oa:`,
+ * The protocol of the URI should be either `webd:`,
* `http:` or `https:`. If the protocol is `http:`
* or `https:`, the provided uri MUST point to a valid resource.
* This resource MUST contain a human readable specification
- * of the format. URIs with `oa:` protocol are reserved for
+ * of the format. URIs with `webd:` protocol are reserved for
* standard formats, but are still useful if you want to
* specify a custom parser.
*
@@ -34,9 +34,9 @@ exports.register = function(uri, parseFunction) {
}
/**
- * Decode an object from OpenAnything format.
+ * Decode an object from WebD format.
* This function does not perform JSON parsing.
- * If that's what you need, check out `oa.parse()`.
+ * If that's what you need, check out `webd.parse()`.
*
* @param {Object} obj The object being decoded
* @returns {Object} The decoded version of the object
@@ -86,7 +86,7 @@ var decode = exports.encode = function(obj) {
}
/**
- * Encode an object to OpenAnything format (but don't stringify it)
+ * Encode an object to WebD format (but don't stringify it)
*
* @param {Object} obj The object being encoded
* @returns {Object} The encoded version of the object
@@ -100,8 +100,8 @@ var encode = exports.encode = function(obj) {
} else if (['number', 'string', 'boolean'].indexOf(typeof obj) != -1) {
newObj = obj
} else if (typeof obj === 'object') {
- if (obj.toOA && obj.toOA instanceof Function) {
- newObj = obj.toOA()
+ if (obj.toWebD && obj.toWebD instanceof Function) {
+ newObj = obj.toWebD()
} else {
if (obj instanceof Array) {
newObj = []
@@ -119,13 +119,13 @@ var encode = exports.encode = function(obj) {
}
}
} else if (typeof obj === 'undefined') {
- newObj = parsers['oa:undefined'].singleton
+ newObj = parsers['webd:undefined'].singleton
}
return newObj
}
/**
- * Parse a JSON string representation of an object in OpenAnything format.
+ * Parse a JSON string representation of an object in WebD format.
*
* @param {String, Object} obj The Object being parsed
* @returns {Object} The result of the parsing
@@ -142,13 +142,13 @@ exports.parse = function(obj) {
}
/**
- * Stringify an object to a JSON representation of OpenAnything format.
+ * Stringify an object to a JSON representation of WebD format.
*
* @param {Object} obj The Object being stringified
* @param {String} space The character or sequence of characters used to indent the output.
* (e.g. ' ' or '\t'). If provided, the function will produce pretty
* printed output.
- * @returns {String} The string representing the Object in OpenAnything format
+ * @returns {String} The string representing the Object in WebD format
*
* @api public
*/
@@ -157,5 +157,5 @@ exports.stringify = function(obj, space) {
return JSON.stringify(encode(obj), null, space)
}
-exports.Unit = parsers['oa:unit']
-exports.Measure = parsers['oa:measure']
+exports.Unit = parsers['webd:unit']
+exports.Measure = parsers['webd:measure']
View
9 package.json
@@ -1,10 +1,11 @@
{
- "name": "oa"
- , "description": "OpenAnything for node.js"
- , "tags": ["open anything"]
- , "homepage": "https://github.com/coreh/openanything"
+ "name": "webd"
+ , "description": "WebD is a convention for representing a wide variety of datatypes in JSON."
+ , "tags": ["WebD", "data interchange"]
+ , "homepage": "https://github.com/coreh/webd"
, "version": "0.1.0"
, "engines": { "node": ">= 0.6.0" }
+ , "main": "./lib/webd.js"
, "dependencies": {}
, "devDependencies":
{ "expect.js": ">=0.1.2"
View
40 test/measure.js
@@ -1,47 +1,47 @@
-var oa = require('../lib/oa')
+var webd = require('../lib/webd')
var expect = require('expect.js')
-describe('oa.Measure', function() {
- var metersPerSecond = new oa.Unit('m', 's')
- var seconds = new oa.Unit('s')
+describe('webd.Measure', function() {
+ var metersPerSecond = new webd.Unit('m', 's')
+ var seconds = new webd.Unit('s')
it('should be a constructor', function() {
- expect(oa.Measure).to.be.a(Function)
+ expect(webd.Measure).to.be.a(Function)
})
it('should create a valid measure', function() {
- var result = new oa.Measure(5, seconds)
- expect(result).to.be.a(oa.Measure)
+ var result = new webd.Measure(5, seconds)
+ expect(result).to.be.a(webd.Measure)
expect(result.value).to.be(5)
expect(result.unit).to.be(seconds)
})
it('should add properly', function() {
- var m1 = new oa.Measure(5, seconds)
- var m2 = new oa.Measure(10, seconds)
+ var m1 = new webd.Measure(5, seconds)
+ var m2 = new webd.Measure(10, seconds)
var m3 = m1.add(m2)
- expect(m3).to.be.a(oa.Measure)
+ expect(m3).to.be.a(webd.Measure)
expect(m3.value).to.be(15)
expect(m3.unit).to.be(seconds)
})
it('should not allow adding measurements with different units', function() {
- var m1 = new oa.Measure(5, metersPerSecond)
- var m2 = new oa.Measure(3, seconds)
+ var m1 = new webd.Measure(5, metersPerSecond)
+ var m2 = new webd.Measure(3, seconds)
var m3 = m1.add(m2)
expect(m3).to.be(null)
})
it('should multiply properly', function() {
- var m1 = new oa.Measure(5, metersPerSecond)
- var m2 = new oa.Measure(3, seconds)
+ var m1 = new webd.Measure(5, metersPerSecond)
+ var m2 = new webd.Measure(3, seconds)
var m3 = m1.multiply(m2)
- expect(m3).to.be.a(oa.Measure)
+ expect(m3).to.be.a(webd.Measure)
expect(m3.value).to.be(15)
- expect(m3.unit).to.be.a(oa.Unit)
+ expect(m3.unit).to.be.a(webd.Unit)
expect(m3.unit.numerator).to.be.eql(['m'])
expect(m3.unit.denominator).to.be.eql([])
})
it('should convert properly to a string', function() {
- expect(new oa.Measure(5, new oa.Unit('m', 's')).toString()).to.be('5m/s')
- expect(new oa.Measure(5, new oa.Unit('m')).toString()).to.be('5m')
- expect(new oa.Measure(5, new oa.Unit([], 's')).toString()).to.be('5/s')
- expect(new oa.Measure(5, new oa.Unit()).toString()).to.be('5')
+ expect(new webd.Measure(5, new webd.Unit('m', 's')).toString()).to.be('5m/s')
+ expect(new webd.Measure(5, new webd.Unit('m')).toString()).to.be('5m')
+ expect(new webd.Measure(5, new webd.Unit([], 's')).toString()).to.be('5/s')
+ expect(new webd.Measure(5, new webd.Unit()).toString()).to.be('5')
})
})
View
42 test/unit.js
@@ -1,53 +1,53 @@
-var oa = require('../lib/oa')
+var webd = require('../lib/webd')
var expect = require('expect.js')
-describe('oa.Unit', function() {
+describe('webd.Unit', function() {
it('should be a constructor', function() {
- expect(oa.Unit).to.be.a(Function)
+ expect(webd.Unit).to.be.a(Function)
})
it('should create correct Units when given numerators and denominators', function() {
- var result = new oa.Unit(['m'],['s'])
- expect(result).to.be.a(oa.Unit)
+ var result = new webd.Unit(['m'],['s'])
+ expect(result).to.be.a(webd.Unit)
expect(result.numerator).to.be.eql(['m'])
expect(result.denominator).to.be.eql(['s'])
})
it('should accept numerators and denominators outside of arrays', function() {
- var result = new oa.Unit('m', 's')
- expect(result).to.be.a(oa.Unit)
+ var result = new webd.Unit('m', 's')
+ expect(result).to.be.a(webd.Unit)
expect(result.numerator).to.be.eql(['m'])
expect(result.denominator).to.be.eql(['s'])
})
it('should accept empty numerators', function() {
- var result = new oa.Unit([], ['s']) // Hertz
- expect(result).to.be.a(oa.Unit)
+ var result = new webd.Unit([], ['s']) // Hertz
+ expect(result).to.be.a(webd.Unit)
expect(result.numerator).to.be.eql([])
expect(result.denominator).to.be.eql(['s'])
})
it('should accept empty denominators', function() {
- var result = new oa.Unit(['s'], []) // Seconds
- expect(result).to.be.a(oa.Unit)
+ var result = new webd.Unit(['s'], []) // Seconds
+ expect(result).to.be.a(webd.Unit)
expect(result.numerator).to.be.eql(['s'])
expect(result.denominator).to.be.eql([])
})
it('should convert properly to a string', function() {
- expect(new oa.Unit(['m'], ['s']).toString()).to.be('m/s')
- expect(new oa.Unit([], ['s']).toString()).to.be('1/s')
- expect(new oa.Unit(['s'], []).toString()).to.be('s')
- expect(new oa.Unit([], []).toString()).to.be('1')
+ expect(new webd.Unit(['m'], ['s']).toString()).to.be('m/s')
+ expect(new webd.Unit([], ['s']).toString()).to.be('1/s')
+ expect(new webd.Unit(['s'], []).toString()).to.be('s')
+ expect(new webd.Unit([], []).toString()).to.be('1')
})
it('should multiply correctly', function() {
- var u1 = new oa.Unit('m', 's')
- var u2 = new oa.Unit('atoms', 'kg')
+ var u1 = new webd.Unit('m', 's')
+ var u2 = new webd.Unit('atoms', 'kg')
var u3 = u1.multiply(u2)
- expect(u3).to.be.a(oa.Unit)
+ expect(u3).to.be.a(webd.Unit)
expect(u3.numerator).to.be.eql(['atoms', 'm'])
expect(u3.denominator).to.be.eql(['kg', 's'])
})
it('should simplify correctly', function() {
- var u1 = new oa.Unit('m', ['s', 's'])
- var u2 = new oa.Unit('s')
+ var u1 = new webd.Unit('m', ['s', 's'])
+ var u2 = new webd.Unit('s')
var u3 = u1.multiply(u2)
- expect(u3).to.be.a(oa.Unit)
+ expect(u3).to.be.a(webd.Unit)
expect(u3.numerator).to.be.eql(['m'])
expect(u3.denominator).to.be.eql(['s'])
})
View
34 test/oa.js → test/webd.js
@@ -1,55 +1,55 @@
-var oa = require('../lib/oa')
+var webd = require('../lib/webd')
var expect = require('expect.js')
-describe('OpenAnything', function() {
+describe('WebD', function() {
it('should export a function named parse', function() {
- expect(oa.parse).to.be.a(Function)
+ expect(webd.parse).to.be.a(Function)
})
it('should parse dates', function() {
- var result = oa.parse(
- { _: 'oa:date'
+ var result = webd.parse(
+ { _: 'webd:date'
, value: '2012-02-05T21:43:51.173Z'
}
)
expect(result).to.be.a(Date)
})
it('should parse units', function() {
- var result = oa.parse(
- { _: 'oa:unit'
+ var result = webd.parse(
+ { _: 'webd:unit'
, numerator: ['m']
, denominator: ['s']
}
)
- expect(result).to.be.a(oa.Unit)
+ expect(result).to.be.a(webd.Unit)
expect(result.numerator).to.be.eql(['m'])
expect(result.denominator).to.be.eql(['s'])
})
it('should parse measures', function() {
- var result = oa.parse(
- { _: 'oa:measure'
+ var result = webd.parse(
+ { _: 'webd:measure'
, unit:
- { _: 'oa:unit'
+ { _: 'webd:unit'
, numerator: ['m']
, denominator: ['s']
}
, value: 0.5
}
)
- expect(result).to.be.a(oa.Measure)
+ expect(result).to.be.a(webd.Measure)
expect(result.value).to.be.a('number')
- expect(result.unit).to.be.a(oa.Unit)
+ expect(result.unit).to.be.a(webd.Unit)
})
it('should export a function named stringify', function() {
- expect(oa.stringify).to.be.a(Function);
+ expect(webd.stringify).to.be.a(Function);
})
it('should stringify dates', function() {
var now = new Date()
- expect(oa.stringify(now)).to.be('{"_":"oa:date","value":"' + now.toJSON() + '"}')
+ expect(webd.stringify(now)).to.be('{"_":"webd:date","value":"' + now.toJSON() + '"}')
})
it('should stringify units', function() {
- expect(oa.stringify(new oa.Unit('m', 's'))).to.be('{"_":"oa:unit","numerator":["m"],"denominator":["s"]}')
+ expect(webd.stringify(new webd.Unit('m', 's'))).to.be('{"_":"webd:unit","numerator":["m"],"denominator":["s"]}')
})
it('should stringify measures', function() {
- expect(oa.stringify(new oa.Measure(5, new oa.Unit('m', 's')))).to.be('{"_":"oa:measure","value":5,"unit":{"_":"oa:unit","numerator":["m"],"denominator":["s"]}}')
+ expect(webd.stringify(new webd.Measure(5, new webd.Unit('m', 's')))).to.be('{"_":"webd:measure","value":5,"unit":{"_":"webd:unit","numerator":["m"],"denominator":["s"]}}')
})
})
Please sign in to comment.
Something went wrong with that request. Please try again.