2e007adb6c01c0f66554edf1609335d196e49ddcae6d9c87264e029fc6e1a0bf7d5c25ec3e3d7ae3cac6804fd986e0e037b77eb0311cc8b72ffac43d15ac2c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. /*globals define, module, Symbol */
  2. /*jshint -W056 */
  3. (function (globals) {
  4. 'use strict';
  5. var strings, messages, predicates, functions, assert, not, maybe,
  6. collections, slice, neginf, posinf, isArray, keys, haveSymbols;
  7. strings = {
  8. v: 'value',
  9. n: 'number',
  10. s: 'string',
  11. b: 'boolean',
  12. o: 'object',
  13. t: 'type',
  14. a: 'array',
  15. al: 'array-like',
  16. i: 'iterable',
  17. d: 'date',
  18. f: 'function',
  19. l: 'length'
  20. };
  21. messages = {};
  22. predicates = {};
  23. [
  24. { n: 'equal', f: equal, s: 'v' },
  25. { n: 'undefined', f: isUndefined, s: 'v' },
  26. { n: 'null', f: isNull, s: 'v' },
  27. { n: 'assigned', f: assigned, s: 'v' },
  28. { n: 'primitive', f: primitive, s: 'v' },
  29. { n: 'includes', f: includes, s: 'v' },
  30. { n: 'zero', f: zero },
  31. { n: 'infinity', f: infinity },
  32. { n: 'number', f: number },
  33. { n: 'integer', f: integer },
  34. { n: 'even', f: even },
  35. { n: 'odd', f: odd },
  36. { n: 'greater', f: greater },
  37. { n: 'less', f: less },
  38. { n: 'between', f: between },
  39. { n: 'greaterOrEqual', f: greaterOrEqual },
  40. { n: 'lessOrEqual', f: lessOrEqual },
  41. { n: 'inRange', f: inRange },
  42. { n: 'positive', f: positive },
  43. { n: 'negative', f: negative },
  44. { n: 'string', f: string, s: 's' },
  45. { n: 'emptyString', f: emptyString, s: 's' },
  46. { n: 'nonEmptyString', f: nonEmptyString, s: 's' },
  47. { n: 'contains', f: contains, s: 's' },
  48. { n: 'match', f: match, s: 's' },
  49. { n: 'boolean', f: boolean, s: 'b' },
  50. { n: 'object', f: object, s: 'o' },
  51. { n: 'emptyObject', f: emptyObject, s: 'o' },
  52. { n: 'nonEmptyObject', f: nonEmptyObject, s: 'o' },
  53. { n: 'instanceStrict', f: instanceStrict, s: 't' },
  54. { n: 'instance', f: instance, s: 't' },
  55. { n: 'like', f: like, s: 't' },
  56. { n: 'array', f: array, s: 'a' },
  57. { n: 'emptyArray', f: emptyArray, s: 'a' },
  58. { n: 'nonEmptyArray', f: nonEmptyArray, s: 'a' },
  59. { n: 'arrayLike', f: arrayLike, s: 'al' },
  60. { n: 'iterable', f: iterable, s: 'i' },
  61. { n: 'date', f: date, s: 'd' },
  62. { n: 'function', f: isFunction, s: 'f' },
  63. { n: 'hasLength', f: hasLength, s: 'l' },
  64. ].map(function (data) {
  65. var n = data.n;
  66. messages[n] = 'Invalid ' + strings[data.s || 'n'];
  67. predicates[n] = data.f;
  68. });
  69. functions = {
  70. map: map,
  71. all: all,
  72. any: any
  73. };
  74. collections = [ 'array', 'arrayLike', 'iterable', 'object' ];
  75. slice = Array.prototype.slice;
  76. neginf = Number.NEGATIVE_INFINITY;
  77. posinf = Number.POSITIVE_INFINITY;
  78. isArray = Array.isArray;
  79. keys = Object.keys;
  80. haveSymbols = typeof Symbol === 'function';
  81. functions = mixin(functions, predicates);
  82. assert = createModifiedPredicates(assertModifier, assertImpl);
  83. not = createModifiedPredicates(notModifier, notImpl);
  84. maybe = createModifiedPredicates(maybeModifier, maybeImpl);
  85. assert.not = createModifiedModifier(assertModifier, not);
  86. assert.maybe = createModifiedModifier(assertModifier, maybe);
  87. collections.forEach(createOfPredicates);
  88. createOfModifiers(assert, assertModifier);
  89. createOfModifiers(not, notModifier);
  90. collections.forEach(createMaybeOfModifiers);
  91. exportFunctions(mixin(functions, {
  92. assert: assert,
  93. not: not,
  94. maybe: maybe
  95. }));
  96. /**
  97. * Public function `equal`.
  98. *
  99. * Returns true if `lhs` and `rhs` are strictly equal, without coercion.
  100. * Returns false otherwise.
  101. */
  102. function equal (lhs, rhs) {
  103. return lhs === rhs;
  104. }
  105. /**
  106. * Public function `undefined`.
  107. *
  108. * Returns true if `data` is undefined, false otherwise.
  109. */
  110. function isUndefined (data) {
  111. return data === undefined;
  112. }
  113. /**
  114. * Public function `null`.
  115. *
  116. * Returns true if `data` is null, false otherwise.
  117. */
  118. function isNull (data) {
  119. return data === null;
  120. }
  121. /**
  122. * Public function `assigned`.
  123. *
  124. * Returns true if `data` is not null or undefined, false otherwise.
  125. */
  126. function assigned (data) {
  127. return data !== undefined && data !== null;
  128. }
  129. /**
  130. * Public function `primitive`.
  131. *
  132. * Returns true if `data` is a primitive type, false otherwise.
  133. */
  134. function primitive (data) {
  135. var type;
  136. switch (data) {
  137. case null:
  138. case undefined:
  139. case false:
  140. case true:
  141. return true;
  142. }
  143. type = typeof data;
  144. return type === 'string' || type === 'number' || (haveSymbols && type === 'symbol');
  145. }
  146. /**
  147. * Public function `zero`.
  148. *
  149. * Returns true if `data` is zero, false otherwise.
  150. */
  151. function zero (data) {
  152. return data === 0;
  153. }
  154. /**
  155. * Public function `infinity`.
  156. *
  157. * Returns true if `data` is positive or negative infinity, false otherwise.
  158. */
  159. function infinity (data) {
  160. return data === neginf || data === posinf;
  161. }
  162. /**
  163. * Public function `number`.
  164. *
  165. * Returns true if `data` is a number, false otherwise.
  166. */
  167. function number (data) {
  168. return typeof data === 'number' && data > neginf && data < posinf;
  169. }
  170. /**
  171. * Public function `integer`.
  172. *
  173. * Returns true if `data` is an integer, false otherwise.
  174. */
  175. function integer (data) {
  176. return typeof data === 'number' && data % 1 === 0;
  177. }
  178. /**
  179. * Public function `even`.
  180. *
  181. * Returns true if `data` is an even number, false otherwise.
  182. */
  183. function even (data) {
  184. return typeof data === 'number' && data % 2 === 0;
  185. }
  186. /**
  187. * Public function `odd`.
  188. *
  189. * Returns true if `data` is an odd number, false otherwise.
  190. */
  191. function odd (data) {
  192. return integer(data) && data % 2 !== 0;
  193. }
  194. /**
  195. * Public function `greater`.
  196. *
  197. * Returns true if `lhs` is a number greater than `rhs`, false otherwise.
  198. */
  199. function greater (lhs, rhs) {
  200. return number(lhs) && lhs > rhs;
  201. }
  202. /**
  203. * Public function `less`.
  204. *
  205. * Returns true if `lhs` is a number less than `rhs`, false otherwise.
  206. */
  207. function less (lhs, rhs) {
  208. return number(lhs) && lhs < rhs;
  209. }
  210. /**
  211. * Public function `between`.
  212. *
  213. * Returns true if `data` is a number between `x` and `y`, false otherwise.
  214. */
  215. function between (data, x, y) {
  216. if (x < y) {
  217. return greater(data, x) && data < y;
  218. }
  219. return less(data, x) && data > y;
  220. }
  221. /**
  222. * Public function `greaterOrEqual`.
  223. *
  224. * Returns true if `lhs` is a number greater than or equal to `rhs`, false
  225. * otherwise.
  226. */
  227. function greaterOrEqual (lhs, rhs) {
  228. return number(lhs) && lhs >= rhs;
  229. }
  230. /**
  231. * Public function `lessOrEqual`.
  232. *
  233. * Returns true if `lhs` is a number less than or equal to `rhs`, false
  234. * otherwise.
  235. */
  236. function lessOrEqual (lhs, rhs) {
  237. return number(lhs) && lhs <= rhs;
  238. }
  239. /**
  240. * Public function `inRange`.
  241. *
  242. * Returns true if `data` is a number in the range `x..y`, false otherwise.
  243. */
  244. function inRange (data, x, y) {
  245. if (x < y) {
  246. return greaterOrEqual(data, x) && data <= y;
  247. }
  248. return lessOrEqual(data, x) && data >= y;
  249. }
  250. /**
  251. * Public function `positive`.
  252. *
  253. * Returns true if `data` is a positive number, false otherwise.
  254. */
  255. function positive (data) {
  256. return greater(data, 0);
  257. }
  258. /**
  259. * Public function `negative`.
  260. *
  261. * Returns true if `data` is a negative number, false otherwise.
  262. */
  263. function negative (data) {
  264. return less(data, 0);
  265. }
  266. /**
  267. * Public function `string`.
  268. *
  269. * Returns true if `data` is a string, false otherwise.
  270. */
  271. function string (data) {
  272. return typeof data === 'string';
  273. }
  274. /**
  275. * Public function `emptyString`.
  276. *
  277. * Returns true if `data` is the empty string, false otherwise.
  278. */
  279. function emptyString (data) {
  280. return data === '';
  281. }
  282. /**
  283. * Public function `nonEmptyString`.
  284. *
  285. * Returns true if `data` is a non-empty string, false otherwise.
  286. */
  287. function nonEmptyString (data) {
  288. return string(data) && data !== '';
  289. }
  290. /**
  291. * Public function `contains`.
  292. *
  293. * Returns true if `data` is a string that contains `substring`, false
  294. * otherwise.
  295. */
  296. function contains (data, substring) {
  297. return string(data) && data.indexOf(substring) !== -1;
  298. }
  299. /**
  300. * Public function `match`.
  301. *
  302. * Returns true if `data` is a string that matches `regex`, false otherwise.
  303. */
  304. function match (data, regex) {
  305. return string(data) && !! data.match(regex);
  306. }
  307. /**
  308. * Public function `boolean`.
  309. *
  310. * Returns true if `data` is a boolean value, false otherwise.
  311. */
  312. function boolean (data) {
  313. return data === false || data === true;
  314. }
  315. /**
  316. * Public function `object`.
  317. *
  318. * Returns true if `data` is a plain-old JS object, false otherwise.
  319. */
  320. function object (data) {
  321. return Object.prototype.toString.call(data) === '[object Object]';
  322. }
  323. /**
  324. * Public function `emptyObject`.
  325. *
  326. * Returns true if `data` is an empty object, false otherwise.
  327. */
  328. function emptyObject (data) {
  329. return object(data) && !some(data, function () {
  330. return true;
  331. });
  332. }
  333. function some (data, predicate) {
  334. for (var key in data) {
  335. if (data.hasOwnProperty(key)) {
  336. if (predicate(key, data[key])) {
  337. return true;
  338. }
  339. }
  340. }
  341. return false;
  342. }
  343. /**
  344. * Public function `nonEmptyObject`.
  345. *
  346. * Returns true if `data` is a non-empty object, false otherwise.
  347. */
  348. function nonEmptyObject (data) {
  349. return object(data) && some(data, function () {
  350. return true;
  351. });
  352. }
  353. /**
  354. * Public function `instanceStrict`.
  355. *
  356. * Returns true if `data` is an instance of `prototype`, false otherwise.
  357. */
  358. function instanceStrict (data, prototype) {
  359. try {
  360. return data instanceof prototype;
  361. } catch (error) {
  362. return false;
  363. }
  364. }
  365. /**
  366. * Public function `instance`.
  367. *
  368. * Returns true if `data` is an instance of `prototype`, false otherwise.
  369. * Falls back to testing constructor.name and Object.prototype.toString
  370. * if the initial instanceof test fails.
  371. */
  372. function instance (data, prototype) {
  373. try {
  374. return instanceStrict(data, prototype) ||
  375. data.constructor.name === prototype.name ||
  376. Object.prototype.toString.call(data) === '[object ' + prototype.name + ']';
  377. } catch (error) {
  378. return false;
  379. }
  380. }
  381. /**
  382. * Public function `like`.
  383. *
  384. * Tests whether `data` 'quacks like a duck'. Returns true if `data` has all
  385. * of the properties of `archetype` (the 'duck'), false otherwise.
  386. */
  387. function like (data, archetype) {
  388. var name;
  389. for (name in archetype) {
  390. if (archetype.hasOwnProperty(name)) {
  391. if (data.hasOwnProperty(name) === false || typeof data[name] !== typeof archetype[name]) {
  392. return false;
  393. }
  394. if (object(data[name]) && like(data[name], archetype[name]) === false) {
  395. return false;
  396. }
  397. }
  398. }
  399. return true;
  400. }
  401. /**
  402. * Public function `array`.
  403. *
  404. * Returns true if `data` is an array, false otherwise.
  405. */
  406. function array (data) {
  407. return isArray(data);
  408. }
  409. /**
  410. * Public function `emptyArray`.
  411. *
  412. * Returns true if `data` is an empty array, false otherwise.
  413. */
  414. function emptyArray (data) {
  415. return isArray(data) && data.length === 0;
  416. }
  417. /**
  418. * Public function `nonEmptyArray`.
  419. *
  420. * Returns true if `data` is a non-empty array, false otherwise.
  421. */
  422. function nonEmptyArray (data) {
  423. return isArray(data) && data.length > 0;
  424. }
  425. /**
  426. * Public function `arrayLike`.
  427. *
  428. * Returns true if `data` is an array-like object, false otherwise.
  429. */
  430. function arrayLike (data) {
  431. return assigned(data) && data.length >= 0;
  432. }
  433. /**
  434. * Public function `iterable`.
  435. *
  436. * Returns true if `data` is an iterable, false otherwise.
  437. */
  438. function iterable (data) {
  439. if (! haveSymbols) {
  440. // Fall back to `arrayLike` predicate in pre-ES6 environments.
  441. return arrayLike(data);
  442. }
  443. return assigned(data) && isFunction(data[Symbol.iterator]);
  444. }
  445. /**
  446. * Public function `includes`.
  447. *
  448. * Returns true if `data` contains `value`, false otherwise.
  449. */
  450. function includes (data, value) {
  451. var iterator, iteration;
  452. if (! assigned(data)) {
  453. return false;
  454. }
  455. if (haveSymbols && data[Symbol.iterator] && isFunction(data.values)) {
  456. iterator = data.values();
  457. do {
  458. iteration = iterator.next();
  459. if (iteration.value === value) {
  460. return true;
  461. }
  462. } while (! iteration.done);
  463. return false;
  464. }
  465. return some(data, function (key, dataValue) {
  466. return dataValue === value;
  467. });
  468. }
  469. /**
  470. * Public function `hasLength`.
  471. *
  472. * Returns true if `data` has a length property that equals `length`, false
  473. * otherwise.
  474. */
  475. function hasLength (data, length) {
  476. return assigned(data) && data.length === length;
  477. }
  478. /**
  479. * Public function `date`.
  480. *
  481. * Returns true if `data` is a valid date, false otherwise.
  482. */
  483. function date (data) {
  484. return instanceStrict(data, Date) && integer(data.getTime());
  485. }
  486. /**
  487. * Public function `function`.
  488. *
  489. * Returns true if `data` is a function, false otherwise.
  490. */
  491. function isFunction (data) {
  492. return typeof data === 'function';
  493. }
  494. /**
  495. * Public function `map`.
  496. *
  497. * Maps each value from `data` to the corresponding predicate and returns
  498. * the results. If the same function is to be applied across all of the data,
  499. * a single predicate function may be passed in.
  500. */
  501. function map (data, predicates) {
  502. var result;
  503. if (isArray(data)) {
  504. result = [];
  505. } else {
  506. result = {};
  507. }
  508. if (isFunction(predicates)) {
  509. forEach(data, function (key, value) {
  510. result[key] = predicates(value);
  511. });
  512. } else {
  513. if (! isArray(predicates)) {
  514. assert.object(predicates);
  515. }
  516. var dataKeys = keys(data || {});
  517. forEach(predicates, function (key, predicate) {
  518. dataKeys.some(function (dataKey, index) {
  519. if (dataKey === key) {
  520. dataKeys.splice(index, 1);
  521. return true;
  522. }
  523. return false;
  524. });
  525. if (isFunction(predicate)) {
  526. if (not.assigned(data)) {
  527. result[key] = !!predicate.m;
  528. } else {
  529. result[key] = predicate(data[key]);
  530. }
  531. } else {
  532. result[key] = map(data[key], predicate);
  533. }
  534. });
  535. }
  536. return result;
  537. }
  538. function forEach (object, action) {
  539. for (var key in object) {
  540. if (object.hasOwnProperty(key)) {
  541. action(key, object[key]);
  542. }
  543. }
  544. }
  545. /**
  546. * Public function `all`
  547. *
  548. * Check that all boolean values are true
  549. * in an array or object returned from `map`.
  550. */
  551. function all (data) {
  552. if (isArray(data)) {
  553. return testArray(data, false);
  554. }
  555. assert.object(data);
  556. return testObject(data, false);
  557. }
  558. function testArray (data, result) {
  559. var i;
  560. for (i = 0; i < data.length; i += 1) {
  561. if (data[i] === result) {
  562. return result;
  563. }
  564. }
  565. return !result;
  566. }
  567. function testObject (data, result) {
  568. var key, value;
  569. for (key in data) {
  570. if (data.hasOwnProperty(key)) {
  571. value = data[key];
  572. if (object(value) && testObject(value, result) === result) {
  573. return result;
  574. }
  575. if (value === result) {
  576. return result;
  577. }
  578. }
  579. }
  580. return !result;
  581. }
  582. /**
  583. * Public function `any`
  584. *
  585. * Check that at least one boolean value is true
  586. * in an array or object returned from `map`.
  587. */
  588. function any (data) {
  589. if (isArray(data)) {
  590. return testArray(data, true);
  591. }
  592. assert.object(data);
  593. return testObject(data, true);
  594. }
  595. function mixin (target, source) {
  596. forEach(source, function (key, value) {
  597. target[key] = value;
  598. });
  599. return target;
  600. }
  601. /**
  602. * Public modifier `assert`.
  603. *
  604. * Throws if `predicate` returns false.
  605. */
  606. function assertModifier (predicate, defaultMessage) {
  607. return function () {
  608. return assertPredicate(predicate, arguments, defaultMessage);
  609. };
  610. }
  611. function assertPredicate (predicate, args, defaultMessage) {
  612. var argCount = predicate.l || predicate.length;
  613. var message = args[argCount];
  614. var ErrorType = args[argCount + 1];
  615. assertImpl(
  616. predicate.apply(null, args),
  617. nonEmptyString(message) ? message : defaultMessage,
  618. isFunction(ErrorType) ? ErrorType : TypeError
  619. );
  620. return args[0];
  621. }
  622. function assertImpl (value, message, ErrorType) {
  623. if (value) {
  624. return value;
  625. }
  626. throw new (ErrorType || Error)(message || 'Assertion failed');
  627. }
  628. /**
  629. * Public modifier `not`.
  630. *
  631. * Negates `predicate`.
  632. */
  633. function notModifier (predicate) {
  634. var modifiedPredicate = function () {
  635. return notImpl(predicate.apply(null, arguments));
  636. };
  637. modifiedPredicate.l = predicate.length;
  638. return modifiedPredicate;
  639. }
  640. function notImpl (value) {
  641. return !value;
  642. }
  643. /**
  644. * Public modifier `maybe`.
  645. *
  646. * Returns true if predicate argument is null or undefined,
  647. * otherwise propagates the return value from `predicate`.
  648. */
  649. function maybeModifier (predicate) {
  650. var modifiedPredicate = function () {
  651. if (not.assigned(arguments[0])) {
  652. return true;
  653. }
  654. return predicate.apply(null, arguments);
  655. };
  656. modifiedPredicate.l = predicate.length;
  657. // Hackishly indicate that this is a maybe.xxx predicate.
  658. // Without this flag, the alternative would be to iterate
  659. // through the maybe predicates or use indexOf to check,
  660. // which would be time-consuming.
  661. modifiedPredicate.m = true;
  662. return modifiedPredicate;
  663. }
  664. function maybeImpl (value) {
  665. if (assigned(value) === false) {
  666. return true;
  667. }
  668. return value;
  669. }
  670. /**
  671. * Public modifier `of`.
  672. *
  673. * Applies the chained predicate to members of the collection.
  674. */
  675. function ofModifier (target, type, predicate) {
  676. var modifiedPredicate = function () {
  677. var collection, args;
  678. collection = arguments[0];
  679. if (target === 'maybe' && not.assigned(collection)) {
  680. return true;
  681. }
  682. if (!type(collection)) {
  683. return false;
  684. }
  685. collection = coerceCollection(type, collection);
  686. args = slice.call(arguments, 1);
  687. try {
  688. collection.forEach(function (item) {
  689. if (
  690. (target !== 'maybe' || assigned(item)) &&
  691. !predicate.apply(null, [ item ].concat(args))
  692. ) {
  693. // TODO: Replace with for...of when ES6 is required.
  694. throw 0;
  695. }
  696. });
  697. } catch (ignore) {
  698. return false;
  699. }
  700. return true;
  701. };
  702. modifiedPredicate.l = predicate.length;
  703. return modifiedPredicate;
  704. }
  705. function coerceCollection (type, collection) {
  706. switch (type) {
  707. case arrayLike:
  708. return slice.call(collection);
  709. case object:
  710. return keys(collection).map(function (key) {
  711. return collection[key];
  712. });
  713. default:
  714. return collection;
  715. }
  716. }
  717. function createModifiedPredicates (modifier, object) {
  718. return createModifiedFunctions([ modifier, predicates, object ]);
  719. }
  720. function createModifiedFunctions (args) {
  721. var modifier, object, functions, result;
  722. modifier = args.shift();
  723. object = args.pop();
  724. functions = args.pop();
  725. result = object || {};
  726. forEach(functions, function (key, fn) {
  727. Object.defineProperty(result, key, {
  728. configurable: false,
  729. enumerable: true,
  730. writable: false,
  731. value: modifier.apply(null, args.concat(fn, messages[key]))
  732. });
  733. });
  734. return result;
  735. }
  736. function createModifiedModifier (modifier, modified) {
  737. return createModifiedFunctions([ modifier, modified, null ]);
  738. }
  739. function createOfPredicates (key) {
  740. predicates[key].of = createModifiedFunctions(
  741. [ ofModifier.bind(null, null), predicates[key], predicates, null ]
  742. );
  743. }
  744. function createOfModifiers (base, modifier) {
  745. collections.forEach(function (key) {
  746. base[key].of = createModifiedModifier(modifier, predicates[key].of);
  747. });
  748. }
  749. function createMaybeOfModifiers (key) {
  750. maybe[key].of = createModifiedFunctions(
  751. [ ofModifier.bind(null, 'maybe'), predicates[key], predicates, null ]
  752. );
  753. assert.maybe[key].of = createModifiedModifier(assertModifier, maybe[key].of);
  754. assert.not[key].of = createModifiedModifier(assertModifier, not[key].of);
  755. }
  756. function exportFunctions (functions) {
  757. if (typeof define === 'function' && define.amd) {
  758. define(function () {
  759. return functions;
  760. });
  761. } else if (typeof module !== 'undefined' && module !== null && module.exports) {
  762. module.exports = functions;
  763. } else {
  764. globals.check = functions;
  765. }
  766. }
  767. }(this));