Skip to content

Commit

Permalink
feat(ascii): add option for ascii-only results output
Browse files Browse the repository at this point in the history
  • Loading branch information
blindlybright committed Oct 15, 2015
1 parent 882395b commit a0531e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
34 changes: 21 additions & 13 deletions caniuse.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ open = require 'open'
path = require 'path'
osHomedir = require 'os-homedir'

if (Date.now()/1000 - data.updated) > 30*60*60*24
console.warn """
⚠ Caniuse data is more than 30 days out of date!
Consider updating: npm install -g caniuse-cmd
""".yellow

argv = require 'yargs'
.option 'short',
alias: 's'
Expand Down Expand Up @@ -81,10 +74,28 @@ argv = require 'yargs'
type: 'string'
default: path.join(osHomedir(), '.caniuse.json')
describe: "Specify a config file with default options"
.option 'ascii',
alias: 'A'
type: 'boolean'
default: false
describe: "UTF symbols replacement with ASCII description"
.config 'config'
.help 'help'
.argv

resultmap = y: "", n: "", a: "", u: "", i: "", w: ""
supernums = "⁰¹²³⁴⁵⁶⁷⁸⁹"

if argv["ascii"]
resultmap = y: "[Yes]", n: "[No]", a: "[Partly]", u: "[?!]", i: "[Info]", w: "[Warning]"

if (Date.now()/1000 - data.updated) > 30*60*60*24
console.warn """
#{resultmap.w} Caniuse data is more than 30 days out of date!
Consider updating: npm install -g caniuse-cmd
""".yellow

if argv.web
return open "http://caniuse.com/#search=#{encodeURIComponent argv._.join ' '}"

Expand Down Expand Up @@ -118,9 +129,6 @@ versionrange[1] = Infinity if argv.future
versionrange[0] = currentVersion if argv.current
versionrange[0] = eras.indexOf(argv.era) if argv.era

resultmap = y: "", n: "", a: "", u: ""
supernums = "⁰¹²³⁴⁵⁶⁷⁸⁹"

# Generate the text for a single version result
# FIXME: gross output parameter
makeResult = (result, nums={}) ->
Expand Down Expand Up @@ -173,8 +181,8 @@ showFeature = (result, opts={}) ->
opts.short ?= !opts.long

percentages = []
percentages.push " #{result.usage_perc_y}%".green if result.usage_perc_y
percentages.push " #{result.usage_perc_a}%".yellow if result.usage_perc_a
percentages.push resultmap.y + " #{result.usage_perc_y}%".green if result.usage_perc_y
percentages.push resultmap.a + " #{result.usage_perc_a}%".yellow if result.usage_perc_a
percentages = percentages.join(' ')

status = if opts.long then " [#{data.statuses[result.status]}]" else ''
Expand Down Expand Up @@ -219,7 +227,7 @@ showFeature = (result, opts={}) ->
unless opts.short
for num, note of result.notes_by_num when need_note[num]
console.log wrap "\t\t#{supernums[num].yellow}#{note}"
console.log wrap "\t #{result.notes.replace(/[\r\n]+/g, ' ')}" if result.notes
console.log wrap "\t " + resultmap.i + " #{result.notes.replace(/[\r\n]+/g, ' ')}" if result.notes


slowFind = (query) ->
Expand Down

0 comments on commit a0531e6

Please sign in to comment.