1 |
|
2 | (function() {
|
3 | var GeneratorFunction, Type, curry, instanceOf, isArray, isBoolean, isBuffer, isDate, isDefined, isError, isFinite, isFloat, isFunction, isGeneratorFunction, isInteger, isKind, isNaN, isNumber, isObject, isPromise, isPrototype, isRegExp, isString, isTransitivePrototype, isType, isUndefined, prototype;
|
4 |
|
5 | curry = require("fairmont-core").curry;
|
6 |
|
7 | prototype = function(value) {
|
8 | if (value != null) {
|
9 | return Object.getPrototypeOf(value);
|
10 | }
|
11 | };
|
12 |
|
13 | isPrototype = curry(function(p, value) {
|
14 | return (p != null) && p === prototype(value);
|
15 | });
|
16 |
|
17 | isType = curry(function(type, value) {
|
18 | return isPrototype(type != null ? type.prototype : void 0, value);
|
19 | });
|
20 |
|
21 | isTransitivePrototype = curry(function(p, value) {
|
22 | var q;
|
23 | return (p != null) && (p === (q = prototype(value)) || (q && isTransitivePrototype(p, q)));
|
24 | });
|
25 |
|
26 | isKind = curry(function(type, value) {
|
27 | return isTransitivePrototype(type != null ? type.prototype : void 0, value);
|
28 | });
|
29 |
|
30 | isNumber = isType(Number);
|
31 |
|
32 | isNaN = function(n) {
|
33 | return Number.isNaN(n);
|
34 | };
|
35 |
|
36 | isFinite = function(n) {
|
37 | return Number.isFinite(n);
|
38 | };
|
39 |
|
40 | isInteger = function(n) {
|
41 | return Number.isInteger(n);
|
42 | };
|
43 |
|
44 | isFloat = function(n) {
|
45 | return n === +n && n !== (n | 0);
|
46 | };
|
47 |
|
48 | isBoolean = isType(Boolean);
|
49 |
|
50 | isDate = isType(Date);
|
51 |
|
52 | isRegExp = isType(RegExp);
|
53 |
|
54 | isString = isType(String);
|
55 |
|
56 | isBuffer = isType(Buffer);
|
57 |
|
58 | isFunction = isType(Function);
|
59 |
|
60 | isObject = isType(Object);
|
61 |
|
62 | isArray = isType(Array);
|
63 |
|
64 | isError = isType(Error);
|
65 |
|
66 | isDefined = function(x) {
|
67 | return x != null;
|
68 | };
|
69 |
|
70 | isUndefined = function(x) {
|
71 | return x == null;
|
72 | };
|
73 |
|
74 | GeneratorFunction = (function*() {
|
75 | return (yield null);
|
76 | }).constructor;
|
77 |
|
78 | isGeneratorFunction = isType(GeneratorFunction);
|
79 |
|
80 | isPromise = isType(Promise);
|
81 |
|
82 | instanceOf = curry(function(t, x) {
|
83 | return x instanceof t;
|
84 | });
|
85 |
|
86 | Type = {
|
87 | create: function(type) {
|
88 | return Object.create(type != null ? type.prototype : void 0);
|
89 | },
|
90 | define: function(parent) {
|
91 | if (parent == null) {
|
92 | parent = Object;
|
93 | }
|
94 | return {
|
95 | prototype: Type.create(parent)
|
96 | };
|
97 | }
|
98 | };
|
99 |
|
100 | module.exports = {
|
101 | prototype: prototype,
|
102 | isPrototype: isPrototype,
|
103 | isTransitivePrototype: isTransitivePrototype,
|
104 | isType: isType,
|
105 | isKind: isKind,
|
106 | Type: Type,
|
107 | instanceOf: instanceOf,
|
108 | isBoolean: isBoolean,
|
109 | isNumber: isNumber,
|
110 | isNaN: isNaN,
|
111 | isFinite: isFinite,
|
112 | isInteger: isInteger,
|
113 | isFloat: isFloat,
|
114 | isString: isString,
|
115 | isBuffer: isBuffer,
|
116 | isFunction: isFunction,
|
117 | isObject: isObject,
|
118 | isArray: isArray,
|
119 | isDefined: isDefined,
|
120 | isUndefined: isUndefined,
|
121 | isRegExp: isRegExp,
|
122 | isDate: isDate,
|
123 | isGeneratorFunction: isGeneratorFunction,
|
124 | isPromise: isPromise
|
125 | };
|
126 |
|
127 | }).call(this);
|