Skip to content

Commit

Permalink
added is-promise
Browse files Browse the repository at this point in the history
added is-numeric-int
  • Loading branch information
farzher committed Sep 22, 2016
1 parent 0b3566d commit 63c1e2c
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 34 deletions.
2 changes: 1 addition & 1 deletion browser.min.js

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 4 additions & 6 deletions index.ls
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ _.map-number = (value, from1, from2, to1, to2, o=null) ->
if is-negative => ratio = -ratio
b-dist * ratio + to1

_.is-numeric = (n) -> !(isNaN parseFloat n) && isFinite n

## Obj

Expand Down Expand Up @@ -208,21 +207,20 @@ _.capitalize = (str) -> (str.substr 0, 1)toUpperCase! + str.substr 1

## Util

# -> bool
_.is-func = -> typeof! it is 'Function'
# -> bool
_.is-arr = -> typeof! it is 'Array'
# -> bool
_.is-obj = -> typeof! it is 'Object'
# -> bool
_.is-bool = -> typeof! it is 'Boolean'
# -> bool
_.is-num = -> typeof! it is 'Number'
_.is-promise = -> typeof! it.then is 'Function'
_.is-numeric = (n) -> !(isNaN parseFloat n) && isFinite n
_.is-numeric-int = (x) -> Number.isInteger (Number x)
# -> str
_.to-json = -> try JSON.stringify it
# -> mixed
# If there's any error, this returns undefined instead of throwing an error
_.json-parse = -> try JSON.parse it
_.from-json = _.json-parse # Alias, can't decide what name is better

# @usage on('resize', _.debounce(onResize, 100))
_.debounce = (func, wait, immediate) !->
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prelude-ls-extended",
"version": "0.10.0",
"version": "0.11.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
49 changes: 37 additions & 12 deletions test/test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 29 additions & 11 deletions test/test.ls
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,6 @@ exports import
it.strictEqual (_.map-number -0.5, 0, 1, 0, 1, {exponent:2.1}), -(0.5^2.1)
it.strictEqual (_.map-number 0, 0, 1, 100, 0), 100
it.done!
is-numeric: ->
it.strictEqual (_.is-numeric 1), true
it.strictEqual (_.is-numeric '50.34'), true
it.strictEqual (_.is-numeric '50.34b'), false
it.strictEqual (_.is-numeric '0x50.34'), false
it.strictEqual (_.is-numeric '0x50.34'), false
it.strictEqual (_.is-numeric {}), false
it.strictEqual (_.is-numeric '-23.23'), true
it.strictEqual (_.is-numeric '-23.23.23'), false
it.done!
import: ->
a = {a:1}
b = {b:2}
Expand Down Expand Up @@ -217,10 +207,38 @@ exports import
it.strictEqual (_.is-bool false), true
it.strictEqual (_.is-bool 1), false
it.done!
is-promise: ->
p = new Promise (resolve, reject) !->
p-like = {then: ->}
not-p = {then: true}
it.strictEqual (_.is-promise p), true
it.strictEqual (_.is-promise p-like), true
it.strictEqual (_.is-promise not-p), false
it.done!
is-num: ->
it.strictEqual (_.is-num 0), true
it.strictEqual (_.is-num '1'), false
it.done!
is-numeric: ->
it.strictEqual (_.is-numeric 1), true
it.strictEqual (_.is-numeric '50.34'), true
it.strictEqual (_.is-numeric '50.34b'), false
it.strictEqual (_.is-numeric '0x50.34'), false
it.strictEqual (_.is-numeric '0x50.34'), false
it.strictEqual (_.is-numeric {}), false
it.strictEqual (_.is-numeric '-23.23'), true
it.strictEqual (_.is-numeric '-23.23.23'), false
it.done!
is-numeric-int: ->
it.strictEqual (_.is-numeric-int 1), true
it.strictEqual (_.is-numeric-int '50.34'), false
it.strictEqual (_.is-numeric-int '50.34b'), false
it.strictEqual (_.is-numeric-int '0x50'), true
it.strictEqual (_.is-numeric-int '0x50.34'), false
it.strictEqual (_.is-numeric-int {}), false
it.strictEqual (_.is-numeric-int '-23'), true
it.strictEqual (_.is-numeric-int '-23.23.23'), false
it.done!
to-json: ->
circular={};circular.circular=circular
it.strictEqual (_.to-json {a:1}), '{"a":1}'
Expand All @@ -239,7 +257,7 @@ exports import
nodeunit.ok 1
nodeunit.done!

debounced = _.debounce funcToDebounce, 100
debounced = _.debounce funcToDebounce, 100, true
debounced!
debounced!
debounced!
Expand Down

0 comments on commit 63c1e2c

Please sign in to comment.