UNPKG

1.46 kBtext/coffeescriptView Raw
1{curry} = require "fairmont-core"
2
3prototype = (value) -> if value? then Object.getPrototypeOf value
4
5isPrototype = curry (p, value) -> p? && p == prototype value
6
7isType = curry (type, value) -> isPrototype type?.prototype, value
8
9isTransitivePrototype = curry (p, value) ->
10 p? && (p == (q = prototype value) || (q && isTransitivePrototype p, q))
11
12isKind = curry (type, value) -> isTransitivePrototype type?.prototype, value
13
14isNumber = isType Number
15
16isNaN = (n) -> Number.isNaN n
17
18isFinite = (n) -> Number.isFinite n
19
20isInteger = (n) -> Number.isInteger n
21
22isFloat = (n) -> n == +n && n != (n|0)
23
24isBoolean = isType Boolean
25
26isDate = isType Date
27
28isRegExp = isType RegExp
29
30isString = isType String
31
32isBuffer = isType Buffer
33
34isFunction = isType Function
35
36isObject = isType Object
37
38isArray = isType Array
39
40isError = isType Error
41
42isDefined = (x) -> x?
43
44isUndefined = (x) -> !x?
45
46GeneratorFunction = (-> yield null).constructor
47
48isGeneratorFunction = isType GeneratorFunction
49
50isPromise = isType Promise
51
52instanceOf = curry (t, x) -> x instanceof t
53
54Type =
55 create: (type) -> Object.create type?.prototype
56 define: (parent = Object) -> prototype: Type.create parent
57
58module.exports = {prototype, isPrototype, isTransitivePrototype,
59 isType, isKind, Type, instanceOf,
60 isBoolean, isNumber, isNaN, isFinite, isInteger, isFloat,
61 isString, isBuffer, isFunction, isObject, isArray, isDefined, isUndefined
62 isRegExp, isDate, isGeneratorFunction, isPromise}