lib/x10.js
function Address(address) {
	this.houseCode = null;
	this.unitCode = null;

	try {
		switch (typeof address) {
		case "object":
			if (_.isArray(address) && address.length === 2) {
				this.houseCode = new HouseCode(address[0]);
				this.unitCode = new UnitCode(address[1]);
			} else {
				if (address.houseCode !== undefined && address.houseCode !== null) {
					this.houseCode = new HouseCode(address.houseCode);
				}
				if (address.unitCode !== undefined && address.unitCode !== null) {
					this.unitCode = new UnitCode(address.unitCode);
				}
			}
			break;
		case "string":
			try {
				address = JSON.parse(address);
				if (address.hasOwnProperty("houseCode") && address.houseCode !== null) {
					this.houseCode = new HouseCode(address.houseCode);
				}
				if (address.hasOwnProperty("unitCode") && address.unitCode !== null) {
					this.unitCode = new UnitCode(address.unitCode);
				}
			} catch (e) {
				this.houseCode = new HouseCode((address.toUpperCase().match(/[A-P]+/)||[null])[0]);
				this.unitCode = new UnitCode((address.match(/\d+/)||[null])[0]);
			}
			break;
		case "number":
			this.houseCode = new HouseCode(address>>>4);
			this.unitCode = new UnitCode(address&0x0F);
			break;
		default:
			throw new Error("Invalid address.");
			break;
		}
	} catch (e) {
		throw new Error('Address out of range.');
	}
}
function Address(address) {
	this.houseCode = null;
	this.unitCode = null;

	try {
		switch (typeof address) {
		case "object":
			if (_.isArray(address) && address.length === 2) {
				this.houseCode = new HouseCode(address[0]);
				this.unitCode = new UnitCode(address[1]);
			} else {
				if (address.houseCode !== undefined && address.houseCode !== null) {
					this.houseCode = new HouseCode(address.houseCode);
				}
				if (address.unitCode !== undefined && address.unitCode !== null) {
					this.unitCode = new UnitCode(address.unitCode);
				}
			}
			break;
		case "string":
			try {
				address = JSON.parse(address);
				if (address.hasOwnProperty("houseCode") && address.houseCode !== null) {
					this.houseCode = new HouseCode(address.houseCode);
				}
				if (address.hasOwnProperty("unitCode") && address.unitCode !== null) {
					this.unitCode = new UnitCode(address.unitCode);
				}
			} catch (e) {
				this.houseCode = new HouseCode((address.toUpperCase().match(/[A-P]+/)||[null])[0]);
				this.unitCode = new UnitCode((address.match(/\d+/)||[null])[0]);
			}
			break;
		case "number":
			this.houseCode = new HouseCode(address>>>4);
			this.unitCode = new UnitCode(address&0x0F);
			break;
		default:
			throw new Error("Invalid address.");
			break;
		}
	} catch (e) {
		throw new Error('Address out of range.');
	}
}
function Address ( address ) { this . houseCode = null ; this . unitCode = null ; try { switch ( typeof address ) { case "object" : if ( _ . isArray ( address ) && address . length === 2 ) { this . houseCode = new HouseCode ( address [ 0 ] ) ; this . unitCode = new UnitCode ( address [ 1 ] ) ; } else { if ( address . houseCode !== undefined && address . houseCode !== null ) { this . houseCode = new HouseCode ( address . houseCode ) ; } if ( address . unitCode !== undefined && address . unitCode !== null ) { this . unitCode = new UnitCode ( address . unitCode ) ; } } break ; case "string" : try { address = JSON . parse ( address ) ; if ( address . hasOwnProperty ( "houseCode" ) && address . houseCode !== null ) { this . houseCode = new HouseCode ( address . houseCode ) ; } if ( address . hasOwnProperty ( "unitCode" ) && address . unitCode !== null ) { this . unitCode = new UnitCode ( address . unitCode ) ; } } catch ( e ) { this . houseCode = new HouseCode ( ( address . toUpperCase ( ) . match ( / [A-P]+ / ) || [ null ] ) [ 0 ] ) ; this . unitCode = new UnitCode ( ( address . match ( / \d+ / ) || [ null ] ) [ 0 ] ) ; } break ; case "number" : this . houseCode = new HouseCode ( address >>> 4 ) ; this . unitCode = new UnitCode ( address & 0x0F ) ; break ; default : throw new Error ( "Invalid address." ) ; break ; } } catch ( e ) { throw new Error ( 'Address out of range.' ) ; } }
object to convert X-10 addresses from numbers to strings and back
object to convert X - 10 addresses from numbers to strings and back