govuk_publishing_components 16.29.0 → 17.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js +46 -23
  3. data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +8 -2
  4. data/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js +101 -21
  5. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +9 -2
  6. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +0 -1
  7. data/app/assets/stylesheets/govuk_publishing_components/components/_button.scss +4 -6
  8. data/app/assets/stylesheets/govuk_publishing_components/components/_cookie-banner.scss +36 -5
  9. data/app/assets/stylesheets/govuk_publishing_components/components/_heading.scss +14 -14
  10. data/app/assets/stylesheets/govuk_publishing_components/components/_highlight-boxes.scss +23 -23
  11. data/app/assets/stylesheets/govuk_publishing_components/components/_inverse-header.scss +8 -8
  12. data/app/assets/stylesheets/govuk_publishing_components/components/_lead-paragraph.scss +2 -2
  13. data/app/assets/stylesheets/govuk_publishing_components/components/_metadata.scss +8 -8
  14. data/app/assets/stylesheets/govuk_publishing_components/components/_organisation-logo.scss +10 -10
  15. data/app/assets/stylesheets/govuk_publishing_components/components/_previous-and-next-navigation.scss +11 -14
  16. data/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss +14 -14
  17. data/app/assets/stylesheets/govuk_publishing_components/components/_share-links.scss +8 -8
  18. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss +7 -7
  19. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss +20 -16
  20. data/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss +4 -4
  21. data/app/assets/stylesheets/govuk_publishing_components/components/_success-alert.scss +5 -5
  22. data/app/assets/stylesheets/govuk_publishing_components/components/_taxonomy-list.scss +5 -5
  23. data/app/assets/stylesheets/govuk_publishing_components/components/_title.scss +8 -8
  24. data/app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav-header.scss +1 -1
  25. data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +33 -25
  26. data/app/views/govuk_publishing_components/components/_error_summary.html.erb +4 -2
  27. data/app/views/govuk_publishing_components/components/_notice.html.erb +4 -1
  28. data/app/views/govuk_publishing_components/components/docs/cookie_banner.yml +2 -0
  29. data/app/views/govuk_publishing_components/components/docs/error_summary.yml +6 -0
  30. data/app/views/govuk_publishing_components/components/docs/notice.yml +6 -0
  31. data/app/views/govuk_publishing_components/components/docs/success_alert.yml +1 -1
  32. data/lib/govuk_publishing_components/presenters/cookie_banner_helper.rb +0 -4
  33. data/lib/govuk_publishing_components/version.rb +1 -1
  34. data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.js +1 -1
  35. data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.js.map +1 -1
  36. data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.preact.min.js +1 -1
  37. data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.preact.min.js.map +1 -1
  38. data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.react.min.js +1 -1
  39. data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.react.min.js.map +1 -1
  40. data/node_modules/accessible-autocomplete/package.json +3 -3
  41. data/node_modules/accessible-autocomplete/src/autocomplete.js +4 -2
  42. data/node_modules/accessible-autocomplete/src/wrapper.js +5 -1
  43. data/node_modules/d/CHANGELOG.md +9 -0
  44. data/node_modules/d/CHANGES +4 -0
  45. data/node_modules/d/LICENSE +12 -16
  46. data/node_modules/d/README.md +49 -19
  47. data/node_modules/d/auto-bind.js +11 -10
  48. data/node_modules/d/index.js +23 -24
  49. data/node_modules/d/lazy.js +21 -23
  50. data/node_modules/d/package.json +63 -16
  51. data/node_modules/d/test/auto-bind.js +6 -7
  52. data/node_modules/d/test/index.js +78 -51
  53. data/node_modules/d/test/lazy.js +65 -50
  54. data/node_modules/es6-weak-map/CHANGELOG.md +5 -0
  55. data/node_modules/es6-weak-map/LICENSE +12 -16
  56. data/node_modules/es6-weak-map/README.md +34 -19
  57. data/node_modules/es6-weak-map/implement.js +9 -5
  58. data/node_modules/es6-weak-map/index.js +2 -2
  59. data/node_modules/es6-weak-map/is-implemented.js +10 -9
  60. data/node_modules/es6-weak-map/is-native-implemented.js +3 -3
  61. data/node_modules/es6-weak-map/is-weak-map.js +8 -8
  62. data/node_modules/es6-weak-map/package.json +30 -19
  63. data/node_modules/es6-weak-map/polyfill.js +31 -32
  64. data/node_modules/es6-weak-map/test/implement.js +4 -2
  65. data/node_modules/es6-weak-map/test/index.js +4 -3
  66. data/node_modules/es6-weak-map/test/is-implemented.js +9 -8
  67. data/node_modules/es6-weak-map/test/is-native-implemented.js +4 -2
  68. data/node_modules/es6-weak-map/test/is-weak-map.js +4 -4
  69. data/node_modules/es6-weak-map/test/polyfill.js +13 -13
  70. data/node_modules/es6-weak-map/test/valid-weak-map.js +22 -9
  71. data/node_modules/es6-weak-map/valid-weak-map.js +5 -5
  72. data/node_modules/resolve/lib/async.js +1 -1
  73. data/node_modules/resolve/lib/node-modules-paths.js +1 -1
  74. data/node_modules/resolve/lib/sync.js +0 -2
  75. data/node_modules/resolve/package.json +13 -13
  76. data/node_modules/resolve/test/node-modules-paths.js +0 -22
  77. data/node_modules/resolve/test/resolver.js +11 -0
  78. data/node_modules/resolve/test/resolver_sync.js +11 -0
  79. data/node_modules/standard/node_modules/ms/index.js +2 -2
  80. data/node_modules/standard/node_modules/ms/package.json +205 -16
  81. data/node_modules/standard/node_modules/ms/readme.md +1 -1
  82. data/node_modules/type/CHANGELOG.md +62 -0
  83. data/node_modules/type/README.md +743 -0
  84. data/node_modules/type/array-length/coerce.js +10 -0
  85. data/node_modules/type/array-length/ensure.js +10 -0
  86. data/node_modules/type/array-like/ensure.js +9 -0
  87. data/node_modules/type/array-like/is.js +21 -0
  88. data/node_modules/type/array/ensure.js +9 -0
  89. data/node_modules/type/array/is.js +27 -0
  90. data/node_modules/type/date/ensure.js +9 -0
  91. data/node_modules/type/date/is.js +26 -0
  92. data/node_modules/type/error/ensure.js +9 -0
  93. data/node_modules/type/error/is.js +24 -0
  94. data/node_modules/type/finite/coerce.js +8 -0
  95. data/node_modules/type/finite/ensure.js +10 -0
  96. data/node_modules/type/function/ensure.js +9 -0
  97. data/node_modules/type/function/is.js +19 -0
  98. data/node_modules/type/integer/coerce.js +11 -0
  99. data/node_modules/type/integer/ensure.js +10 -0
  100. data/node_modules/type/iterable/ensure.js +9 -0
  101. data/node_modules/type/iterable/is.js +20 -0
  102. data/node_modules/type/lib/is-to-string-tag-supported.js +3 -0
  103. data/node_modules/type/lib/resolve-exception.js +21 -0
  104. data/node_modules/type/lib/safe-to-string.js +10 -0
  105. data/node_modules/type/lib/to-short-string.js +29 -0
  106. data/node_modules/type/natural-number/coerce.js +10 -0
  107. data/node_modules/type/natural-number/ensure.js +10 -0
  108. data/node_modules/type/number/coerce.js +14 -0
  109. data/node_modules/type/number/ensure.js +10 -0
  110. data/node_modules/type/object/ensure.js +9 -0
  111. data/node_modules/type/object/is.js +11 -0
  112. data/node_modules/type/package.json +159 -0
  113. data/node_modules/type/plain-function/ensure.js +9 -0
  114. data/node_modules/type/plain-function/is.js +11 -0
  115. data/node_modules/type/plain-object/ensure.js +9 -0
  116. data/node_modules/type/plain-object/is.js +28 -0
  117. data/node_modules/type/promise/ensure.js +9 -0
  118. data/node_modules/type/promise/is.js +27 -0
  119. data/node_modules/type/prototype/is.js +13 -0
  120. data/node_modules/type/reg-exp/ensure.js +9 -0
  121. data/node_modules/type/reg-exp/is.js +37 -0
  122. data/node_modules/type/safe-integer/coerce.js +13 -0
  123. data/node_modules/type/safe-integer/ensure.js +10 -0
  124. data/node_modules/type/string/coerce.js +23 -0
  125. data/node_modules/type/string/ensure.js +10 -0
  126. data/node_modules/type/test/_lib/arrow-function-if-supported.js +4 -0
  127. data/node_modules/type/test/_lib/class-if-supported.js +4 -0
  128. data/node_modules/type/test/array-length/coerce.js +47 -0
  129. data/node_modules/type/test/array-length/ensure.js +19 -0
  130. data/node_modules/type/test/array-like/ensure.js +24 -0
  131. data/node_modules/type/test/array-like/is.js +47 -0
  132. data/node_modules/type/test/array/ensure.js +20 -0
  133. data/node_modules/type/test/array/is.js +41 -0
  134. data/node_modules/type/test/date/ensure.js +20 -0
  135. data/node_modules/type/test/date/is.js +46 -0
  136. data/node_modules/type/test/error/ensure.js +20 -0
  137. data/node_modules/type/test/error/is.js +42 -0
  138. data/node_modules/type/test/finite/coerce.js +40 -0
  139. data/node_modules/type/test/finite/ensure.js +17 -0
  140. data/node_modules/type/test/function/ensure.js +20 -0
  141. data/node_modules/type/test/function/is.js +46 -0
  142. data/node_modules/type/test/integer/coerce.js +49 -0
  143. data/node_modules/type/test/integer/ensure.js +17 -0
  144. data/node_modules/type/test/iterable/ensure.js +24 -0
  145. data/node_modules/type/test/iterable/is.js +50 -0
  146. data/node_modules/type/test/lib/is-to-string-tag-supported.js +10 -0
  147. data/node_modules/type/test/lib/resolve-exception.js +39 -0
  148. data/node_modules/type/test/lib/safe-to-string.js +32 -0
  149. data/node_modules/type/test/lib/to-short-string.js +41 -0
  150. data/node_modules/type/test/natural-number/coerce.js +47 -0
  151. data/node_modules/type/test/natural-number/ensure.js +19 -0
  152. data/node_modules/type/test/number/coerce.js +40 -0
  153. data/node_modules/type/test/number/ensure.js +17 -0
  154. data/node_modules/type/test/object/ensure.js +20 -0
  155. data/node_modules/type/test/object/is.js +30 -0
  156. data/node_modules/type/test/plain-function/ensure.js +20 -0
  157. data/node_modules/type/test/plain-function/is.js +56 -0
  158. data/node_modules/type/test/plain-object/ensure.js +20 -0
  159. data/node_modules/type/test/plain-object/is.js +47 -0
  160. data/node_modules/type/test/promise/ensure.js +20 -0
  161. data/node_modules/type/test/promise/is.js +39 -0
  162. data/node_modules/type/test/prototype/is.js +39 -0
  163. data/node_modules/type/test/reg-exp/ensure.js +20 -0
  164. data/node_modules/type/test/reg-exp/is.js +47 -0
  165. data/node_modules/type/test/safe-integer/coerce.js +49 -0
  166. data/node_modules/type/test/safe-integer/ensure.js +19 -0
  167. data/node_modules/type/test/string/coerce.js +36 -0
  168. data/node_modules/type/test/string/ensure.js +17 -0
  169. data/node_modules/type/test/thenable/ensure.js +20 -0
  170. data/node_modules/type/test/thenable/is.js +44 -0
  171. data/node_modules/type/test/time-value/coerce.js +47 -0
  172. data/node_modules/type/test/time-value/ensure.js +17 -0
  173. data/node_modules/type/test/value/ensure.js +20 -0
  174. data/node_modules/type/test/value/is.js +29 -0
  175. data/node_modules/type/thenable/ensure.js +9 -0
  176. data/node_modules/type/thenable/is.js +9 -0
  177. data/node_modules/type/time-value/coerce.js +12 -0
  178. data/node_modules/type/time-value/ensure.js +10 -0
  179. data/node_modules/type/value/ensure.js +9 -0
  180. data/node_modules/type/value/is.js +6 -0
  181. metadata +118 -21
  182. data/app/assets/stylesheets/govuk_publishing_components/components/_taxonomy-navigation.scss +0 -94
  183. data/node_modules/resolve/reaf +0 -0
  184. data/node_modules/resolve/test/shadowed_core.js +0 -38
  185. data/node_modules/resolve/test/shadowed_core/node_modules/util/index.js +0 -0
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , ensureDate = require("../../date/ensure");
5
+
6
+ describe("date/ensure", function () {
7
+ it("Should return input value", function () {
8
+ var value = new Date();
9
+ assert.equal(ensureDate(value), value);
10
+ });
11
+ it("Should crash on invalid value", function () {
12
+ try {
13
+ ensureDate(null);
14
+ throw new Error("Unexpected");
15
+ } catch (error) {
16
+ assert.equal(error.name, "TypeError");
17
+ assert(error.message.includes("is not a date object"));
18
+ }
19
+ });
20
+ });
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , isDate = require("../../date/is");
5
+
6
+ describe("date/is", function () {
7
+ it("Should return true on date", function () { assert.equal(isDate(new Date()), true); });
8
+ it("Should return false on invalid date", function () {
9
+ assert.equal(isDate(new Date("foo")), false);
10
+ });
11
+
12
+ it("Should return false on native date with no common API exposed", function () {
13
+ var value = new Date();
14
+ value.getFullYear = null;
15
+ assert.equal(isDate(value), false);
16
+ });
17
+ it("Should return false on Date.prototype", function () {
18
+ assert.equal(isDate(Date.prototype), false);
19
+ });
20
+ it("Should return false on time value", function () { assert.equal(isDate(12312313), false); });
21
+
22
+ it("Should return false on plain object", function () { assert.equal(isDate({}), false); });
23
+ it("Should return false on function", function () {
24
+ assert.equal(isDate(function () { return true; }), false);
25
+ });
26
+
27
+ it("Should return false on array", function () { assert.equal(isDate([]), false); });
28
+ if (typeof Object.create === "function") {
29
+ it("Should return false on object with no prototype", function () {
30
+ assert.equal(isDate(Object.create(null)), false);
31
+ });
32
+ }
33
+ it("Should return false on string", function () { assert.equal(isDate("foo"), false); });
34
+ it("Should return false on empty string", function () { assert.equal(isDate(""), false); });
35
+ it("Should return false on number", function () { assert.equal(isDate(123), false); });
36
+ it("Should return false on NaN", function () { assert.equal(isDate(NaN), false); });
37
+ it("Should return false on boolean", function () { assert.equal(isDate(true), false); });
38
+ if (typeof Symbol === "function") {
39
+ it("Should return false on symbol", function () {
40
+ assert.equal(isDate(Symbol("foo")), false);
41
+ });
42
+ }
43
+
44
+ it("Should return false on null", function () { assert.equal(isDate(null), false); });
45
+ it("Should return false on undefined", function () { assert.equal(isDate(void 0), false); });
46
+ });
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , ensureError = require("../../error/ensure");
5
+
6
+ describe("error/ensure", function () {
7
+ it("Should return input value", function () {
8
+ var value = new Error();
9
+ assert.equal(ensureError(value), value);
10
+ });
11
+ it("Should crash on invalid value", function () {
12
+ try {
13
+ ensureError(null);
14
+ throw new Error("Unexpected");
15
+ } catch (error) {
16
+ assert.equal(error.name, "TypeError");
17
+ assert(error.message.includes("is not an error object"));
18
+ }
19
+ });
20
+ });
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , isError = require("../../error/is");
5
+
6
+ describe("error/is", function () {
7
+ it("Should return true on error", function () { assert.equal(isError(new Error()), true); });
8
+
9
+ it("Should return false on native error with no common API exposed", function () {
10
+ var value = new Error();
11
+ value.message = null;
12
+ assert.equal(isError(value), false);
13
+ });
14
+ it("Should return false on Error.prototype", function () {
15
+ assert.equal(isError(Error.prototype), false);
16
+ });
17
+
18
+ it("Should return false on plain object", function () { assert.equal(isError({}), false); });
19
+ it("Should return false on function", function () {
20
+ assert.equal(isError(function () { return true; }), false);
21
+ });
22
+
23
+ it("Should return false on array", function () { assert.equal(isError([]), false); });
24
+ if (typeof Object.create === "function") {
25
+ it("Should return false on object with no prototype", function () {
26
+ assert.equal(isError(Object.create(null)), false);
27
+ });
28
+ }
29
+ it("Should return false on string", function () { assert.equal(isError("foo"), false); });
30
+ it("Should return false on empty string", function () { assert.equal(isError(""), false); });
31
+ it("Should return false on number", function () { assert.equal(isError(123), false); });
32
+ it("Should return false on NaN", function () { assert.equal(isError(NaN), false); });
33
+ it("Should return false on boolean", function () { assert.equal(isError(true), false); });
34
+ if (typeof Symbol === "function") {
35
+ it("Should return false on symbol", function () {
36
+ assert.equal(isError(Symbol("foo")), false);
37
+ });
38
+ }
39
+
40
+ it("Should return false on null", function () { assert.equal(isError(null), false); });
41
+ it("Should return false on undefined", function () { assert.equal(isError(void 0), false); });
42
+ });
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , coerceToFinite = require("../../finite/coerce");
5
+
6
+ describe("finite/coerce", function () {
7
+ it("Should return input number", function () {
8
+ assert.equal(coerceToFinite(123.123), 123.123);
9
+ });
10
+ it("Should coerce string", function () { assert.equal(coerceToFinite("12"), 12); });
11
+ it("Should coerce booleans", function () { assert.equal(coerceToFinite(true), 1); });
12
+ it("Should coerce number objects", function () {
13
+ assert.equal(coerceToFinite(new Number(343)), 343);
14
+ });
15
+ it("Should coerce objects", function () {
16
+ assert.equal(coerceToFinite({ valueOf: function () { return 23; } }), 23);
17
+ });
18
+
19
+ it("Should reject infinite number", function () {
20
+ assert.equal(coerceToFinite(Infinity), null);
21
+ });
22
+ it("Should reject NaN", function () { assert.equal(coerceToFinite(NaN), null); });
23
+
24
+ if (typeof Object.create === "function") {
25
+ it("Should not coerce objects with no number representation", function () {
26
+ assert.equal(coerceToFinite(Object.create(null)), null);
27
+ });
28
+ }
29
+
30
+ it("Should not coerce null", function () { assert.equal(coerceToFinite(null), null); });
31
+ it("Should not coerce undefined", function () {
32
+ assert.equal(coerceToFinite(undefined), null);
33
+ });
34
+
35
+ if (typeof Symbol === "function") {
36
+ it("Should not coerce symbols", function () {
37
+ assert.equal(coerceToFinite(Symbol("foo")), null);
38
+ });
39
+ }
40
+ });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , ensureFinite = require("../../finite/ensure");
5
+
6
+ describe("finite/ensure", function () {
7
+ it("Should return coerced value", function () { assert.equal(ensureFinite("12.23"), 12.23); });
8
+ it("Should crash on no value", function () {
9
+ try {
10
+ ensureFinite(null);
11
+ throw new Error("Unexpected");
12
+ } catch (error) {
13
+ assert.equal(error.name, "TypeError");
14
+ assert.equal(error.message, "null is not a finite number");
15
+ }
16
+ });
17
+ });
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , ensureFunction = require("../../function/ensure");
5
+
6
+ describe("function/ensure", function () {
7
+ it("Should return input value", function () {
8
+ var value = function () { return true; };
9
+ assert.equal(ensureFunction(value), value);
10
+ });
11
+ it("Should crash on invalid value", function () {
12
+ try {
13
+ ensureFunction(null);
14
+ throw new Error("Unexpected");
15
+ } catch (error) {
16
+ assert.equal(error.name, "TypeError");
17
+ assert(error.message.includes("is not a function"));
18
+ }
19
+ });
20
+ });
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , isFunction = require("../../function/is")
5
+ , arrowFunctionIfSupported = require("../_lib/arrow-function-if-supported")
6
+ , classIfSupported = require("../_lib/class-if-supported");
7
+
8
+ describe("function/is", function () {
9
+ it("Should return true on function", function () {
10
+ assert.equal(isFunction(function () { return true; }), true);
11
+ });
12
+ if (arrowFunctionIfSupported) {
13
+ it("Should return true on arrow function", function () {
14
+ assert.equal(isFunction(arrowFunctionIfSupported), true);
15
+ });
16
+ }
17
+ if (classIfSupported) {
18
+ it("Should return true on class", function () {
19
+ assert.equal(isFunction(classIfSupported), true);
20
+ });
21
+ }
22
+ it("Should return false on reg-exp", function () { assert.equal(isFunction(/foo/), false); });
23
+
24
+ it("Should return false on plain object", function () { assert.equal(isFunction({}), false); });
25
+ it("Should return false on array", function () { assert.equal(isFunction([]), false); });
26
+ if (typeof Object.create === "function") {
27
+ it("Should return false on object with no prototype", function () {
28
+ assert.equal(isFunction(Object.create(null)), false);
29
+ });
30
+ }
31
+ it("Should return false on string", function () { assert.equal(isFunction("foo"), false); });
32
+ it("Should return false on empty string", function () { assert.equal(isFunction(""), false); });
33
+ it("Should return false on number", function () { assert.equal(isFunction(123), false); });
34
+ it("Should return false on NaN", function () { assert.equal(isFunction(NaN), false); });
35
+ it("Should return false on boolean", function () { assert.equal(isFunction(true), false); });
36
+ if (typeof Symbol === "function") {
37
+ it("Should return false on symbol", function () {
38
+ assert.equal(isFunction(Symbol("foo")), false);
39
+ });
40
+ }
41
+
42
+ it("Should return false on null", function () { assert.equal(isFunction(null), false); });
43
+ it("Should return false on undefined", function () {
44
+ assert.equal(isFunction(void 0), false);
45
+ });
46
+ });
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , coerceToInteger = require("../../integer/coerce");
5
+
6
+ describe("integer/coerce", function () {
7
+ it("Should coerce float to integer", function () {
8
+ assert.equal(coerceToInteger(123.123), 123);
9
+ assert.equal(coerceToInteger(123.823), 123);
10
+ assert.equal(coerceToInteger(-123.123), -123);
11
+ assert.equal(coerceToInteger(-123.823), -123);
12
+ });
13
+ it("Should coerce string", function () { assert.equal(coerceToInteger("12.123"), 12); });
14
+ it("Should coerce booleans", function () { assert.equal(coerceToInteger(true), 1); });
15
+ it("Should coerce number objects", function () {
16
+ assert.equal(coerceToInteger(new Number(343)), 343);
17
+ });
18
+ it("Should coerce objects", function () {
19
+ assert.equal(coerceToInteger({ valueOf: function () { return 23; } }), 23);
20
+ });
21
+ it("Should coerce number beyond Number.MAX_SAFE_INTEGER", function () {
22
+ assert.equal(coerceToInteger(9007199254740992), 9007199254740992);
23
+ });
24
+ it("Should coerce number beyond Number.MIN_SAFE_INTEGER", function () {
25
+ assert.equal(coerceToInteger(-9007199254740992), -9007199254740992);
26
+ });
27
+
28
+ it("Should reject infinite number", function () {
29
+ assert.equal(coerceToInteger(Infinity), null);
30
+ });
31
+ it("Should reject NaN", function () { assert.equal(coerceToInteger(NaN), null); });
32
+
33
+ if (typeof Object.create === "function") {
34
+ it("Should not coerce objects with no number representation", function () {
35
+ assert.equal(coerceToInteger(Object.create(null)), null);
36
+ });
37
+ }
38
+
39
+ it("Should not coerce null", function () { assert.equal(coerceToInteger(null), null); });
40
+ it("Should not coerce undefined", function () {
41
+ assert.equal(coerceToInteger(undefined), null);
42
+ });
43
+
44
+ if (typeof Symbol === "function") {
45
+ it("Should not coerce symbols", function () {
46
+ assert.equal(coerceToInteger(Symbol("foo")), null);
47
+ });
48
+ }
49
+ });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , ensureInteger = require("../../integer/ensure");
5
+
6
+ describe("integer/ensure", function () {
7
+ it("Should return coerced value", function () { assert.equal(ensureInteger("12.23"), 12); });
8
+ it("Should crash on no value", function () {
9
+ try {
10
+ ensureInteger(null);
11
+ throw new Error("Unexpected");
12
+ } catch (error) {
13
+ assert.equal(error.name, "TypeError");
14
+ assert.equal(error.message, "null is not an integer");
15
+ }
16
+ });
17
+ });
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , ensureIterable = require("../../iterable/ensure");
5
+
6
+ describe("iterable/ensure", function () {
7
+ it("Should return input value", function () {
8
+ var value = [];
9
+ assert.equal(ensureIterable(value), value);
10
+ });
11
+ it("Should allow strings with allowString option", function () {
12
+ var value = "foo";
13
+ assert.equal(ensureIterable(value, { allowString: true }), value);
14
+ });
15
+ it("Should crash on invalid value", function () {
16
+ try {
17
+ ensureIterable("foo");
18
+ throw new Error("Unexpected");
19
+ } catch (error) {
20
+ assert.equal(error.name, "TypeError");
21
+ assert(error.message.includes("is not an iterable value"));
22
+ }
23
+ });
24
+ });
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , isIterable = require("../../iterable/is");
5
+
6
+ describe("iterable/is", function () {
7
+ it("Should return true on array", function () { assert.equal(isIterable([]), true); });
8
+ it("Should return true on arguments", function () {
9
+ assert.equal(isIterable((function () { return arguments; })()), true);
10
+ });
11
+ it("Should by default return false on string", function () {
12
+ assert.equal(isIterable("foo"), false);
13
+ });
14
+ it("Should accept strings if specified", function () {
15
+ assert.equal(isIterable("foo", { allowString: true }), true);
16
+ });
17
+
18
+ if (typeof Set === "function") {
19
+ it("Should return true on set", function () { assert.equal(isIterable(new Set()), true); });
20
+ }
21
+ if (typeof Map === "function") {
22
+ it("Should return true on set", function () { assert.equal(isIterable(new Map()), true); });
23
+ }
24
+
25
+ it("Should return false on plain object", function () { assert.equal(isIterable({}), false); });
26
+ it("Should return false on function", function () {
27
+ assert.equal(isIterable(function () { return true; }), false);
28
+ });
29
+
30
+ if (typeof Object.create === "function") {
31
+ it("Should return false on object with no prototype", function () {
32
+ assert.equal(isIterable(Object.create(null)), false);
33
+ });
34
+ }
35
+ it("Should return false on string", function () { assert.equal(isIterable("foo"), false); });
36
+ it("Should return false on empty string", function () { assert.equal(isIterable(""), false); });
37
+ it("Should return false on number", function () { assert.equal(isIterable(123), false); });
38
+ it("Should return false on NaN", function () { assert.equal(isIterable(NaN), false); });
39
+ it("Should return false on boolean", function () { assert.equal(isIterable(true), false); });
40
+ if (typeof Symbol === "function") {
41
+ it("Should return false on symbol", function () {
42
+ assert.equal(isIterable(Symbol("foo")), false);
43
+ });
44
+ }
45
+
46
+ it("Should return false on null", function () { assert.equal(isIterable(null), false); });
47
+ it("Should return false on undefined", function () {
48
+ assert.equal(isIterable(void 0), false);
49
+ });
50
+ });
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , isToStringTagSupported = require("../../lib/is-to-string-tag-supported");
5
+
6
+ describe("lib/is-to-string-tag-supported", function () {
7
+ it("Should return boolean", function () {
8
+ assert(typeof isToStringTagSupported === "boolean");
9
+ });
10
+ });
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var assert = require("chai").assert
4
+ , handleException = require("../../lib/resolve-exception");
5
+
6
+ describe("lib/handle-exception", function () {
7
+ it("Should throw TypeError", function () {
8
+ try {
9
+ handleException(12, "Invalid value");
10
+ throw new Error("Unexpected");
11
+ } catch (error) {
12
+ assert.equal(error.name, "TypeError");
13
+ assert.equal(error.message, "Invalid value");
14
+ }
15
+ });
16
+ it("Should resolve value in default message", function () {
17
+ try {
18
+ handleException(12, "%v is invalid", {});
19
+ throw new Error("Unexpected");
20
+ } catch (error) {
21
+ assert.equal(error.message, "12 is invalid");
22
+ }
23
+ });
24
+ it("Should support optional values via inputOptions.isOptional", function () {
25
+ assert.equal(handleException(null, "%v is invalid", { isOptional: true }, null));
26
+ });
27
+ it("Should support optional values via inputOptions.default", function () {
28
+ // prettier-ignore
29
+ assert.equal(handleException(null, "%v is invalid", { "default": "bar" }), "bar");
30
+ });
31
+ it("Should support custome error message via inputOptions.errorMessage", function () {
32
+ try {
33
+ handleException(null, "%v is invalid", { errorMessage: "%v is not supported age" });
34
+ throw new Error("Unexpected");
35
+ } catch (error) {
36
+ assert.equal(error.message, "null is not supported age");
37
+ }
38
+ });
39
+ });