#!/usr/bin/env node
var nonary2bts = require('./').nonary2bts;
var bts2nonary = require('./').bts2nonary;

// TODO: refactor with balanced-ternary module?
// if the string could possibly represent balanced ternary
function maybe_bts(s) {
  return !!s.match(/^[01i]+$/);
}


process.argv.slice(2).forEach(function(arg) {
  var ns = nonary2bts(arg);

  // ternary -> nonary

  console.log(ns+' = '+arg);

  if (maybe_bts(arg)) {
    console.log(arg+' = '+bts2nonary(arg));
  }
});


@@ -270,108 +270,173 @@
 %0A%7D%0A%0A
-%0Aprocess.argv.slice(2).forEach(function(arg) %7B%0A  var ns = nonary2bts(arg);%0A%0A  // ternary -%3E nonary%0A%0A
+function maybe_nonary(s) %7B%0A  return !!s.match(/%5E%5Babcd0wxyz%5D+$/);%0A%7D%0A%0A%0Aprocess.argv.slice(2).forEach(function(arg) %7B%0A  // ternary -%3E nonary%0A%0A  if (maybe_bts(arg)) %7B%0A  
   co
@@ -449,22 +449,39 @@
 log(
-ns
+arg
 +' = '+
-arg);
+bts2nonary(arg));%0A  %7D
 %0A%0A  
@@ -482,35 +482,38 @@
  %7D%0A%0A  if (maybe_
-bts
+nonary
 (arg)) %7B%0A    con
@@ -525,34 +525,34 @@
 log(
+nonary2bts(
 arg
+)
 +' = '+
-bts2nonary(
 arg)
-)
 ;%0A  

Check in nonary_cli if maybe nonary