UNPKG

p5.js-svg

Version:

The main goal of p5.SVG is to provide a SVG runtime for p5.js, so that we can draw using p5's powerful API in \<svg\>, save things to svg file and manipulating existing SVG file without rasterization.

1,699 lines (1,507 loc) 467 kB
(function () { 'use strict'; var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function getDefaultExportFromCjs (x) { return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } function getAugmentedNamespace(n) { if (n.__esModule) return n; var f = n.default; if (typeof f == "function") { var a = function a () { if (this instanceof a) { var args = [null]; args.push.apply(args, arguments); var Ctor = Function.bind.apply(f, args); return new Ctor(); } return f.apply(this, arguments); }; a.prototype = f.prototype; } else a = {}; Object.defineProperty(a, '__esModule', {value: true}); Object.keys(n).forEach(function (k) { var d = Object.getOwnPropertyDescriptor(n, k); Object.defineProperty(a, k, d.get ? d : { enumerable: true, get: function () { return n[k]; } }); }); return a; } var unit = {}; var chai$2 = {}; /*! * assertion-error * Copyright(c) 2013 Jake Luer <jake@qualiancy.com> * MIT Licensed */ /*! * Return a function that will copy properties from * one object to another excluding any originally * listed. Returned function will create a new `{}`. * * @param {String} excluded properties ... * @return {Function} */ function exclude () { var excludes = [].slice.call(arguments); function excludeProps (res, obj) { Object.keys(obj).forEach(function (key) { if (!~excludes.indexOf(key)) res[key] = obj[key]; }); } return function extendExclude () { var args = [].slice.call(arguments) , i = 0 , res = {}; for (; i < args.length; i++) { excludeProps(res, args[i]); } return res; }; } /*! * Primary Exports */ var assertionError = AssertionError$1; /** * ### AssertionError * * An extension of the JavaScript `Error` constructor for * assertion and validation scenarios. * * @param {String} message * @param {Object} properties to include (optional) * @param {callee} start stack function (optional) */ function AssertionError$1 (message, _props, ssf) { var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON') , props = extend(_props || {}); // default values this.message = message || 'Unspecified AssertionError'; this.showDiff = false; // copy from properties for (var key in props) { this[key] = props[key]; } // capture stack trace ssf = ssf || AssertionError$1; if (Error.captureStackTrace) { Error.captureStackTrace(this, ssf); } else { try { throw new Error(); } catch(e) { this.stack = e.stack; } } } /*! * Inherit from Error.prototype */ AssertionError$1.prototype = Object.create(Error.prototype); /*! * Statically set name */ AssertionError$1.prototype.name = 'AssertionError'; /*! * Ensure correct constructor */ AssertionError$1.prototype.constructor = AssertionError$1; /** * Allow errors to be converted to JSON for static transfer. * * @param {Boolean} include stack (default: `true`) * @return {Object} object that can be `JSON.stringify` */ AssertionError$1.prototype.toJSON = function (stack) { var extend = exclude('constructor', 'toJSON', 'stack') , props = extend({ name: this.name }, this); // include stack if exists and not turned off if (false !== stack && this.stack) { props.stack = this.stack; } return props; }; var utils$1 = {}; /* ! * Chai - pathval utility * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com> * @see https://github.com/logicalparadox/filtr * MIT Licensed */ /** * ### .hasProperty(object, name) * * This allows checking whether an object has own * or inherited from prototype chain named property. * * Basically does the same thing as the `in` * operator but works properly with null/undefined values * and other primitives. * * var obj = { * arr: ['a', 'b', 'c'] * , str: 'Hello' * } * * The following would be the results. * * hasProperty(obj, 'str'); // true * hasProperty(obj, 'constructor'); // true * hasProperty(obj, 'bar'); // false * * hasProperty(obj.str, 'length'); // true * hasProperty(obj.str, 1); // true * hasProperty(obj.str, 5); // false * * hasProperty(obj.arr, 'length'); // true * hasProperty(obj.arr, 2); // true * hasProperty(obj.arr, 3); // false * * @param {Object} object * @param {String|Symbol} name * @returns {Boolean} whether it exists * @namespace Utils * @name hasProperty * @api public */ function hasProperty(obj, name) { if (typeof obj === 'undefined' || obj === null) { return false; } // The `in` operator does not work with primitives. return name in Object(obj); } /* ! * ## parsePath(path) * * Helper function used to parse string object * paths. Use in conjunction with `internalGetPathValue`. * * var parsed = parsePath('myobject.property.subprop'); * * ### Paths: * * * Can be infinitely deep and nested. * * Arrays are also valid using the formal `myobject.document[3].property`. * * Literal dots and brackets (not delimiter) must be backslash-escaped. * * @param {String} path * @returns {Object} parsed * @api private */ function parsePath(path) { var str = path.replace(/([^\\])\[/g, '$1.['); var parts = str.match(/(\\\.|[^.]+?)+/g); return parts.map(function mapMatches(value) { if ( value === 'constructor' || value === '__proto__' || value === 'prototype' ) { return {}; } var regexp = /^\[(\d+)\]$/; var mArr = regexp.exec(value); var parsed = null; if (mArr) { parsed = { i: parseFloat(mArr[1]) }; } else { parsed = { p: value.replace(/\\([.[\]])/g, '$1') }; } return parsed; }); } /* ! * ## internalGetPathValue(obj, parsed[, pathDepth]) * * Helper companion function for `.parsePath` that returns * the value located at the parsed address. * * var value = getPathValue(obj, parsed); * * @param {Object} object to search against * @param {Object} parsed definition from `parsePath`. * @param {Number} depth (nesting level) of the property we want to retrieve * @returns {Object|Undefined} value * @api private */ function internalGetPathValue(obj, parsed, pathDepth) { var temporaryValue = obj; var res = null; pathDepth = typeof pathDepth === 'undefined' ? parsed.length : pathDepth; for (var i = 0; i < pathDepth; i++) { var part = parsed[i]; if (temporaryValue) { if (typeof part.p === 'undefined') { temporaryValue = temporaryValue[part.i]; } else { temporaryValue = temporaryValue[part.p]; } if (i === pathDepth - 1) { res = temporaryValue; } } } return res; } /* ! * ## internalSetPathValue(obj, value, parsed) * * Companion function for `parsePath` that sets * the value located at a parsed address. * * internalSetPathValue(obj, 'value', parsed); * * @param {Object} object to search and define on * @param {*} value to use upon set * @param {Object} parsed definition from `parsePath` * @api private */ function internalSetPathValue(obj, val, parsed) { var tempObj = obj; var pathDepth = parsed.length; var part = null; // Here we iterate through every part of the path for (var i = 0; i < pathDepth; i++) { var propName = null; var propVal = null; part = parsed[i]; // If it's the last part of the path, we set the 'propName' value with the property name if (i === pathDepth - 1) { propName = typeof part.p === 'undefined' ? part.i : part.p; // Now we set the property with the name held by 'propName' on object with the desired val tempObj[propName] = val; } else if (typeof part.p !== 'undefined' && tempObj[part.p]) { tempObj = tempObj[part.p]; } else if (typeof part.i !== 'undefined' && tempObj[part.i]) { tempObj = tempObj[part.i]; } else { // If the obj doesn't have the property we create one with that name to define it var next = parsed[i + 1]; // Here we set the name of the property which will be defined propName = typeof part.p === 'undefined' ? part.i : part.p; // Here we decide if this property will be an array or a new object propVal = typeof next.p === 'undefined' ? [] : {}; tempObj[propName] = propVal; tempObj = tempObj[propName]; } } } /** * ### .getPathInfo(object, path) * * This allows the retrieval of property info in an * object given a string path. * * The path info consists of an object with the * following properties: * * * parent - The parent object of the property referenced by `path` * * name - The name of the final property, a number if it was an array indexer * * value - The value of the property, if it exists, otherwise `undefined` * * exists - Whether the property exists or not * * @param {Object} object * @param {String} path * @returns {Object} info * @namespace Utils * @name getPathInfo * @api public */ function getPathInfo(obj, path) { var parsed = parsePath(path); var last = parsed[parsed.length - 1]; var info = { parent: parsed.length > 1 ? internalGetPathValue(obj, parsed, parsed.length - 1) : obj, name: last.p || last.i, value: internalGetPathValue(obj, parsed), }; info.exists = hasProperty(info.parent, info.name); return info; } /** * ### .getPathValue(object, path) * * This allows the retrieval of values in an * object given a string path. * * var obj = { * prop1: { * arr: ['a', 'b', 'c'] * , str: 'Hello' * } * , prop2: { * arr: [ { nested: 'Universe' } ] * , str: 'Hello again!' * } * } * * The following would be the results. * * getPathValue(obj, 'prop1.str'); // Hello * getPathValue(obj, 'prop1.att[2]'); // b * getPathValue(obj, 'prop2.arr[0].nested'); // Universe * * @param {Object} object * @param {String} path * @returns {Object} value or `undefined` * @namespace Utils * @name getPathValue * @api public */ function getPathValue(obj, path) { var info = getPathInfo(obj, path); return info.value; } /** * ### .setPathValue(object, path, value) * * Define the value in an object at a given string path. * * ```js * var obj = { * prop1: { * arr: ['a', 'b', 'c'] * , str: 'Hello' * } * , prop2: { * arr: [ { nested: 'Universe' } ] * , str: 'Hello again!' * } * }; * ``` * * The following would be acceptable. * * ```js * var properties = require('tea-properties'); * properties.set(obj, 'prop1.str', 'Hello Universe!'); * properties.set(obj, 'prop1.arr[2]', 'B'); * properties.set(obj, 'prop2.arr[0].nested.value', { hello: 'universe' }); * ``` * * @param {Object} object * @param {String} path * @param {Mixed} value * @api private */ function setPathValue(obj, path, val) { var parsed = parsePath(path); internalSetPathValue(obj, val, parsed); return obj; } var pathval = { hasProperty: hasProperty, getPathInfo: getPathInfo, getPathValue: getPathValue, setPathValue: setPathValue, }; /*! * Chai - flag utility * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ /** * ### .flag(object, key, [value]) * * Get or set a flag value on an object. If a * value is provided it will be set, else it will * return the currently set value or `undefined` if * the value is not set. * * utils.flag(this, 'foo', 'bar'); // setter * utils.flag(this, 'foo'); // getter, returns `bar` * * @param {Object} object constructed Assertion * @param {String} key * @param {Mixed} value (optional) * @namespace Utils * @name flag * @api private */ var flag$5 = function flag(obj, key, value) { var flags = obj.__flags || (obj.__flags = Object.create(null)); if (arguments.length === 3) { flags[key] = value; } else { return flags[key]; } }; /*! * Chai - test utility * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ /*! * Module dependencies */ var flag$4 = flag$5; /** * ### .test(object, expression) * * Test an object for expression. * * @param {Object} object (constructed Assertion) * @param {Arguments} chai.Assertion.prototype.assert arguments * @namespace Utils * @name test */ var test$1 = function test(obj, args) { var negate = flag$4(obj, 'negate') , expr = args[0]; return negate ? !expr : expr; }; var typeDetect = {exports: {}}; (function (module, exports) { (function (global, factory) { module.exports = factory() ; })(commonjsGlobal, (function () { var promiseExists = typeof Promise === 'function'; var globalObject = (function (Obj) { if (typeof globalThis === 'object') { return globalThis; } Object.defineProperty(Obj, 'typeDetectGlobalObject', { get: function get() { return this; }, configurable: true, }); var global = typeDetectGlobalObject; delete Obj.typeDetectGlobalObject; return global; })(Object.prototype); var symbolExists = typeof Symbol !== 'undefined'; var mapExists = typeof Map !== 'undefined'; var setExists = typeof Set !== 'undefined'; var weakMapExists = typeof WeakMap !== 'undefined'; var weakSetExists = typeof WeakSet !== 'undefined'; var dataViewExists = typeof DataView !== 'undefined'; var symbolIteratorExists = symbolExists && typeof Symbol.iterator !== 'undefined'; var symbolToStringTagExists = symbolExists && typeof Symbol.toStringTag !== 'undefined'; var setEntriesExists = setExists && typeof Set.prototype.entries === 'function'; var mapEntriesExists = mapExists && typeof Map.prototype.entries === 'function'; var setIteratorPrototype = setEntriesExists && Object.getPrototypeOf(new Set().entries()); var mapIteratorPrototype = mapEntriesExists && Object.getPrototypeOf(new Map().entries()); var arrayIteratorExists = symbolIteratorExists && typeof Array.prototype[Symbol.iterator] === 'function'; var arrayIteratorPrototype = arrayIteratorExists && Object.getPrototypeOf([][Symbol.iterator]()); var stringIteratorExists = symbolIteratorExists && typeof String.prototype[Symbol.iterator] === 'function'; var stringIteratorPrototype = stringIteratorExists && Object.getPrototypeOf(''[Symbol.iterator]()); var toStringLeftSliceLength = 8; var toStringRightSliceLength = -1; function typeDetect(obj) { var typeofObj = typeof obj; if (typeofObj !== 'object') { return typeofObj; } if (obj === null) { return 'null'; } if (obj === globalObject) { return 'global'; } if (Array.isArray(obj) && (symbolToStringTagExists === false || !(Symbol.toStringTag in obj))) { return 'Array'; } if (typeof window === 'object' && window !== null) { if (typeof window.location === 'object' && obj === window.location) { return 'Location'; } if (typeof window.document === 'object' && obj === window.document) { return 'Document'; } if (typeof window.navigator === 'object') { if (typeof window.navigator.mimeTypes === 'object' && obj === window.navigator.mimeTypes) { return 'MimeTypeArray'; } if (typeof window.navigator.plugins === 'object' && obj === window.navigator.plugins) { return 'PluginArray'; } } if ((typeof window.HTMLElement === 'function' || typeof window.HTMLElement === 'object') && obj instanceof window.HTMLElement) { if (obj.tagName === 'BLOCKQUOTE') { return 'HTMLQuoteElement'; } if (obj.tagName === 'TD') { return 'HTMLTableDataCellElement'; } if (obj.tagName === 'TH') { return 'HTMLTableHeaderCellElement'; } } } var stringTag = (symbolToStringTagExists && obj[Symbol.toStringTag]); if (typeof stringTag === 'string') { return stringTag; } var objPrototype = Object.getPrototypeOf(obj); if (objPrototype === RegExp.prototype) { return 'RegExp'; } if (objPrototype === Date.prototype) { return 'Date'; } if (promiseExists && objPrototype === Promise.prototype) { return 'Promise'; } if (setExists && objPrototype === Set.prototype) { return 'Set'; } if (mapExists && objPrototype === Map.prototype) { return 'Map'; } if (weakSetExists && objPrototype === WeakSet.prototype) { return 'WeakSet'; } if (weakMapExists && objPrototype === WeakMap.prototype) { return 'WeakMap'; } if (dataViewExists && objPrototype === DataView.prototype) { return 'DataView'; } if (mapExists && objPrototype === mapIteratorPrototype) { return 'Map Iterator'; } if (setExists && objPrototype === setIteratorPrototype) { return 'Set Iterator'; } if (arrayIteratorExists && objPrototype === arrayIteratorPrototype) { return 'Array Iterator'; } if (stringIteratorExists && objPrototype === stringIteratorPrototype) { return 'String Iterator'; } if (objPrototype === null) { return 'Object'; } return Object .prototype .toString .call(obj) .slice(toStringLeftSliceLength, toStringRightSliceLength); } return typeDetect; })); } (typeDetect)); var typeDetectExports = typeDetect.exports; /*! * Chai - expectTypes utility * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ /** * ### .expectTypes(obj, types) * * Ensures that the object being tested against is of a valid type. * * utils.expectTypes(this, ['array', 'object', 'string']); * * @param {Mixed} obj constructed Assertion * @param {Array} type A list of allowed types for this assertion * @namespace Utils * @name expectTypes * @api public */ var AssertionError = assertionError; var flag$3 = flag$5; var type$2 = typeDetectExports; var expectTypes = function expectTypes(obj, types) { var flagMsg = flag$3(obj, 'message'); var ssfi = flag$3(obj, 'ssfi'); flagMsg = flagMsg ? flagMsg + ': ' : ''; obj = flag$3(obj, 'object'); types = types.map(function (t) { return t.toLowerCase(); }); types.sort(); // Transforms ['lorem', 'ipsum'] into 'a lorem, or an ipsum' var str = types.map(function (t, index) { var art = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(t.charAt(0)) ? 'an' : 'a'; var or = types.length > 1 && index === types.length - 1 ? 'or ' : ''; return or + art + ' ' + t; }).join(', '); var objType = type$2(obj).toLowerCase(); if (!types.some(function (expected) { return objType === expected; })) { throw new AssertionError( flagMsg + 'object tested must be ' + str + ', but ' + objType + ' given', undefined, ssfi ); } }; /*! * Chai - getActual utility * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ /** * ### .getActual(object, [actual]) * * Returns the `actual` value for an Assertion. * * @param {Object} object (constructed Assertion) * @param {Arguments} chai.Assertion.prototype.assert arguments * @namespace Utils * @name getActual */ var getActual$1 = function getActual(obj, args) { return args.length > 4 ? args[4] : obj._obj; }; /* ! * Chai - getFuncName utility * Copyright(c) 2012-2016 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ /** * ### .getFuncName(constructorFn) * * Returns the name of a function. * When a non-function instance is passed, returns `null`. * This also includes a polyfill function if `aFunc.name` is not defined. * * @name getFuncName * @param {Function} funct * @namespace Utils * @api public */ var toString$2 = Function.prototype.toString; var functionNameMatch = /\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/; var maxFunctionSourceLength = 512; function getFuncName(aFunc) { if (typeof aFunc !== 'function') { return null; } var name = ''; if (typeof Function.prototype.name === 'undefined' && typeof aFunc.name === 'undefined') { // eslint-disable-next-line prefer-reflect var functionSource = toString$2.call(aFunc); // To avoid unconstrained resource consumption due to pathalogically large function names, // we limit the available return value to be less than 512 characters. if (functionSource.indexOf('(') > maxFunctionSourceLength) { return name; } // Here we run a polyfill if Function does not support the `name` property and if aFunc.name is not defined var match = functionSource.match(functionNameMatch); if (match) { name = match[1]; } } else { // If we've got a `name` property we just use it name = aFunc.name; } return name; } var getFuncName_1 = getFuncName; var getFuncName$1 = /*@__PURE__*/getDefaultExportFromCjs(getFuncName_1); const ansiColors = { bold: ['1', '22'], dim: ['2', '22'], italic: ['3', '23'], underline: ['4', '24'], // 5 & 6 are blinking inverse: ['7', '27'], hidden: ['8', '28'], strike: ['9', '29'], // 10-20 are fonts // 21-29 are resets for 1-9 black: ['30', '39'], red: ['31', '39'], green: ['32', '39'], yellow: ['33', '39'], blue: ['34', '39'], magenta: ['35', '39'], cyan: ['36', '39'], white: ['37', '39'], brightblack: ['30;1', '39'], brightred: ['31;1', '39'], brightgreen: ['32;1', '39'], brightyellow: ['33;1', '39'], brightblue: ['34;1', '39'], brightmagenta: ['35;1', '39'], brightcyan: ['36;1', '39'], brightwhite: ['37;1', '39'], grey: ['90', '39'], }; const styles = { special: 'cyan', number: 'yellow', bigint: 'yellow', boolean: 'yellow', undefined: 'grey', null: 'bold', string: 'green', symbol: 'green', date: 'magenta', regexp: 'red', }; const truncator = '…'; function colorise(value, styleType) { const color = ansiColors[styles[styleType]] || ansiColors[styleType]; if (!color) { return String(value) } return `\u001b[${color[0]}m${String(value)}\u001b[${color[1]}m` } function normaliseOptions({ showHidden = false, depth = 2, colors = false, customInspect = true, showProxy = false, maxArrayLength = Infinity, breakLength = Infinity, seen = [], // eslint-disable-next-line no-shadow truncate = Infinity, stylize = String, } = {}) { const options = { showHidden: Boolean(showHidden), depth: Number(depth), colors: Boolean(colors), customInspect: Boolean(customInspect), showProxy: Boolean(showProxy), maxArrayLength: Number(maxArrayLength), breakLength: Number(breakLength), truncate: Number(truncate), seen, stylize, }; if (options.colors) { options.stylize = colorise; } return options } function truncate(string, length, tail = truncator) { string = String(string); const tailLength = tail.length; const stringLength = string.length; if (tailLength > length && stringLength > tailLength) { return tail } if (stringLength > length && stringLength > tailLength) { return `${string.slice(0, length - tailLength)}${tail}` } return string } // eslint-disable-next-line complexity function inspectList(list, options, inspectItem, separator = ', ') { inspectItem = inspectItem || options.inspect; const size = list.length; if (size === 0) return '' const originalLength = options.truncate; let output = ''; let peek = ''; let truncated = ''; for (let i = 0; i < size; i += 1) { const last = i + 1 === list.length; const secondToLast = i + 2 === list.length; truncated = `${truncator}(${list.length - i})`; const value = list[i]; // If there is more than one remaining we need to account for a separator of `, ` options.truncate = originalLength - output.length - (last ? 0 : separator.length); const string = peek || inspectItem(value, options) + (last ? '' : separator); const nextLength = output.length + string.length; const truncatedLength = nextLength + truncated.length; // If this is the last element, and adding it would // take us over length, but adding the truncator wouldn't - then break now if (last && nextLength > originalLength && output.length + truncated.length <= originalLength) { break } // If this isn't the last or second to last element to scan, // but the string is already over length then break here if (!last && !secondToLast && truncatedLength > originalLength) { break } // Peek at the next string to determine if we should // break early before adding this item to the output peek = last ? '' : inspectItem(list[i + 1], options) + (secondToLast ? '' : separator); // If we have one element left, but this element and // the next takes over length, the break early if (!last && secondToLast && truncatedLength > originalLength && nextLength + peek.length > originalLength) { break } output += string; // If the next element takes us to length - // but there are more after that, then we should truncate now if (!last && !secondToLast && nextLength + peek.length >= originalLength) { truncated = `${truncator}(${list.length - i - 1})`; break } truncated = ''; } return `${output}${truncated}` } function quoteComplexKey(key) { if (key.match(/^[a-zA-Z_][a-zA-Z_0-9]*$/)) { return key } return JSON.stringify(key) .replace(/'/g, "\\'") .replace(/\\"/g, '"') .replace(/(^"|"$)/g, "'") } function inspectProperty([key, value], options) { options.truncate -= 2; if (typeof key === 'string') { key = quoteComplexKey(key); } else if (typeof key !== 'number') { key = `[${options.inspect(key, options)}]`; } options.truncate -= key.length; value = options.inspect(value, options); return `${key}: ${value}` } function inspectArray(array, options) { // Object.keys will always output the Array indices first, so we can slice by // `array.length` to get non-index properties const nonIndexProperties = Object.keys(array).slice(array.length); if (!array.length && !nonIndexProperties.length) return '[]' options.truncate -= 4; const listContents = inspectList(array, options); options.truncate -= listContents.length; let propertyContents = ''; if (nonIndexProperties.length) { propertyContents = inspectList( nonIndexProperties.map(key => [key, array[key]]), options, inspectProperty ); } return `[ ${listContents}${propertyContents ? `, ${propertyContents}` : ''} ]` } const getArrayName = array => { // We need to special case Node.js' Buffers, which report to be Uint8Array if (typeof Buffer === 'function' && array instanceof Buffer) { return 'Buffer' } if (array[Symbol.toStringTag]) { return array[Symbol.toStringTag] } return getFuncName$1(array.constructor) }; function inspectTypedArray(array, options) { const name = getArrayName(array); options.truncate -= name.length + 4; // Object.keys will always output the Array indices first, so we can slice by // `array.length` to get non-index properties const nonIndexProperties = Object.keys(array).slice(array.length); if (!array.length && !nonIndexProperties.length) return `${name}[]` // As we know TypedArrays only contain Unsigned Integers, we can skip inspecting each one and simply // stylise the toString() value of them let output = ''; for (let i = 0; i < array.length; i++) { const string = `${options.stylize(truncate(array[i], options.truncate), 'number')}${ i === array.length - 1 ? '' : ', ' }`; options.truncate -= string.length; if (array[i] !== array.length && options.truncate <= 3) { output += `${truncator}(${array.length - array[i] + 1})`; break } output += string; } let propertyContents = ''; if (nonIndexProperties.length) { propertyContents = inspectList( nonIndexProperties.map(key => [key, array[key]]), options, inspectProperty ); } return `${name}[ ${output}${propertyContents ? `, ${propertyContents}` : ''} ]` } function inspectDate(dateObject, options) { const stringRepresentation = dateObject.toJSON(); if (stringRepresentation === null) { return 'Invalid Date' } const split = stringRepresentation.split('T'); const date = split[0]; // If we need to - truncate the time portion, but never the date return options.stylize(`${date}T${truncate(split[1], options.truncate - date.length - 1)}`, 'date') } function inspectFunction(func, options) { const name = getFuncName$1(func); if (!name) { return options.stylize('[Function]', 'special') } return options.stylize(`[Function ${truncate(name, options.truncate - 11)}]`, 'special') } function inspectMapEntry([key, value], options) { options.truncate -= 4; key = options.inspect(key, options); options.truncate -= key.length; value = options.inspect(value, options); return `${key} => ${value}` } // IE11 doesn't support `map.entries()` function mapToEntries(map) { const entries = []; map.forEach((value, key) => { entries.push([key, value]); }); return entries } function inspectMap(map, options) { const size = map.size - 1; if (size <= 0) { return 'Map{}' } options.truncate -= 7; return `Map{ ${inspectList(mapToEntries(map), options, inspectMapEntry)} }` } const isNaN$2 = Number.isNaN || (i => i !== i); // eslint-disable-line no-self-compare function inspectNumber(number, options) { if (isNaN$2(number)) { return options.stylize('NaN', 'number') } if (number === Infinity) { return options.stylize('Infinity', 'number') } if (number === -Infinity) { return options.stylize('-Infinity', 'number') } if (number === 0) { return options.stylize(1 / number === Infinity ? '+0' : '-0', 'number') } return options.stylize(truncate(number, options.truncate), 'number') } function inspectBigInt(number, options) { let nums = truncate(number.toString(), options.truncate - 1); if (nums !== truncator) nums += 'n'; return options.stylize(nums, 'bigint') } function inspectRegExp(value, options) { const flags = value.toString().split('/')[2]; const sourceLength = options.truncate - (2 + flags.length); const source = value.source; return options.stylize(`/${truncate(source, sourceLength)}/${flags}`, 'regexp') } // IE11 doesn't support `Array.from(set)` function arrayFromSet(set) { const values = []; set.forEach(value => { values.push(value); }); return values } function inspectSet(set, options) { if (set.size === 0) return 'Set{}' options.truncate -= 7; return `Set{ ${inspectList(arrayFromSet(set), options)} }` } const stringEscapeChars = new RegExp( "['\\u0000-\\u001f\\u007f-\\u009f\\u00ad\\u0600-\\u0604\\u070f\\u17b4\\u17b5" + '\\u200c-\\u200f\\u2028-\\u202f\\u2060-\\u206f\\ufeff\\ufff0-\\uffff]', 'g' ); const escapeCharacters = { '\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', "'": "\\'", '\\': '\\\\', }; const hex = 16; const unicodeLength = 4; function escape(char) { return escapeCharacters[char] || `\\u${`0000${char.charCodeAt(0).toString(hex)}`.slice(-unicodeLength)}` } function inspectString(string, options) { if (stringEscapeChars.test(string)) { string = string.replace(stringEscapeChars, escape); } return options.stylize(`'${truncate(string, options.truncate - 2)}'`, 'string') } function inspectSymbol(value) { if ('description' in Symbol.prototype) { return value.description ? `Symbol(${value.description})` : 'Symbol()' } return value.toString() } let getPromiseValue = () => 'Promise{…}'; try { const { getPromiseDetails, kPending, kRejected } = process.binding('util'); if (Array.isArray(getPromiseDetails(Promise.resolve()))) { getPromiseValue = (value, options) => { const [state, innerValue] = getPromiseDetails(value); if (state === kPending) { return 'Promise{<pending>}' } return `Promise${state === kRejected ? '!' : ''}{${options.inspect(innerValue, options)}}` }; } } catch (notNode) { /* ignore */ } var inspectPromise = getPromiseValue; function inspectObject$1(object, options) { const properties = Object.getOwnPropertyNames(object); const symbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : []; if (properties.length === 0 && symbols.length === 0) { return '{}' } options.truncate -= 4; options.seen = options.seen || []; if (options.seen.indexOf(object) >= 0) { return '[Circular]' } options.seen.push(object); const propertyContents = inspectList( properties.map(key => [key, object[key]]), options, inspectProperty ); const symbolContents = inspectList( symbols.map(key => [key, object[key]]), options, inspectProperty ); options.seen.pop(); let sep = ''; if (propertyContents && symbolContents) { sep = ', '; } return `{ ${propertyContents}${sep}${symbolContents} }` } const toStringTag = typeof Symbol !== 'undefined' && Symbol.toStringTag ? Symbol.toStringTag : false; function inspectClass(value, options) { let name = ''; if (toStringTag && toStringTag in value) { name = value[toStringTag]; } name = name || getFuncName$1(value.constructor); // Babel transforms anonymous classes to the name `_class` if (!name || name === '_class') { name = '<Anonymous Class>'; } options.truncate -= name.length; return `${name}${inspectObject$1(value, options)}` } function inspectArguments(args, options) { if (args.length === 0) return 'Arguments[]' options.truncate -= 13; return `Arguments[ ${inspectList(args, options)} ]` } const errorKeys = [ 'stack', 'line', 'column', 'name', 'message', 'fileName', 'lineNumber', 'columnNumber', 'number', 'description', ]; function inspectObject(error, options) { const properties = Object.getOwnPropertyNames(error).filter(key => errorKeys.indexOf(key) === -1); const name = error.name; options.truncate -= name.length; let message = ''; if (typeof error.message === 'string') { message = truncate(error.message, options.truncate); } else { properties.unshift('message'); } message = message ? `: ${message}` : ''; options.truncate -= message.length + 5; const propertyContents = inspectList( properties.map(key => [key, error[key]]), options, inspectProperty ); return `${name}${message}${propertyContents ? ` { ${propertyContents} }` : ''}` } function inspectAttribute([key, value], options) { options.truncate -= 3; if (!value) { return `${options.stylize(key, 'yellow')}` } return `${options.stylize(key, 'yellow')}=${options.stylize(`"${value}"`, 'string')}` } function inspectHTMLCollection(collection, options) { // eslint-disable-next-line no-use-before-define return inspectList(collection, options, inspectHTML, '\n') } function inspectHTML(element, options) { const properties = element.getAttributeNames(); const name = element.tagName.toLowerCase(); const head = options.stylize(`<${name}`, 'special'); const headClose = options.stylize(`>`, 'special'); const tail = options.stylize(`</${name}>`, 'special'); options.truncate -= name.length * 2 + 5; let propertyContents = ''; if (properties.length > 0) { propertyContents += ' '; propertyContents += inspectList( properties.map(key => [key, element.getAttribute(key)]), options, inspectAttribute, ' ' ); } options.truncate -= propertyContents.length; const truncate = options.truncate; let children = inspectHTMLCollection(element.children, options); if (children && children.length > truncate) { children = `${truncator}(${element.children.length})`; } return `${head}${propertyContents}${headClose}${children}${tail}` } /* ! * loupe * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ const symbolsSupported = typeof Symbol === 'function' && typeof Symbol.for === 'function'; const chaiInspect = symbolsSupported ? Symbol.for('chai/inspect') : '@@chai/inspect'; let nodeInspect = false; try { // eslint-disable-next-line global-require const nodeUtil = require('util'); nodeInspect = nodeUtil.inspect ? nodeUtil.inspect.custom : false; } catch (noNodeInspect) { nodeInspect = false; } function FakeMap$1() { // eslint-disable-next-line prefer-template this.key = 'chai/loupe__' + Math.random() + Date.now(); } FakeMap$1.prototype = { // eslint-disable-next-line object-shorthand get: function get(key) { return key[this.key] }, // eslint-disable-next-line object-shorthand has: function has(key) { return this.key in key }, // eslint-disable-next-line object-shorthand set: function set(key, value) { if (Object.isExtensible(key)) { Object.defineProperty(key, this.key, { // eslint-disable-next-line object-shorthand value: value, configurable: true, }); } }, }; const constructorMap = new (typeof WeakMap === 'function' ? WeakMap : FakeMap$1)(); const stringTagMap = {}; const baseTypesMap = { undefined: (value, options) => options.stylize('undefined', 'undefined'), null: (value, options) => options.stylize(null, 'null'), boolean: (value, options) => options.stylize(value, 'boolean'), Boolean: (value, options) => options.stylize(value, 'boolean'), number: inspectNumber, Number: inspectNumber, bigint: inspectBigInt, BigInt: inspectBigInt, string: inspectString, String: inspectString, function: inspectFunction, Function: inspectFunction, symbol: inspectSymbol, // A Symbol polyfill will return `Symbol` not `symbol` from typedetect Symbol: inspectSymbol, Array: inspectArray, Date: inspectDate, Map: inspectMap, Set: inspectSet, RegExp: inspectRegExp, Promise: inspectPromise, // WeakSet, WeakMap are totally opaque to us WeakSet: (value, options) => options.stylize('WeakSet{…}', 'special'), WeakMap: (value, options) => options.stylize('WeakMap{…}', 'special'), Arguments: inspectArguments, Int8Array: inspectTypedArray, Uint8Array: inspectTypedArray, Uint8ClampedArray: inspectTypedArray, Int16Array: inspectTypedArray, Uint16Array: inspectTypedArray, Int32Array: inspectTypedArray, Uint32Array: inspectTypedArray, Float32Array: inspectTypedArray, Float64Array: inspectTypedArray, Generator: () => '', DataView: () => '', ArrayBuffer: () => '', Error: inspectObject, HTMLCollection: inspectHTMLCollection, NodeList: inspectHTMLCollection, }; // eslint-disable-next-line complexity const inspectCustom = (value, options, type) => { if (chaiInspect in value && typeof value[chaiInspect] === 'function') { return value[chaiInspect](options) } if (nodeInspect && nodeInspect in value && typeof value[nodeInspect] === 'function') { return value[nodeInspect](options.depth, options) } if ('inspect' in value && typeof value.inspect === 'function') { return value.inspect(options.depth, options) } if ('constructor' in value && constructorMap.has(value.constructor)) { return constructorMap.get(value.constructor)(value, options) } if (stringTagMap[type]) { return stringTagMap[type](value, options) } return '' }; const toString$1 = Object.prototype.toString; // eslint-disable-next-line complexity function inspect$3(value, options) { options = normaliseOptions(options); options.inspect = inspect$3; const { customInspect } = options; let type = value === null ? 'null' : typeof value; if (type === 'object') { type = toString$1.call(value).slice(8, -1); } // If it is a base value that we already support, then use Loupe's inspector if (baseTypesMap[type]) { return baseTypesMap[type](value, options) } // If `options.customInspect` is set to true then try to use the custom inspector if (customInspect && value) { const output = inspectCustom(value, options, type); if (output) { if (typeof output === 'string') return output return inspect$3(output, options) } } const proto = value ? Object.getPrototypeOf(value) : false; // If it's a plain Object then use Loupe's inspector if (proto === Object.prototype || proto === null) { return inspectObject$1(value, options) } // Specifically account for HTMLElements // eslint-disable-next-line no-undef if (value && typeof HTMLElement === 'function' && value instanceof HTMLElement) { return inspectHTML(value, options) } if ('constructor' in value) { // If it is a class, inspect it like an object but add the constructor name if (value.constructor !== Object) { return inspectClass(value, options) } // If it is an object with an anonymous prototype, display it as an object. return inspectObject$1(value, options) } // last chance to check if it's an object if (value === Object(value)) { return inspectObject$1(value, options) } // We have run out of options! Just stringify the value return options.stylize(String(value), type) } function registerConstructor(constructor, inspector) { if (constructorMap.has(constructor)) { return false } constructorMap.set(constructor, inspector); return true } function registerStringTag(stringTag, inspector) { if (stringTag in stringTagMap) { return false } stringTagMap[stringTag] = inspector; return true } const custom = chaiInspect; var loupe$1 = /*#__PURE__*/Object.freeze({ __proto__: null, custom: custom, default: inspect$3, inspect: inspect$3, registerConstructor: registerConstructor, registerStringTag: registerStringTag }); var require$$1 = /*@__PURE__*/getAugmentedNamespace(loupe$1); var config$6 = { /** * ### config.includeStack * * User configurable property, influences whether stack trace * is included in Assertion error message. Default of false * suppresses stack trace in the error message. * * chai.config.includeStack = true; // enable stack on error * * @param {Boolean} * @api public */ includeStack: false, /** * ### config.showDiff * * User configurable property, influences whether or not * the `showDiff` flag should be included in the thrown * AssertionErrors. `false` will always be `false`; `true` * will be true when the assertion has requested a diff * be shown. * * @param {Boolean} * @api public */ showDiff: true, /** * ### config.truncateThreshold * * User configurable property, sets length threshold for actual and * expected values in assertion errors. If this threshold is exceeded, for * example for large data structures, the value is replaced with something * like `[ Array(3) ]` or `{ Object (prop1, prop2) }`. * * Set it to zero if you want to disable truncating altogether. * * This is especially userful when doing assertions on arrays: having this * set to a reasonable large value makes the failure messages readily * inspectable. * * chai.config.truncateThreshold = 0; // disable truncating * * @param {Number} * @api public */ truncateThreshold: 40, /** * ### config.useProxy * * User configurable property, defines if chai will use a Proxy to throw * an error when a non-existent property is read, which protects users * from typos when using property-based assertions. * * Set it to false if you want to disable this feature. * * chai.config.useProxy = false; // disable use of Proxy * * This feature is automatically disabled regardless of this config value * in environments that don't support proxies. * * @param {Boolean} * @api public */ useProxy: true, /** * ### config.proxyExcludedKeys * * User configurable property, defines which properties should be ignored * instead of throwing an error if they do not exist on the assertion. * This is only applied if the environment Chai is running in supports proxies and * if the `useProxy` configuration setting is enabled. * By default, `then` and `inspect` will not throw an error if they do not exist on the * assertion object because the `.inspect` property is read by `util.inspect` (for example, when * using `console.log` on the assertion object) and `.then` is necessary for promise type-checking. * * // By default these keys will not throw an error if they do not exist on the assertion object * chai.config.proxyExcludedKeys = ['then', 'inspect']; * * @param {Array} * @api public */ proxyExcludedKeys: ['then', 'catch', 'inspect', 'toJSON'], /** * ### config.deepEqual * * User configurable property, defines which a custom function to use for deepEqual * comparisons. * By default, the function used is the one from the `deep-eql` package without custom comparator. * * // use a custom comparator * chai.config.deepEqual = (expected, actual) => { * return chai.util.eql(expected, actual, { * comparator: (expected, actual) => { * // for non number comparison, use the default behavior * if(typeof expected !== 'number') return null; * // allow a difference of 10 between compared numbers * return typeof actual === 'number' && Math.abs(actual - expected) < 10 * } * }) * }; * * @param {Function} * @api public */ deepEqual: null }; var loupe = require$$1; var config$5 = config$6; var inspect_1 = inspect$2; /** * ### .inspect(obj, [showHidden], [depth], [colors]) * * Echoes the value of a value. Tries to print the value out * in the best way possible given the different types. * * @param {Object} obj The object to print out. * @param {Boolean} showHidden Flag that shows hidden (not enumerable) * properties of objects. Default is false. * @param {Number} depth Depth in which to descend in object. Default is 2. * @param {Boolean} colors Flag to turn on ANSI escape codes to color the * output. Default is false (no coloring). * @namespace Utils * @name inspect */ function inspect$2(obj, showHidden, depth, colors) { var options = { colors: colors, depth: (typeof depth === 'undefined' ? 2 : depth), showHidden: showHidden, truncate: config$5.truncateThreshold ? config$5.truncateThreshold : Infinity, }; return loupe.inspect(obj, options); } /*! * Chai - flag utility * Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com> * MIT Licensed */ /*! * Module dependencies */ var inspect$1 = inspect_1; var config$4 = config$6; /** * ### .objDisplay(object) * * Determines if an object or an array matches * criteria to be inspected in-line for error * messages or should be truncated. * * @param {Mixed} javascript object to inspect * @returns {string} stringified object * @name objDisplay * @namespace Utils * @api public */ var objDisplay$1 = function objDisplay(obj) { var str = inspect$1(obj) , type = Object.prototype.toString.call(obj); if (config$4.truncateThreshold && str.length >= config$4.truncateThreshold) { if (type === '[object Function]') { return !obj.name || obj.name === '' ? '[Function]' : '[Function: ' + obj.name + ']'; } else if (type === '[object Array]') { return '[ Array(' + obj.length + ') ]'; } else if (type === '[object Object]')