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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js +46 -23
- data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +8 -2
- data/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js +101 -21
- data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +9 -2
- data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +0 -1
- data/app/assets/stylesheets/govuk_publishing_components/components/_button.scss +4 -6
- data/app/assets/stylesheets/govuk_publishing_components/components/_cookie-banner.scss +36 -5
- data/app/assets/stylesheets/govuk_publishing_components/components/_heading.scss +14 -14
- data/app/assets/stylesheets/govuk_publishing_components/components/_highlight-boxes.scss +23 -23
- data/app/assets/stylesheets/govuk_publishing_components/components/_inverse-header.scss +8 -8
- data/app/assets/stylesheets/govuk_publishing_components/components/_lead-paragraph.scss +2 -2
- data/app/assets/stylesheets/govuk_publishing_components/components/_metadata.scss +8 -8
- data/app/assets/stylesheets/govuk_publishing_components/components/_organisation-logo.scss +10 -10
- data/app/assets/stylesheets/govuk_publishing_components/components/_previous-and-next-navigation.scss +11 -14
- data/app/assets/stylesheets/govuk_publishing_components/components/_related-navigation.scss +14 -14
- data/app/assets/stylesheets/govuk_publishing_components/components/_share-links.scss +8 -8
- data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-header.scss +7 -7
- data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav-related.scss +20 -16
- data/app/assets/stylesheets/govuk_publishing_components/components/_subscription-links.scss +4 -4
- data/app/assets/stylesheets/govuk_publishing_components/components/_success-alert.scss +5 -5
- data/app/assets/stylesheets/govuk_publishing_components/components/_taxonomy-list.scss +5 -5
- data/app/assets/stylesheets/govuk_publishing_components/components/_title.scss +8 -8
- data/app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav-header.scss +1 -1
- data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +33 -25
- data/app/views/govuk_publishing_components/components/_error_summary.html.erb +4 -2
- data/app/views/govuk_publishing_components/components/_notice.html.erb +4 -1
- data/app/views/govuk_publishing_components/components/docs/cookie_banner.yml +2 -0
- data/app/views/govuk_publishing_components/components/docs/error_summary.yml +6 -0
- data/app/views/govuk_publishing_components/components/docs/notice.yml +6 -0
- data/app/views/govuk_publishing_components/components/docs/success_alert.yml +1 -1
- data/lib/govuk_publishing_components/presenters/cookie_banner_helper.rb +0 -4
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.js +1 -1
- data/node_modules/accessible-autocomplete/dist/accessible-autocomplete.min.js.map +1 -1
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.preact.min.js +1 -1
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.preact.min.js.map +1 -1
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.react.min.js +1 -1
- data/node_modules/accessible-autocomplete/dist/lib/accessible-autocomplete.react.min.js.map +1 -1
- data/node_modules/accessible-autocomplete/package.json +3 -3
- data/node_modules/accessible-autocomplete/src/autocomplete.js +4 -2
- data/node_modules/accessible-autocomplete/src/wrapper.js +5 -1
- data/node_modules/d/CHANGELOG.md +9 -0
- data/node_modules/d/CHANGES +4 -0
- data/node_modules/d/LICENSE +12 -16
- data/node_modules/d/README.md +49 -19
- data/node_modules/d/auto-bind.js +11 -10
- data/node_modules/d/index.js +23 -24
- data/node_modules/d/lazy.js +21 -23
- data/node_modules/d/package.json +63 -16
- data/node_modules/d/test/auto-bind.js +6 -7
- data/node_modules/d/test/index.js +78 -51
- data/node_modules/d/test/lazy.js +65 -50
- data/node_modules/es6-weak-map/CHANGELOG.md +5 -0
- data/node_modules/es6-weak-map/LICENSE +12 -16
- data/node_modules/es6-weak-map/README.md +34 -19
- data/node_modules/es6-weak-map/implement.js +9 -5
- data/node_modules/es6-weak-map/index.js +2 -2
- data/node_modules/es6-weak-map/is-implemented.js +10 -9
- data/node_modules/es6-weak-map/is-native-implemented.js +3 -3
- data/node_modules/es6-weak-map/is-weak-map.js +8 -8
- data/node_modules/es6-weak-map/package.json +30 -19
- data/node_modules/es6-weak-map/polyfill.js +31 -32
- data/node_modules/es6-weak-map/test/implement.js +4 -2
- data/node_modules/es6-weak-map/test/index.js +4 -3
- data/node_modules/es6-weak-map/test/is-implemented.js +9 -8
- data/node_modules/es6-weak-map/test/is-native-implemented.js +4 -2
- data/node_modules/es6-weak-map/test/is-weak-map.js +4 -4
- data/node_modules/es6-weak-map/test/polyfill.js +13 -13
- data/node_modules/es6-weak-map/test/valid-weak-map.js +22 -9
- data/node_modules/es6-weak-map/valid-weak-map.js +5 -5
- data/node_modules/resolve/lib/async.js +1 -1
- data/node_modules/resolve/lib/node-modules-paths.js +1 -1
- data/node_modules/resolve/lib/sync.js +0 -2
- data/node_modules/resolve/package.json +13 -13
- data/node_modules/resolve/test/node-modules-paths.js +0 -22
- data/node_modules/resolve/test/resolver.js +11 -0
- data/node_modules/resolve/test/resolver_sync.js +11 -0
- data/node_modules/standard/node_modules/ms/index.js +2 -2
- data/node_modules/standard/node_modules/ms/package.json +205 -16
- data/node_modules/standard/node_modules/ms/readme.md +1 -1
- data/node_modules/type/CHANGELOG.md +62 -0
- data/node_modules/type/README.md +743 -0
- data/node_modules/type/array-length/coerce.js +10 -0
- data/node_modules/type/array-length/ensure.js +10 -0
- data/node_modules/type/array-like/ensure.js +9 -0
- data/node_modules/type/array-like/is.js +21 -0
- data/node_modules/type/array/ensure.js +9 -0
- data/node_modules/type/array/is.js +27 -0
- data/node_modules/type/date/ensure.js +9 -0
- data/node_modules/type/date/is.js +26 -0
- data/node_modules/type/error/ensure.js +9 -0
- data/node_modules/type/error/is.js +24 -0
- data/node_modules/type/finite/coerce.js +8 -0
- data/node_modules/type/finite/ensure.js +10 -0
- data/node_modules/type/function/ensure.js +9 -0
- data/node_modules/type/function/is.js +19 -0
- data/node_modules/type/integer/coerce.js +11 -0
- data/node_modules/type/integer/ensure.js +10 -0
- data/node_modules/type/iterable/ensure.js +9 -0
- data/node_modules/type/iterable/is.js +20 -0
- data/node_modules/type/lib/is-to-string-tag-supported.js +3 -0
- data/node_modules/type/lib/resolve-exception.js +21 -0
- data/node_modules/type/lib/safe-to-string.js +10 -0
- data/node_modules/type/lib/to-short-string.js +29 -0
- data/node_modules/type/natural-number/coerce.js +10 -0
- data/node_modules/type/natural-number/ensure.js +10 -0
- data/node_modules/type/number/coerce.js +14 -0
- data/node_modules/type/number/ensure.js +10 -0
- data/node_modules/type/object/ensure.js +9 -0
- data/node_modules/type/object/is.js +11 -0
- data/node_modules/type/package.json +159 -0
- data/node_modules/type/plain-function/ensure.js +9 -0
- data/node_modules/type/plain-function/is.js +11 -0
- data/node_modules/type/plain-object/ensure.js +9 -0
- data/node_modules/type/plain-object/is.js +28 -0
- data/node_modules/type/promise/ensure.js +9 -0
- data/node_modules/type/promise/is.js +27 -0
- data/node_modules/type/prototype/is.js +13 -0
- data/node_modules/type/reg-exp/ensure.js +9 -0
- data/node_modules/type/reg-exp/is.js +37 -0
- data/node_modules/type/safe-integer/coerce.js +13 -0
- data/node_modules/type/safe-integer/ensure.js +10 -0
- data/node_modules/type/string/coerce.js +23 -0
- data/node_modules/type/string/ensure.js +10 -0
- data/node_modules/type/test/_lib/arrow-function-if-supported.js +4 -0
- data/node_modules/type/test/_lib/class-if-supported.js +4 -0
- data/node_modules/type/test/array-length/coerce.js +47 -0
- data/node_modules/type/test/array-length/ensure.js +19 -0
- data/node_modules/type/test/array-like/ensure.js +24 -0
- data/node_modules/type/test/array-like/is.js +47 -0
- data/node_modules/type/test/array/ensure.js +20 -0
- data/node_modules/type/test/array/is.js +41 -0
- data/node_modules/type/test/date/ensure.js +20 -0
- data/node_modules/type/test/date/is.js +46 -0
- data/node_modules/type/test/error/ensure.js +20 -0
- data/node_modules/type/test/error/is.js +42 -0
- data/node_modules/type/test/finite/coerce.js +40 -0
- data/node_modules/type/test/finite/ensure.js +17 -0
- data/node_modules/type/test/function/ensure.js +20 -0
- data/node_modules/type/test/function/is.js +46 -0
- data/node_modules/type/test/integer/coerce.js +49 -0
- data/node_modules/type/test/integer/ensure.js +17 -0
- data/node_modules/type/test/iterable/ensure.js +24 -0
- data/node_modules/type/test/iterable/is.js +50 -0
- data/node_modules/type/test/lib/is-to-string-tag-supported.js +10 -0
- data/node_modules/type/test/lib/resolve-exception.js +39 -0
- data/node_modules/type/test/lib/safe-to-string.js +32 -0
- data/node_modules/type/test/lib/to-short-string.js +41 -0
- data/node_modules/type/test/natural-number/coerce.js +47 -0
- data/node_modules/type/test/natural-number/ensure.js +19 -0
- data/node_modules/type/test/number/coerce.js +40 -0
- data/node_modules/type/test/number/ensure.js +17 -0
- data/node_modules/type/test/object/ensure.js +20 -0
- data/node_modules/type/test/object/is.js +30 -0
- data/node_modules/type/test/plain-function/ensure.js +20 -0
- data/node_modules/type/test/plain-function/is.js +56 -0
- data/node_modules/type/test/plain-object/ensure.js +20 -0
- data/node_modules/type/test/plain-object/is.js +47 -0
- data/node_modules/type/test/promise/ensure.js +20 -0
- data/node_modules/type/test/promise/is.js +39 -0
- data/node_modules/type/test/prototype/is.js +39 -0
- data/node_modules/type/test/reg-exp/ensure.js +20 -0
- data/node_modules/type/test/reg-exp/is.js +47 -0
- data/node_modules/type/test/safe-integer/coerce.js +49 -0
- data/node_modules/type/test/safe-integer/ensure.js +19 -0
- data/node_modules/type/test/string/coerce.js +36 -0
- data/node_modules/type/test/string/ensure.js +17 -0
- data/node_modules/type/test/thenable/ensure.js +20 -0
- data/node_modules/type/test/thenable/is.js +44 -0
- data/node_modules/type/test/time-value/coerce.js +47 -0
- data/node_modules/type/test/time-value/ensure.js +17 -0
- data/node_modules/type/test/value/ensure.js +20 -0
- data/node_modules/type/test/value/is.js +29 -0
- data/node_modules/type/thenable/ensure.js +9 -0
- data/node_modules/type/thenable/is.js +9 -0
- data/node_modules/type/time-value/coerce.js +12 -0
- data/node_modules/type/time-value/ensure.js +10 -0
- data/node_modules/type/value/ensure.js +9 -0
- data/node_modules/type/value/is.js +6 -0
- metadata +118 -21
- data/app/assets/stylesheets/govuk_publishing_components/components/_taxonomy-navigation.scss +0 -94
- data/node_modules/resolve/reaf +0 -0
- data/node_modules/resolve/test/shadowed_core.js +0 -38
- data/node_modules/resolve/test/shadowed_core/node_modules/util/index.js +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var resolveException = require("../lib/resolve-exception")
|
|
4
|
+
, is = require("./is");
|
|
5
|
+
|
|
6
|
+
module.exports = function (value/*, options*/) {
|
|
7
|
+
if (is(value)) return value;
|
|
8
|
+
return resolveException(value, "%v is not a plain function", arguments[1]);
|
|
9
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var isFunction = require("../function/is");
|
|
4
|
+
|
|
5
|
+
var classRe = /^\s*class[\s{/}]/, functionToString = Function.prototype.toString;
|
|
6
|
+
|
|
7
|
+
module.exports = function (value) {
|
|
8
|
+
if (!isFunction(value)) return false;
|
|
9
|
+
if (classRe.test(functionToString.call(value))) return false;
|
|
10
|
+
return true;
|
|
11
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var resolveException = require("../lib/resolve-exception")
|
|
4
|
+
, is = require("./is");
|
|
5
|
+
|
|
6
|
+
module.exports = function (value/*, options*/) {
|
|
7
|
+
if (is(value)) return value;
|
|
8
|
+
return resolveException(value, "%v is not a plain object", arguments[1]);
|
|
9
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var isObject = require("../object/is")
|
|
4
|
+
, isPrototype = require("../prototype/is");
|
|
5
|
+
|
|
6
|
+
var getPrototypeOf;
|
|
7
|
+
if (typeof Object.getPrototypeOf === "function") {
|
|
8
|
+
getPrototypeOf = Object.getPrototypeOf;
|
|
9
|
+
} else if ({}.__proto__ === Object.prototype) {
|
|
10
|
+
getPrototypeOf = function (object) { return object.__proto__; };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = function (value) {
|
|
14
|
+
if (!isObject(value)) return false;
|
|
15
|
+
var prototype;
|
|
16
|
+
if (getPrototypeOf) {
|
|
17
|
+
prototype = getPrototypeOf(value);
|
|
18
|
+
} else {
|
|
19
|
+
try {
|
|
20
|
+
var valueConstructor = value.constructor;
|
|
21
|
+
if (valueConstructor) prototype = valueConstructor.prototype;
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (prototype && !hasOwnProperty.call(prototype, "propertyIsEnumerable")) return false;
|
|
27
|
+
return !isPrototype(value);
|
|
28
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var isPrototype = require("../prototype/is");
|
|
4
|
+
|
|
5
|
+
// In theory we could rely on Symbol.toStringTag directly,
|
|
6
|
+
// still early native implementation (e.g. in FF) predated symbols
|
|
7
|
+
var objectToString = Object.prototype.toString
|
|
8
|
+
, objectTaggedString = objectToString.call(Promise.resolve());
|
|
9
|
+
|
|
10
|
+
module.exports = function (value) {
|
|
11
|
+
if (!value) return false;
|
|
12
|
+
|
|
13
|
+
// Sanity check (reject objects which do not expose common Promise interface)
|
|
14
|
+
try {
|
|
15
|
+
if (typeof value.then !== "function") return false;
|
|
16
|
+
if (typeof value["catch"] !== "function") return false;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Ensure its native Promise object (has [[PromiseState]] slot)
|
|
22
|
+
// Note: it's not 100% precise as string tag may be overriden
|
|
23
|
+
// and other objects could be hacked to expose it
|
|
24
|
+
if (objectToString.call(value) !== objectTaggedString) return false;
|
|
25
|
+
|
|
26
|
+
return !isPrototype(value);
|
|
27
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var isObject = require("../object/is");
|
|
4
|
+
|
|
5
|
+
module.exports = function (value) {
|
|
6
|
+
if (!isObject(value)) return false;
|
|
7
|
+
try {
|
|
8
|
+
if (!value.constructor) return false;
|
|
9
|
+
return value.constructor.prototype === value;
|
|
10
|
+
} catch (error) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var resolveException = require("../lib/resolve-exception")
|
|
4
|
+
, is = require("./is");
|
|
5
|
+
|
|
6
|
+
module.exports = function (value/*, options*/) {
|
|
7
|
+
if (is(value)) return value;
|
|
8
|
+
return resolveException(value, "%v is not a regular expression object", arguments[1]);
|
|
9
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var isToStringTagSupported = require("../lib/is-to-string-tag-supported")
|
|
4
|
+
, isPrototype = require("../prototype/is");
|
|
5
|
+
|
|
6
|
+
var regExpTest = RegExp.prototype.test
|
|
7
|
+
, objectToString = Object.prototype.toString
|
|
8
|
+
, objectTaggedString = objectToString.call(/a/);
|
|
9
|
+
|
|
10
|
+
module.exports = function (value) {
|
|
11
|
+
if (!value) return false;
|
|
12
|
+
|
|
13
|
+
// Sanity check (reject objects which do not expose common RegExp interface)
|
|
14
|
+
if (!hasOwnProperty.call(value, "lastIndex")) return false;
|
|
15
|
+
try {
|
|
16
|
+
if (typeof value.lastIndex !== "number") return false;
|
|
17
|
+
if (typeof value.test !== "function") return false;
|
|
18
|
+
if (typeof value.exec !== "function") return false;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Ensure its native RegExp object (has [[RegExpMatcher]] slot)
|
|
24
|
+
if (isToStringTagSupported && typeof value[Symbol.toStringTag] === "string") {
|
|
25
|
+
// Edge case (possibly a regExp with custom Symbol.toStringTag)
|
|
26
|
+
try {
|
|
27
|
+
var lastIndex = value.lastIndex;
|
|
28
|
+
regExpTest.call(value, "");
|
|
29
|
+
if (value.lastIndex !== lastIndex) value.lastIndex = lastIndex;
|
|
30
|
+
return true;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (objectToString.call(value) !== objectTaggedString) return false;
|
|
36
|
+
return !isPrototype(value);
|
|
37
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var coerceToInteger = require("../integer/coerce");
|
|
4
|
+
|
|
5
|
+
var MAX_SAFE_INTEGER = 9007199254740991, MIN_SAFE_INTEGER = -9007199254740991;
|
|
6
|
+
|
|
7
|
+
module.exports = function (value) {
|
|
8
|
+
value = coerceToInteger(value);
|
|
9
|
+
if (!value) return value;
|
|
10
|
+
if (value > MAX_SAFE_INTEGER) return null;
|
|
11
|
+
if (value < MIN_SAFE_INTEGER) return null;
|
|
12
|
+
return value;
|
|
13
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var resolveException = require("../lib/resolve-exception")
|
|
4
|
+
, coerce = require("./coerce");
|
|
5
|
+
|
|
6
|
+
module.exports = function (value/*, options*/) {
|
|
7
|
+
var coerced = coerce(value);
|
|
8
|
+
if (coerced !== null) return coerced;
|
|
9
|
+
return resolveException(value, "%v is not a safe integer", arguments[1]);
|
|
10
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var isValue = require("../value/is")
|
|
4
|
+
, isObject = require("../object/is");
|
|
5
|
+
|
|
6
|
+
var objectToString = Object.prototype.toString;
|
|
7
|
+
|
|
8
|
+
module.exports = function (value) {
|
|
9
|
+
if (!isValue(value)) return null;
|
|
10
|
+
if (isObject(value)) {
|
|
11
|
+
// Reject Object.prototype.toString coercion
|
|
12
|
+
var valueToString = value.toString;
|
|
13
|
+
if (typeof valueToString !== "function") return null;
|
|
14
|
+
if (valueToString === objectToString) return null;
|
|
15
|
+
// Note: It can be object coming from other realm, still as there's no ES3 and CSP compliant
|
|
16
|
+
// way to resolve its realm's Object.prototype.toString it's left as not addressed edge case
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return "" + value; // Ensure implicit coercion
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var resolveException = require("../lib/resolve-exception")
|
|
4
|
+
, coerce = require("./coerce");
|
|
5
|
+
|
|
6
|
+
module.exports = function (value/*, options*/) {
|
|
7
|
+
var coerced = coerce(value);
|
|
8
|
+
if (coerced !== null) return coerced;
|
|
9
|
+
return resolveException(value, "%v is not a string", arguments[1]);
|
|
10
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var assert = require("chai").assert
|
|
4
|
+
, coerceToArrayLength = require("../../array-length/coerce");
|
|
5
|
+
|
|
6
|
+
describe("array-length/coerce", function () {
|
|
7
|
+
it("Should coerce float", function () {
|
|
8
|
+
assert.equal(coerceToArrayLength(123.123), 123);
|
|
9
|
+
assert.equal(coerceToArrayLength(123.823), 123);
|
|
10
|
+
});
|
|
11
|
+
it("Should coerce string", function () { assert.equal(coerceToArrayLength("12.123"), 12); });
|
|
12
|
+
it("Should coerce booleans", function () { assert.equal(coerceToArrayLength(true), 1); });
|
|
13
|
+
it("Should coerce number objects", function () {
|
|
14
|
+
assert.equal(coerceToArrayLength(new Number(343)), 343);
|
|
15
|
+
});
|
|
16
|
+
it("Should coerce objects", function () {
|
|
17
|
+
assert.equal(coerceToArrayLength({ valueOf: function () { return 23; } }), 23);
|
|
18
|
+
});
|
|
19
|
+
it("Should reject infinite number", function () {
|
|
20
|
+
assert.equal(coerceToArrayLength(Infinity), null);
|
|
21
|
+
});
|
|
22
|
+
it("Should reject number beyond Number.MAX_SAFE_INTEGER", function () {
|
|
23
|
+
assert.equal(coerceToArrayLength(9007199254740992), null);
|
|
24
|
+
});
|
|
25
|
+
it("Should reject negative number", function () {
|
|
26
|
+
assert.equal(coerceToArrayLength(-9), null);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("Should reject NaN", function () { assert.equal(coerceToArrayLength(NaN), null); });
|
|
30
|
+
|
|
31
|
+
if (typeof Object.create === "function") {
|
|
32
|
+
it("Should not coerce objects with no number representation", function () {
|
|
33
|
+
assert.equal(coerceToArrayLength(Object.create(null)), null);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
it("Should not coerce null", function () { assert.equal(coerceToArrayLength(null), null); });
|
|
38
|
+
it("Should not coerce undefined", function () {
|
|
39
|
+
assert.equal(coerceToArrayLength(undefined), null);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (typeof Symbol === "function") {
|
|
43
|
+
it("Should not coerce symbols", function () {
|
|
44
|
+
assert.equal(coerceToArrayLength(Symbol("foo")), null);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var assert = require("chai").assert
|
|
4
|
+
, ensureArrayLength = require("../../array-length/ensure");
|
|
5
|
+
|
|
6
|
+
describe("array-length/ensure", function () {
|
|
7
|
+
it("Should return coerced value", function () {
|
|
8
|
+
assert.equal(ensureArrayLength("12.23"), 12);
|
|
9
|
+
});
|
|
10
|
+
it("Should crash on no value", function () {
|
|
11
|
+
try {
|
|
12
|
+
ensureArrayLength(-20);
|
|
13
|
+
throw new Error("Unexpected");
|
|
14
|
+
} catch (error) {
|
|
15
|
+
assert.equal(error.name, "TypeError");
|
|
16
|
+
assert.equal(error.message, "-20 is not a valid array length");
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var assert = require("chai").assert
|
|
4
|
+
, ensureArrayLike = require("../../array-like/ensure");
|
|
5
|
+
|
|
6
|
+
describe("array-like/ensure", function () {
|
|
7
|
+
it("Should return input value", function () {
|
|
8
|
+
var value = [];
|
|
9
|
+
assert.equal(ensureArrayLike(value), value);
|
|
10
|
+
});
|
|
11
|
+
it("Should allow strings with allowString option", function () {
|
|
12
|
+
var value = "foo";
|
|
13
|
+
assert.equal(ensureArrayLike(value, { allowString: true }), value);
|
|
14
|
+
});
|
|
15
|
+
it("Should crash on invalid value", function () {
|
|
16
|
+
try {
|
|
17
|
+
ensureArrayLike("foo");
|
|
18
|
+
throw new Error("Unexpected");
|
|
19
|
+
} catch (error) {
|
|
20
|
+
assert.equal(error.name, "TypeError");
|
|
21
|
+
assert(error.message.includes("is not an array like value"));
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var assert = require("chai").assert
|
|
4
|
+
, isArrayLike = require("../../array-like/is");
|
|
5
|
+
|
|
6
|
+
describe("array-like/is", function () {
|
|
7
|
+
it("Should return true on array", function () { assert.equal(isArrayLike([]), true); });
|
|
8
|
+
it("Should return true on array-like object", function () {
|
|
9
|
+
assert.equal(isArrayLike({ length: 1 }), true);
|
|
10
|
+
});
|
|
11
|
+
it("Should by default return false on string", function () {
|
|
12
|
+
assert.equal(isArrayLike("foo"), false);
|
|
13
|
+
});
|
|
14
|
+
it("Should accept strings if specified", function () {
|
|
15
|
+
assert.equal(isArrayLike("foo", { allowString: true }), true);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("Should return false on objects with negative length", function () {
|
|
19
|
+
assert.equal(isArrayLike({ length: -1 }), false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("Should return false on plain object", function () {
|
|
23
|
+
assert.equal(isArrayLike({}), false);
|
|
24
|
+
});
|
|
25
|
+
it("Should return false on function", function () {
|
|
26
|
+
assert.equal(isArrayLike(function () { return true; }), false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
if (typeof Object.create === "function") {
|
|
30
|
+
it("Should return false on object with no prototype", function () {
|
|
31
|
+
assert.equal(isArrayLike(Object.create(null)), false);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
it("Should return false on number", function () { assert.equal(isArrayLike(123), false); });
|
|
35
|
+
it("Should return false on NaN", function () { assert.equal(isArrayLike(NaN), false); });
|
|
36
|
+
it("Should return false on boolean", function () { assert.equal(isArrayLike(true), false); });
|
|
37
|
+
if (typeof Symbol === "function") {
|
|
38
|
+
it("Should return false on symbol", function () {
|
|
39
|
+
assert.equal(isArrayLike(Symbol("foo")), false);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
it("Should return false on null", function () { assert.equal(isArrayLike(null), false); });
|
|
44
|
+
it("Should return false on undefined", function () {
|
|
45
|
+
assert.equal(isArrayLike(void 0), false);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var assert = require("chai").assert
|
|
4
|
+
, ensureArray = require("../../array/ensure");
|
|
5
|
+
|
|
6
|
+
describe("array/ensure", function () {
|
|
7
|
+
it("Should return input value", function () {
|
|
8
|
+
var value = [];
|
|
9
|
+
assert.equal(ensureArray(value), value);
|
|
10
|
+
});
|
|
11
|
+
it("Should crash on invalid value", function () {
|
|
12
|
+
try {
|
|
13
|
+
ensureArray(null);
|
|
14
|
+
throw new Error("Unexpected");
|
|
15
|
+
} catch (error) {
|
|
16
|
+
assert.equal(error.name, "TypeError");
|
|
17
|
+
assert(error.message.includes("is not an array object"));
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var assert = require("chai").assert
|
|
4
|
+
, isArray = require("../../array/is");
|
|
5
|
+
|
|
6
|
+
describe("array/is", function () {
|
|
7
|
+
it("Should return true on array", function () { assert.equal(isArray([]), true); });
|
|
8
|
+
|
|
9
|
+
it("Should return false on array with no common API exposed", function () {
|
|
10
|
+
var value = [];
|
|
11
|
+
value.push = null;
|
|
12
|
+
assert.equal(isArray(value), false);
|
|
13
|
+
});
|
|
14
|
+
it("Should return false on Array.prototype", function () {
|
|
15
|
+
assert.equal(isArray(Array.prototype), false);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("Should return false on plain object", function () { assert.equal(isArray({}), false); });
|
|
19
|
+
it("Should return false on function", function () {
|
|
20
|
+
assert.equal(isArray(function () { return true; }), false);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (typeof Object.create === "function") {
|
|
24
|
+
it("Should return false on object with no prototype", function () {
|
|
25
|
+
assert.equal(isArray(Object.create(null)), false);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
it("Should return false on string", function () { assert.equal(isArray("foo"), false); });
|
|
29
|
+
it("Should return false on empty string", function () { assert.equal(isArray(""), false); });
|
|
30
|
+
it("Should return false on number", function () { assert.equal(isArray(123), false); });
|
|
31
|
+
it("Should return false on NaN", function () { assert.equal(isArray(NaN), false); });
|
|
32
|
+
it("Should return false on boolean", function () { assert.equal(isArray(true), false); });
|
|
33
|
+
if (typeof Symbol === "function") {
|
|
34
|
+
it("Should return false on symbol", function () {
|
|
35
|
+
assert.equal(isArray(Symbol("foo")), false);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
it("Should return false on null", function () { assert.equal(isArray(null), false); });
|
|
40
|
+
it("Should return false on undefined", function () { assert.equal(isArray(void 0), false); });
|
|
41
|
+
});
|