urbit-ob

JavaScript utilities for phonemic base wrangling.
Log | Files | Refs | README

commit a31048d881a3d1d8d9289b9afddaca71f0e06582
parent 76aa81f21124147fb73f91852673ff40ee60e3e3
Author: Anthony Arroyo <anthony@tlon.io>
Date:   Mon,  9 Jul 2018 13:49:27 -0700

check for NaN (means that isShip failed in some weird way)

Diffstat:
Mindex.js | 3++-
Mtest/main.js | 6++++++
2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/index.js b/index.js @@ -250,7 +250,8 @@ var toAddress = function(name, unscramble) { }; var isAddress = function(name) { - return typeof toAddress(name) != 'undefined'; + var r = toAddress(name); + return (typeof r != 'undefined' && r === r) } diff --git a/test/main.js b/test/main.js @@ -19,6 +19,12 @@ exports['test that stops execution'] = function(assert) { assert.equal(nom.toGalaxyName(200), 'lex', 'convert ship num 200 to ~lex'); assert.equal(nom.toStarName(512), 'binzod', 'convert ship num 512 to ~binzod'); assert.equal(nom.toPlanetName(9896704), 'poldec-tonteg', 'convert number 9896704 to ship name ~poldec-tonteg'); + assert.equal(nom.isShip('poldec-tonteg'), true, 'identifies poldec-tonteg as a ship'); + assert.equal(nom.isShip('aaa'), false, 'identifies aaa as not ship'); + assert.equal(nom.isShip("aaaaaa"), false, 'invalidates star'); + assert.equal(nom.isShip("//////"), false, 'invalidates star'); + assert.equal(nom.isShip("////////////"), false, 'invalidates planet'); + assert.equal(nom.isShip("//////-//////"), false, 'invalidates planet'); } if (module == require.main) require('test').run(exports);