index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**!
  2. * enable - index.js
  3. *
  4. * Copyright(c) 2014 fengmk2 and other contributors.
  5. * MIT Licensed
  6. *
  7. * Authors:
  8. * fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
  9. * dead_horse <dead_horse@qq.com> (http://github.com/dead-horse)
  10. * hemanth.hm <hemanth.hm@gmail.com> (http://h3manth.com)
  11. */
  12. 'use strict';
  13. /**
  14. * Helper functions.
  15. */
  16. function isFunction(attr) {
  17. return typeof attr === 'function';
  18. }
  19. function isNumber(attr) {
  20. return typeof attr === 'number';
  21. }
  22. /**
  23. * Module dependencies.
  24. */
  25. // generator
  26. try {
  27. eval('(function* () {})()');
  28. exports.generator = true;
  29. } catch (_) {
  30. exports.generator = false;
  31. }
  32. // let
  33. try {
  34. eval('let a = 1;');
  35. exports.let = true;
  36. } catch (_) {
  37. exports.let = false;
  38. }
  39. // const
  40. try {
  41. eval('(function () { const fubar = 42; return typeof fubar === "number"; }())');
  42. exports.const = true;
  43. } catch (_) {
  44. exports.const = false;
  45. }
  46. // Object.{is,assign,getOwnPropertySymbols,setPrototypeOf}
  47. exports.Object = {
  48. is: isFunction(Object.is),
  49. assign: isFunction(Object.assign),
  50. getOwnPropertySymbols: isFunction(Object.getOwnPropertySymbols),
  51. setPrototypeOf: isFunction(Object.setPrototypeOf)
  52. };
  53. // String methods.
  54. exports.String = {
  55. raw: isFunction(String.raw),
  56. fromCodePoint: isFunction(String.fromCodePoint),
  57. prototype:{
  58. codePointAt: isFunction(String.prototype.codePointAt),
  59. normalize: isFunction(String.prototype.normalize),
  60. repeat: isFunction(String.prototype.repeat),
  61. startsWith: isFunction(String.prototype.startsWith),
  62. endsWith: isFunction(String.prototype.endsWith),
  63. contains: isFunction(String.prototype.contains)
  64. }
  65. };
  66. exports.Number = {
  67. isFinite: isFunction(Number.isFinite),
  68. isInteger: isFunction(Number.isInteger),
  69. isSafeInteger: isFunction(Number.isSafeInteger),
  70. isNaN: isFunction(Number.isNaN),
  71. EPSILON: isNumber(Number.EPSILON),
  72. MIN_SAFE_INTEGER: isNumber(Number.MIN_SAFE_INTEGER),
  73. MAX_SAFE_INTEGER: isNumber(Number.MAX_SAFE_INTEGER)
  74. };
  75. exports.Math = {
  76. clz32: isFunction(Math.clz32),
  77. imul: isFunction(Math.imul),
  78. sign: isFunction(Math.sign),
  79. log10: isFunction(Math.log10),
  80. log2: isFunction(Math.log2),
  81. log1p: isFunction(Math.log1p),
  82. expm1: isFunction(Math.expm1),
  83. cosh: isFunction(Math.cosh),
  84. sinh: isFunction(Math.sinh),
  85. tanh: isFunction(Math.tanh),
  86. acosh: isFunction(Math.acosh),
  87. asinh: isFunction(Math.asinh),
  88. atanh: isFunction(Math.atanh),
  89. hypot: isFunction(Math.hypot),
  90. trunc: isFunction(Math.trunc),
  91. fround: isFunction(Math.fround),
  92. cbrt: isFunction(Math.cbrt)
  93. }