Skip to content

Commit

Permalink
Merge pull request #11 from blindlybright/master
Browse files Browse the repository at this point in the history
add option for ascii-only results output
  • Loading branch information
sgentle committed Dec 30, 2015
2 parents 882395b + ff1b886 commit 7df6369
Show file tree
Hide file tree
Showing 3 changed files with 24 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Options:
[boolean] [default: false]
--config, -C Path to JSON config file
[string] [default: "/Users/user/.caniuse.json"]
--ascii, -A UTF-8 symbols replacement with ASCII description
[boolean] [default: false]
--help Show help [boolean]
```
Expand Down
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 @@ -71,6 +64,11 @@ argv = require 'yargs'
alias: 'b'
type: 'string'
describe: "Show results for these browsers, comma-separated (#{Object.keys(data.agents)})"
.option 'ascii',
alias: 'A'
type: 'boolean'
default: false
describe: "UTF-8 symbols replacement with ASCII description"
.option 'web',
alias: 'w'
type: 'boolean'
Expand All @@ -85,6 +83,19 @@ argv = require 'yargs'
.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 7df6369

Please sign in to comment.