values.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict';
  2. var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol';
  3. var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } };
  4. var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } };
  5. var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } };
  6. var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } };
  7. var objects = [{}, coercibleObject, toStringOnlyObject, valueOfOnlyObject];
  8. var nullPrimitives = [undefined, null];
  9. var nonIntegerNumbers = [-1.3, 0.2, 1.8, 1 / 3];
  10. var numbers = [0, -0, Infinity, -Infinity, 42];
  11. var strings = ['', 'foo'];
  12. var booleans = [true, false];
  13. var symbols = hasSymbols ? [Symbol.iterator, Symbol('foo')] : [];
  14. var nonSymbolPrimitives = [].concat(nullPrimitives, booleans, strings, numbers);
  15. var nonNumberPrimitives = [].concat(nullPrimitives, booleans, strings, symbols);
  16. var nonNullPrimitives = [].concat(booleans, strings, numbers, symbols);
  17. var nonUndefinedPrimitives = [].concat(null, nonNullPrimitives);
  18. var nonStrings = [].concat(nullPrimitives, booleans, numbers, symbols, objects);
  19. var primitives = [].concat(nullPrimitives, nonNullPrimitives);
  20. var nonPropertyKeys = [].concat(nullPrimitives, booleans, numbers, objects);
  21. var propertyKeys = [].concat(strings, symbols);
  22. var nonBooleans = [].concat(nullPrimitives, strings, symbols, numbers, objects);
  23. var falsies = [].concat(nullPrimitives, false, '', 0, -0, NaN);
  24. var truthies = [].concat(true, 'foo', 42, symbols, objects);
  25. module.exports = {
  26. coercibleObject: coercibleObject,
  27. valueOfOnlyObject: valueOfOnlyObject,
  28. toStringOnlyObject: toStringOnlyObject,
  29. uncoercibleObject: uncoercibleObject,
  30. objects: objects,
  31. nullPrimitives: nullPrimitives,
  32. numbers: numbers,
  33. strings: strings,
  34. booleans: booleans,
  35. symbols: symbols,
  36. hasSymbols: hasSymbols,
  37. nonSymbolPrimitives: nonSymbolPrimitives,
  38. nonNumberPrimitives: nonNumberPrimitives,
  39. nonNullPrimitives: nonNullPrimitives,
  40. nonUndefinedPrimitives: nonUndefinedPrimitives,
  41. nonStrings: nonStrings,
  42. nonNumbers: nonNumberPrimitives.concat(objects),
  43. nonIntegerNumbers: nonIntegerNumbers,
  44. primitives: primitives,
  45. nonPropertyKeys: nonPropertyKeys,
  46. propertyKeys: propertyKeys,
  47. nonBooleans: nonBooleans,
  48. falsies: falsies,
  49. truthies: truthies
  50. };