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