Changeset 0c6b92a for imaps-frontend/node_modules/es-to-primitive
- Timestamp:
- 12/12/24 17:06:06 (5 weeks ago)
- Branches:
- main
- Parents:
- d565449
- Location:
- imaps-frontend/node_modules/es-to-primitive
- Files:
-
- 7 added
- 2 deleted
- 12 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/es-to-primitive/.eslintrc
rd565449 r0c6b92a 5 5 6 6 "rules": { 7 "complexity": [2, 14],8 7 "func-name-matching": 0, 9 8 "id-length": [2, { "min": 1, "max": 24, "properties": "never" }], 10 "max-statements": [2, 20],11 9 "new-cap": [2, { "capIsNewExceptions": ["GetMethod"] }] 12 10 }, … … 16 14 "files": "test/**", 17 15 "rules": { 18 "max-lines-per-function": [2, { "max": 68 }],16 "max-lines-per-function": 0, 19 17 }, 20 18 } -
imaps-frontend/node_modules/es-to-primitive/CHANGELOG.md
rd565449 r0c6b92a 1 # Changelog 2 3 All notable changes to this project will be documented in this file. 4 5 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) 6 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 7 8 ## [v1.3.0](https://github.com/ljharb/es-to-primitive/compare/v1.2.1...v1.3.0) - 2024-11-26 9 10 ### Commits 11 12 - [actions] reuse common workflows [`bb72efc`](https://github.com/ljharb/es-to-primitive/commit/bb72efc7e04ae11b84e4aecf120a4e9063e34428) 13 - [Tests] use `es-value-fixtures` [`a912f7b`](https://github.com/ljharb/es-to-primitive/commit/a912f7b675333735c1c980cda88772ac1870395b) 14 - [Tests] migrate tests to Github Actions [`510baf0`](https://github.com/ljharb/es-to-primitive/commit/510baf092633a62d59866fbf56836ce42c717c70) 15 - [New] add types [`69ba1fd`](https://github.com/ljharb/es-to-primitive/commit/69ba1fdcac834b03698739990ba98fe6007024dc) 16 - [meta] remove unused Makefile [`4ea66e6`](https://github.com/ljharb/es-to-primitive/commit/4ea66e62ef4afa0102eb8335ba3e003e8332f664) 17 - [actions] use `node/install` instead of `node/run`; use `codecov` action [`3c31937`](https://github.com/ljharb/es-to-primitive/commit/3c31937119ca24fd6d00e362d6435a28cfe9e91c) 18 - [meta] do not publish github action workflow files [`389567e`](https://github.com/ljharb/es-to-primitive/commit/389567e8523b65b90b529f1029d215fd4f12ac14) 19 - [meta] use `npmignore` to autogenerate an npmignore file [`9f3aa76`](https://github.com/ljharb/es-to-primitive/commit/9f3aa7651791ab9386408035491a1ba4fec4c432) 20 - [actions] split out node 10-20, and 20+ [`c60d7d8`](https://github.com/ljharb/es-to-primitive/commit/c60d7d822a36880bce0535335c70fdc2a8da232d) 21 - [Tests] run `nyc` on all tests; use `tape` runner [`29cbb89`](https://github.com/ljharb/es-to-primitive/commit/29cbb89800b5cfef9bef3ae7e0e779c782e1bbb9) 22 - [meta] add `auto-changelog` [`ea744b2`](https://github.com/ljharb/es-to-primitive/commit/ea744b2a0bda788b0d957c1787e41434e98b0155) 23 - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `function.prototype.name`, `has-symbols`, `object-inspect`, `object-is`, `tape` [`e5c3c79`](https://github.com/ljharb/es-to-primitive/commit/e5c3c792f67685a9647e817e7582d4c76a876f69) 24 - [actions] add automatic rebasing / merge commit blocking [`a5a6f00`](https://github.com/ljharb/es-to-primitive/commit/a5a6f0066540c91c8aa45a4921f1cd2349f435ba) 25 - [Dev Deps] update `@ljharb/eslint-config`, `es-value-fixtures`, `function.prototype.name`, `npmignore`, `object-inspect`, `object-is`, `tape` [`7941fd5`](https://github.com/ljharb/es-to-primitive/commit/7941fd530fb3a73f923b76c739335ffc21793ad6) 26 - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `es-value-fixtures`, `foreach`, `object-inspect`, `tape` [`eb1c79c`](https://github.com/ljharb/es-to-primitive/commit/eb1c79c288c89154014634b94f64308344901eaf) 27 - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `function.prototype.name`, `object-inspect`, `safe-publish-latest`, `tape` [`249b42f`](https://github.com/ljharb/es-to-primitive/commit/249b42f1ce069ea78a032f10414d1c1c0b6c6345) 28 - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `function.prototype.name`, `object-inspect`, `object-is`, `tape` [`d57d5e9`](https://github.com/ljharb/es-to-primitive/commit/d57d5e9ea5ea4778f383e2f1aa637be0be80dd78) 29 - [actions] update codecov uploader [`003b62c`](https://github.com/ljharb/es-to-primitive/commit/003b62c483372d5eac38f51925b6cbdf5d7a0665) 30 - [actions] add "Allow Edits" workflow [`75ee990`](https://github.com/ljharb/es-to-primitive/commit/75ee99083626dc14558ae294c127e4aaf925d214) 31 - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`, `object-is`; add `safe-publish-latest` [`ba5da7b`](https://github.com/ljharb/es-to-primitive/commit/ba5da7bffd93c3cc2e079ad751a3e678333a973e) 32 - [readme] remove travis badge [`6f7aec7`](https://github.com/ljharb/es-to-primitive/commit/6f7aec78e4f1ebfca74c384a837063f4099e7b9b) 33 - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `object-inspect`, `tape` [`3291fd5`](https://github.com/ljharb/es-to-primitive/commit/3291fd567695b45bddc58e5ec3da2dcce0e5ccc7) 34 - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `function.prototype.name`, `has-symbols`, `object-inspect` [`53007f2`](https://github.com/ljharb/es-to-primitive/commit/53007f25d1f26e301b4f41d070c423723bed1690) 35 - [actions] update checkout action [`69640db`](https://github.com/ljharb/es-to-primitive/commit/69640dbb9ddafe05527388fe72bda1aca08d07b5) 36 - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `object-is`, `tape`; add `aud` [`c9d644e`](https://github.com/ljharb/es-to-primitive/commit/c9d644ef3c6b2210e86ce2d3aa8e8b1668f6801d) 37 - [Tests] use `for-each` instead of `foreach` [`e9117bb`](https://github.com/ljharb/es-to-primitive/commit/e9117bb055417cb721dbf5dbe1d23b058a8241f2) 38 - [readme] add github actions/codecov badges [`53cd375`](https://github.com/ljharb/es-to-primitive/commit/53cd375ab22a25d4bada35000473e30c22ee2028) 39 - [Deps] update `is-callable`, `is-date-object`, `is-symbol` [`8116c68`](https://github.com/ljharb/es-to-primitive/commit/8116c68a8ba555f8daaf1d71a60c974d3439c94b) 40 - [Tests] fix test skipping for `Symbol.toPrimitive` [`e6268ef`](https://github.com/ljharb/es-to-primitive/commit/e6268ef31b34cb5263501ba9735ccce78a07e504) 41 - [actions] switch Automatic Rebase workflow to `pull_request_target` event [`da41c40`](https://github.com/ljharb/es-to-primitive/commit/da41c40399c2a574f74a59b85800d9934b91d49a) 42 - [Deps] update `is-callable`, `is-date-object` [`96fe13f`](https://github.com/ljharb/es-to-primitive/commit/96fe13ff3c486c7857c2ca69ac70161ef0e5b4a1) 43 - [Tests] replace `aud` with `npm audit` [`0b53154`](https://github.com/ljharb/es-to-primitive/commit/0b531546081427cb8a4fc06fde5540ba0b287b5b) 44 - [meta] use `prepublishOnly` script for npm 7+ [`9d7d485`](https://github.com/ljharb/es-to-primitive/commit/9d7d4856d4b5f28c68de2aba068522b9a85ee669) 45 - [Deps] update `is-callable` [`3c990b6`](https://github.com/ljharb/es-to-primitive/commit/3c990b646813e2470b19460e32801113f9acc13b) 46 - [Deps] update `is-callable` [`9bcfff2`](https://github.com/ljharb/es-to-primitive/commit/9bcfff276ce078034404b6b27e4f74beb530002c) 47 - [Deps] update `is-callable` [`1eb5478`](https://github.com/ljharb/es-to-primitive/commit/1eb5478e0c93b230b7bc67f9fef963d94a391117) 48 - [meta] only run `aud` on prod deps [`1fcd896`](https://github.com/ljharb/es-to-primitive/commit/1fcd89684a4351c15fec2cb289ecc331f917b80e) 49 - [Deps] update `is-symbol` [`7174a47`](https://github.com/ljharb/es-to-primitive/commit/7174a474f4f9f07319c81f046b10446caf9b3af0) 50 51 <!-- auto-changelog-above --> 52 1 53 1.2.1 / 2019-11-08 2 54 ================= -
imaps-frontend/node_modules/es-to-primitive/README.md
rd565449 r0c6b92a 1 1 # es-to-primitive <sup>[![Version Badge][npm-version-svg]][package-url]</sup> 2 2 3 [![Build Status][travis-svg]][travis-url] 3 [![github actions][actions-image]][actions-url] 4 [![coverage][codecov-image]][codecov-url] 4 5 [![dependency status][deps-svg]][deps-url] 5 6 [![dev dependency status][dev-deps-svg]][dev-deps-url] … … 36 37 37 38 [package-url]: https://npmjs.org/package/es-to-primitive 38 [npm-version-svg]: http://versionbadg.es/ljharb/es-to-primitive.svg 39 [travis-svg]: https://travis-ci.org/ljharb/es-to-primitive.svg 40 [travis-url]: https://travis-ci.org/ljharb/es-to-primitive 39 [npm-version-svg]: https://versionbadg.es/ljharb/es-to-primitive.svg 41 40 [deps-svg]: https://david-dm.org/ljharb/es-to-primitive.svg 42 41 [deps-url]: https://david-dm.org/ljharb/es-to-primitive … … 44 43 [dev-deps-url]: https://david-dm.org/ljharb/es-to-primitive#info=devDependencies 45 44 [npm-badge-png]: https://nodei.co/npm/es-to-primitive.png?downloads=true&stars=true 46 [license-image]: http ://img.shields.io/npm/l/es-to-primitive.svg45 [license-image]: https://img.shields.io/npm/l/es-to-primitive.svg 47 46 [license-url]: LICENSE 48 [downloads-image]: http://img.shields.io/npm/dm/es-to-primitive.svg 49 [downloads-url]: http://npm-stat.com/charts.html?package=es-to-primitive 47 [downloads-image]: https://img.shields.io/npm/dm/es-to-primitive.svg 48 [downloads-url]: https://npm-stat.com/charts.html?package=es-to-primitive 49 [codecov-image]: https://codecov.io/gh/ljharb/es-to-primitive/branch/main/graphs/badge.svg 50 [codecov-url]: https://app.codecov.io/gh/ljharb/es-to-primitive/ 51 [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/es-to-primitive 52 [actions-url]: https://github.com/ljharb/es-to-primitive/actions -
imaps-frontend/node_modules/es-to-primitive/es2015.js
rd565449 r0c6b92a 8 8 var isSymbol = require('is-symbol'); 9 9 10 /** @type {(O: { valueOf?: () => unknown, toString?: () => unknown }, hint: 'number' | 'string' | 'default') => null | undefined | string | symbol | number | boolean | bigint} */ 10 11 var ordinaryToPrimitive = function OrdinaryToPrimitive(O, hint) { 11 12 if (typeof O === 'undefined' || O === null) { … … 15 16 throw new TypeError('hint must be "string" or "number"'); 16 17 } 18 /** @type {('toString' | 'valueOf')[]} */ 17 19 var methodNames = hint === 'string' ? ['toString', 'valueOf'] : ['valueOf', 'toString']; 18 20 var method, result, i; … … 29 31 }; 30 32 33 /** @type {<K extends PropertyKey>(O: Record<K, unknown>, P: K) => Function | undefined} */ 31 34 var GetMethod = function GetMethod(O, P) { 32 35 var func = O[P]; 33 36 if (func !== null && typeof func !== 'undefined') { 34 37 if (!isCallable(func)) { 35 throw new TypeError(func + ' returned for property ' + P+ ' of object ' + O + ' is not a function');38 throw new TypeError(func + ' returned for property ' + String(P) + ' of object ' + O + ' is not a function'); 36 39 } 37 40 return func; … … 40 43 }; 41 44 45 /** @type {import('./es2015')} */ 42 46 // http://www.ecma-international.org/ecma-262/6.0/#sec-toprimitive 43 47 module.exports = function ToPrimitive(input) { … … 45 49 return input; 46 50 } 51 /** @type {'default' | 'string' | 'number'} */ 47 52 var hint = 'default'; 48 53 if (arguments.length > 1) { … … 57 62 if (hasSymbols) { 58 63 if (Symbol.toPrimitive) { 59 exoticToPrim = GetMethod(input, Symbol.toPrimitive); 64 // eslint-disable-next-line no-extra-parens 65 exoticToPrim = GetMethod(/** @type {Record<PropertyKey, unknown>} */ (input), Symbol.toPrimitive); 60 66 } else if (isSymbol(input)) { 61 67 exoticToPrim = Symbol.prototype.valueOf; … … 72 78 hint = 'string'; 73 79 } 74 return ordinaryToPrimitive(input, hint === 'default' ? 'number' : hint); 80 // eslint-disable-next-line no-extra-parens 81 return ordinaryToPrimitive(/** @type {object} */ (input), hint === 'default' ? 'number' : hint); 75 82 }; -
imaps-frontend/node_modules/es-to-primitive/es5.js
rd565449 r0c6b92a 7 7 var isCallable = require('is-callable'); 8 8 9 /** @type {{ [k in `[[${string}]]`]: (O: { toString?: unknown, valueOf?: unknown }, actualHint?: StringConstructor | NumberConstructor) => null | undefined | string | symbol | number | boolean | bigint; }} */ 9 10 // http://ecma-international.org/ecma-262/5.1/#sec-8.12.8 10 11 var ES5internalSlots = { … … 18 19 19 20 if (actualHint === String || actualHint === Number) { 21 /** @type {('toString' | 'valueOf')[]} */ 20 22 var methods = actualHint === String ? ['toString', 'valueOf'] : ['valueOf', 'toString']; 21 23 var value, i; 22 24 for (i = 0; i < methods.length; ++i) { 23 if (isCallable(O[methods[i]])) { 24 value = O[methods[i]](); 25 var method = methods[i]; 26 if (isCallable(O[method])) { 27 // eslint-disable-next-line no-extra-parens 28 value = /** @type {Function} */ (O[method])(); 25 29 if (isPrimitive(value)) { 26 30 return value; … … 34 38 }; 35 39 40 /** @type {import('./es5')} */ 36 41 // http://ecma-international.org/ecma-262/5.1/#sec-9.1 37 42 module.exports = function ToPrimitive(input) { … … 40 45 } 41 46 if (arguments.length > 1) { 42 return ES5internalSlots['[[DefaultValue]]'](input, arguments[1]); 47 // eslint-disable-next-line no-extra-parens 48 return ES5internalSlots['[[DefaultValue]]'](/** @type {object} */ (input), arguments[1]); 43 49 } 44 return ES5internalSlots['[[DefaultValue]]'](input); 50 // eslint-disable-next-line no-extra-parens 51 return ES5internalSlots['[[DefaultValue]]'](/** @type {object} */ (input)); 45 52 }; -
imaps-frontend/node_modules/es-to-primitive/es6.js
rd565449 r0c6b92a 1 1 'use strict'; 2 2 3 /** @type {import('./es2015')} */ 3 4 module.exports = require('./es2015'); -
imaps-frontend/node_modules/es-to-primitive/helpers/isPrimitive.js
rd565449 r0c6b92a 1 1 'use strict'; 2 2 3 /** @type {(value: unknown) => value is null | undefined | string | symbol | number | boolean | bigint} */ 3 4 module.exports = function isPrimitive(value) { 4 5 return value === null || (typeof value !== 'function' && typeof value !== 'object'); -
imaps-frontend/node_modules/es-to-primitive/index.js
rd565449 r0c6b92a 10 10 Object.defineProperty(ES2015, 'ES2015', { enumerable: false, value: ES2015 }); 11 11 } else { 12 ES6.ES5 = ES5; 13 ES6.ES6 = ES6; 14 ES6.ES2015 = ES2015; 12 // @ts-expect-error TODO 13 ES2015.ES5 = ES5; 14 // @ts-expect-error TODO 15 ES2015.ES6 = ES6; 16 // @ts-expect-error TODO 17 ES2015.ES2015 = ES2015; 15 18 } 16 19 20 /** @type {import('.')} */ 17 21 module.exports = ES2015; -
imaps-frontend/node_modules/es-to-primitive/package.json
rd565449 r0c6b92a 1 1 { 2 2 "name": "es-to-primitive", 3 "version": "1. 2.1",3 "version": "1.3.0", 4 4 "author": "Jordan Harband <ljharb@gmail.com>", 5 5 "funding": { … … 10 10 "main": "index.js", 11 11 "scripts": { 12 "pretest": "npm run --silent lint", 13 "test": "npm run --silent tests-only", 14 "posttest": "npx aud", 15 "tests-only": "node --es-staging test", 16 "coverage": "covert test/*.js", 17 "coverage-quiet": "covert test/*.js --quiet", 18 "lint": "eslint ." 12 "prepack": "npmignore --auto --commentLines=autogenerated", 13 "prepublish": "not-in-publish || npm run prepublishOnly", 14 "prepublishOnly": "safe-publish-latest", 15 "pretest": "npm run lint", 16 "test": "npm run tests-only", 17 "posttest": "npx npm@'>=10.2' audit --production", 18 "tests-only": "nyc tape 'test/**/*.js'", 19 "lint": "eslint --ext=js,mjs .", 20 "postlint": "tsc && attw -P", 21 "version": "auto-changelog && git add CHANGELOG.md", 22 "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" 19 23 }, 20 24 "repository": { … … 41 45 ], 42 46 "dependencies": { 43 "is-callable": "^1. 1.4",44 "is-date-object": "^1.0. 1",45 "is-symbol": "^1.0. 2"47 "is-callable": "^1.2.7", 48 "is-date-object": "^1.0.5", 49 "is-symbol": "^1.0.4" 46 50 }, 47 51 "devDependencies": { 48 "@ljharb/eslint-config": "^15.0.0", 49 "covert": "^1.1.1", 50 "eslint": "^6.6.0", 51 "foreach": "^2.0.5", 52 "function.prototype.name": "^1.1.1", 53 "has-symbols": "^1.0.0", 54 "object-inspect": "^1.6.0", 55 "object-is": "^1.0.1", 56 "replace": "^1.1.1", 57 "semver": "^6.3.0", 58 "tape": "^4.11.0" 52 "@arethetypeswrong/cli": "^0.17.0", 53 "@ljharb/eslint-config": "^21.1.1", 54 "@ljharb/tsconfig": "^0.2.0", 55 "@types/for-each": "^0.3.3", 56 "@types/function.prototype.name": "^1.1.3", 57 "@types/is-callable": "^1.1.2", 58 "@types/is-date-object": "^1.0.4", 59 "@types/is-symbol": "^1.0.2", 60 "@types/object-inspect": "^1.13.0", 61 "@types/object-is": "^1.1.0", 62 "@types/tape": "^5.6.4", 63 "auto-changelog": "^2.5.0", 64 "encoding": "^0.1.13", 65 "es-value-fixtures": "^1.5.0", 66 "eslint": "=8.8.0", 67 "for-each": "^0.3.3", 68 "function.prototype.name": "^1.1.6", 69 "npmignore": "^0.3.1", 70 "nyc": "^10.3.2", 71 "object-inspect": "^1.13.3", 72 "object-is": "^1.1.6", 73 "safe-publish-latest": "^2.0.0", 74 "tape": "^5.9.0", 75 "typescript": "next" 59 76 }, 60 77 "testling": { 61 "files": "test", 62 "browsers": [ 63 "iexplore/6.0..latest", 64 "firefox/3.0..6.0", 65 "firefox/15.0..latest", 66 "firefox/nightly", 67 "chrome/4.0..10.0", 68 "chrome/20.0..latest", 69 "chrome/canary", 70 "opera/10.0..latest", 71 "opera/next", 72 "safari/4.0..latest", 73 "ipad/6.0..latest", 74 "iphone/6.0..latest", 75 "android-browser/4.2" 76 ] 78 "files": "test/index.js" 77 79 }, 78 80 "engines": { 79 81 "node": ">= 0.4" 82 }, 83 "auto-changelog": { 84 "output": "CHANGELOG.md", 85 "template": "keepachangelog", 86 "unreleased": false, 87 "commitLimit": false, 88 "backfillLimit": false, 89 "hideCredit": true, 90 "startingVersion": "1.2.2" 91 }, 92 "publishConfig": { 93 "ignore": [ 94 ".github/workflows" 95 ] 80 96 } 81 97 } -
imaps-frontend/node_modules/es-to-primitive/test/es2015.js
rd565449 r0c6b92a 4 4 var toPrimitive = require('../es2015'); 5 5 var is = require('object-is'); 6 var forEach = require('for each');6 var forEach = require('for-each'); 7 7 var functionName = require('function.prototype.name'); 8 8 var debug = require('object-inspect'); 9 var v = require('es-value-fixtures'); 9 10 10 var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol'; 11 var hasSymbolToPrimitive = hasSymbols && typeof Symbol.toPrimitive === 'symbol'; 11 /** @typedef {{ toString?: unknown, valueOf?: unknown, [Symbol.toPrimitive]?: unknown }} Coercible */ 12 12 13 13 test('function properties', function (t) { … … 18 18 }); 19 19 20 var primitives = [null, undefined, true, false, 0, -0, 42, NaN, Infinity, -Infinity, '', 'abc'];21 22 20 test('primitives', function (t) { 23 forEach( primitives, function (i) {21 forEach(v.primitives, function (i) { 24 22 t.ok(is(toPrimitive(i), i), 'toPrimitive(' + debug(i) + ') returns the same value'); 25 23 t.ok(is(toPrimitive(i, String), i), 'toPrimitive(' + debug(i) + ', String) returns the same value'); … … 29 27 }); 30 28 31 test('Symbols', { skip: !hasSymbols }, function (t) { 32 var symbols = [ 33 Symbol('foo'), 34 Symbol.iterator, 35 Symbol['for']('foo') // eslint-disable-line no-restricted-properties 36 ]; 37 forEach(symbols, function (sym) { 29 test('Symbols', { skip: !v.hasSymbols }, function (t) { 30 forEach(v.symbols, function (sym) { 38 31 t.equal(toPrimitive(sym), sym, 'toPrimitive(' + debug(sym) + ') returns the same value'); 39 32 t.equal(toPrimitive(sym, String), sym, 'toPrimitive(' + debug(sym) + ', String) returns the same value'); … … 69 62 }); 70 63 71 var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } }; 72 var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } }; 73 var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } }; 74 var coercibleFnObject = { 75 valueOf: function () { return function valueOfFn() {}; }, 76 toString: function () { return 42; } 77 }; 78 var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } }; 79 var uncoercibleFnObject = { 80 valueOf: function () { return function valueOfFn() {}; }, 81 toString: function () { return function toStrFn() {}; } 82 }; 64 test('Objects', function (t) { 65 t.equal(toPrimitive(v.coercibleObject), v.coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf'); 66 t.equal(toPrimitive(v.coercibleObject, Number), v.coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf'); 67 t.equal(toPrimitive(v.coercibleObject, String), v.coercibleObject.toString(), 'coercibleObject with hint String coerces to non-stringified toString'); 83 68 84 test('Objects', function (t) { 85 t.equal(toPrimitive(coercibleObject), coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf'); 86 t.equal(toPrimitive(coercibleObject, Number), coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf'); 87 t.equal(toPrimitive(coercibleObject, String), coercibleObject.toString(), 'coercibleObject with hint String coerces to non-stringified toString'); 88 89 t.equal(toPrimitive(coercibleFnObject), coercibleFnObject.toString(), 'coercibleFnObject coerces to non-stringified toString'); 90 t.equal(toPrimitive(coercibleFnObject, Number), coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to non-stringified toString'); 91 t.equal(toPrimitive(coercibleFnObject, String), coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to non-stringified toString'); 69 t.equal(toPrimitive(v.coercibleFnObject), v.coercibleFnObject.toString(), 'coercibleFnObject coerces to non-stringified toString'); 70 t.equal(toPrimitive(v.coercibleFnObject, Number), v.coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to non-stringified toString'); 71 t.equal(toPrimitive(v.coercibleFnObject, String), v.coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to non-stringified toString'); 92 72 93 73 t.equal(toPrimitive({}), '[object Object]', '{} with no hint coerces to Object#toString'); … … 95 75 t.equal(toPrimitive({}, String), '[object Object]', '{} with hint String coerces to Object#toString'); 96 76 97 t.equal(toPrimitive( toStringOnlyObject),toStringOnlyObject.toString(), 'toStringOnlyObject returns non-stringified toString');98 t.equal(toPrimitive( toStringOnlyObject, Number),toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns non-stringified toString');99 t.equal(toPrimitive( toStringOnlyObject, String),toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns non-stringified toString');77 t.equal(toPrimitive(v.toStringOnlyObject), v.toStringOnlyObject.toString(), 'toStringOnlyObject returns non-stringified toString'); 78 t.equal(toPrimitive(v.toStringOnlyObject, Number), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns non-stringified toString'); 79 t.equal(toPrimitive(v.toStringOnlyObject, String), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns non-stringified toString'); 100 80 101 t.equal(toPrimitive(v alueOfOnlyObject),valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');102 t.equal(toPrimitive(v alueOfOnlyObject, Number),valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');103 t.equal(toPrimitive(v alueOfOnlyObject, String),valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns non-stringified valueOf');81 t.equal(toPrimitive(v.valueOfOnlyObject), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf'); 82 t.equal(toPrimitive(v.valueOfOnlyObject, Number), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf'); 83 t.equal(toPrimitive(v.valueOfOnlyObject, String), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns non-stringified valueOf'); 104 84 105 t.test('Symbol.toPrimitive', { skip: !hasSymbolToPrimitive }, function (st) { 85 t.test('Symbol.toPrimitive', { skip: !v.hasSymbols || !Symbol.toPrimitive }, function (st) { 86 /** @type {Coercible} */ 106 87 var overriddenObject = { toString: st.fail, valueOf: st.fail }; 107 overriddenObject[Symbol.toPrimitive] = function (hint) { return String(hint); }; 88 overriddenObject[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) { 89 return String(hint); 90 }; 108 91 109 92 st.equal(toPrimitive(overriddenObject), 'default', 'object with Symbol.toPrimitive + no hint invokes that'); … … 111 94 st.equal(toPrimitive(overriddenObject, String), 'string', 'object with Symbol.toPrimitive + hint String invokes that'); 112 95 113 var nullToPrimitive = { toString: coercibleObject.toString, valueOf: coercibleObject.valueOf }; 96 /** @type {Coercible} */ 97 var nullToPrimitive = { toString: v.coercibleObject.toString, valueOf: v.coercibleObject.valueOf }; 114 98 nullToPrimitive[Symbol.toPrimitive] = null; 115 st.equal(toPrimitive(nullToPrimitive), toPrimitive( coercibleObject), 'object with no hint + null Symbol.toPrimitive ignores it');116 st.equal(toPrimitive(nullToPrimitive, Number), toPrimitive( coercibleObject, Number), 'object with hint Number + null Symbol.toPrimitive ignores it');117 st.equal(toPrimitive(nullToPrimitive, String), toPrimitive( coercibleObject, String), 'object with hint String + null Symbol.toPrimitive ignores it');99 st.equal(toPrimitive(nullToPrimitive), toPrimitive(v.coercibleObject), 'object with no hint + null Symbol.toPrimitive ignores it'); 100 st.equal(toPrimitive(nullToPrimitive, Number), toPrimitive(v.coercibleObject, Number), 'object with hint Number + null Symbol.toPrimitive ignores it'); 101 st.equal(toPrimitive(nullToPrimitive, String), toPrimitive(v.coercibleObject, String), 'object with hint String + null Symbol.toPrimitive ignores it'); 118 102 119 103 st.test('exceptions', function (sst) { 104 /** @type {Coercible} */ 120 105 var nonFunctionToPrimitive = { toString: sst.fail, valueOf: sst.fail }; 121 106 nonFunctionToPrimitive[Symbol.toPrimitive] = {}; 122 107 sst['throws'](toPrimitive.bind(null, nonFunctionToPrimitive), TypeError, 'Symbol.toPrimitive returning a non-function throws'); 123 108 109 /** @type {Coercible} */ 124 110 var uncoercibleToPrimitive = { toString: sst.fail, valueOf: sst.fail }; 125 uncoercibleToPrimitive[Symbol.toPrimitive] = function (hint) {111 uncoercibleToPrimitive[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) { 126 112 return { toString: function () { return hint; } }; 127 113 }; 128 114 sst['throws'](toPrimitive.bind(null, uncoercibleToPrimitive), TypeError, 'Symbol.toPrimitive returning an object throws'); 129 115 116 /** @type {Coercible} */ 130 117 var throwingToPrimitive = { toString: sst.fail, valueOf: sst.fail }; 131 throwingToPrimitive[Symbol.toPrimitive] = function (hint) { throw new RangeError(hint); }; 118 throwingToPrimitive[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) { 119 throw new RangeError(hint); 120 }; 132 121 sst['throws'](toPrimitive.bind(null, throwingToPrimitive), RangeError, 'Symbol.toPrimitive throwing throws'); 133 122 … … 139 128 140 129 t.test('exceptions', function (st) { 141 st['throws'](toPrimitive.bind(null, uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');142 st['throws'](toPrimitive.bind(null, uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');143 st['throws'](toPrimitive.bind(null, uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');130 st['throws'](toPrimitive.bind(null, v.uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError'); 131 st['throws'](toPrimitive.bind(null, v.uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError'); 132 st['throws'](toPrimitive.bind(null, v.uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError'); 144 133 145 st['throws'](toPrimitive.bind(null, uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');146 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');147 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');134 st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError'); 135 st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError'); 136 st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError'); 148 137 st.end(); 149 138 }); -
imaps-frontend/node_modules/es-to-primitive/test/es5.js
rd565449 r0c6b92a 4 4 var toPrimitive = require('../es5'); 5 5 var is = require('object-is'); 6 var forEach = require('for each');6 var forEach = require('for-each'); 7 7 var functionName = require('function.prototype.name'); 8 8 var debug = require('object-inspect'); 9 var hasSymbols = require('has-symbols')();9 var v = require('es-value-fixtures'); 10 10 11 11 test('function properties', function (t) { … … 16 16 }); 17 17 18 var primitives = [null, undefined, true, false, 0, -0, 42, NaN, Infinity, -Infinity, '', 'abc'];19 20 18 test('primitives', function (t) { 21 forEach( primitives, function (i) {19 forEach(v.primitives, function (i) { 22 20 t.ok(is(toPrimitive(i), i), 'toPrimitive(' + debug(i) + ') returns the same value'); 23 21 t.ok(is(toPrimitive(i, String), i), 'toPrimitive(' + debug(i) + ', String) returns the same value'); … … 27 25 }); 28 26 29 test('Symbols', { skip: !hasSymbols }, function (t) { 30 var symbols = [ 31 Symbol('foo'), 32 Symbol.iterator, 33 Symbol['for']('foo') // eslint-disable-line no-restricted-properties 34 ]; 35 forEach(symbols, function (sym) { 27 test('Symbols', { skip: !v.hasSymbols }, function (t) { 28 forEach(v.symbols, function (sym) { 36 29 t.equal(toPrimitive(sym), sym, 'toPrimitive(' + debug(sym) + ') returns the same value'); 37 30 t.equal(toPrimitive(sym, String), sym, 'toPrimitive(' + debug(sym) + ', String) returns the same value'); … … 70 63 }); 71 64 72 var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } }; 73 var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } }; 74 var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } }; 75 var coercibleFnObject = { 76 valueOf: function () { return function valueOfFn() {}; }, 77 toString: function () { return 42; } 78 }; 79 var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } }; 80 var uncoercibleFnObject = { 81 valueOf: function () { return function valueOfFn() {}; }, 82 toString: function () { return function toStrFn() {}; } 83 }; 65 test('Objects', function (t) { 66 t.equal(toPrimitive(v.coercibleObject), v.coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf'); 67 t.equal(toPrimitive(v.coercibleObject, String), v.coercibleObject.toString(), 'coercibleObject with hint String coerces to toString'); 68 t.equal(toPrimitive(v.coercibleObject, Number), v.coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf'); 84 69 85 test('Objects', function (t) { 86 t.equal(toPrimitive(coercibleObject), coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf'); 87 t.equal(toPrimitive(coercibleObject, String), coercibleObject.toString(), 'coercibleObject with hint String coerces to toString'); 88 t.equal(toPrimitive(coercibleObject, Number), coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf'); 89 90 t.equal(toPrimitive(coercibleFnObject), coercibleFnObject.toString(), 'coercibleFnObject coerces to toString'); 91 t.equal(toPrimitive(coercibleFnObject, String), coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to toString'); 92 t.equal(toPrimitive(coercibleFnObject, Number), coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to toString'); 70 t.equal(toPrimitive(v.coercibleFnObject), v.coercibleFnObject.toString(), 'coercibleFnObject coerces to toString'); 71 t.equal(toPrimitive(v.coercibleFnObject, String), v.coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to toString'); 72 t.equal(toPrimitive(v.coercibleFnObject, Number), v.coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to toString'); 93 73 94 74 t.ok(is(toPrimitive({}), '[object Object]'), '{} with no hint coerces to Object#toString'); … … 96 76 t.ok(is(toPrimitive({}, Number), '[object Object]'), '{} with hint Number coerces to Object#toString'); 97 77 98 t.equal(toPrimitive( toStringOnlyObject),toStringOnlyObject.toString(), 'toStringOnlyObject returns toString');99 t.equal(toPrimitive( toStringOnlyObject, String),toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns toString');100 t.equal(toPrimitive( toStringOnlyObject, Number),toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns toString');78 t.equal(toPrimitive(v.toStringOnlyObject), v.toStringOnlyObject.toString(), 'toStringOnlyObject returns toString'); 79 t.equal(toPrimitive(v.toStringOnlyObject, String), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns toString'); 80 t.equal(toPrimitive(v.toStringOnlyObject, Number), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns toString'); 101 81 102 t.equal(toPrimitive(v alueOfOnlyObject),valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');103 t.equal(toPrimitive(v alueOfOnlyObject, String),valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns valueOf');104 t.equal(toPrimitive(v alueOfOnlyObject, Number),valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');82 t.equal(toPrimitive(v.valueOfOnlyObject), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf'); 83 t.equal(toPrimitive(v.valueOfOnlyObject, String), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns valueOf'); 84 t.equal(toPrimitive(v.valueOfOnlyObject, Number), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf'); 105 85 106 86 t.test('exceptions', function (st) { 107 st['throws'](toPrimitive.bind(null, uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');108 st['throws'](toPrimitive.bind(null, uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');109 st['throws'](toPrimitive.bind(null, uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');87 st['throws'](toPrimitive.bind(null, v.uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError'); 88 st['throws'](toPrimitive.bind(null, v.uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError'); 89 st['throws'](toPrimitive.bind(null, v.uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError'); 110 90 111 st['throws'](toPrimitive.bind(null, uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');112 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');113 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');91 st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError'); 92 st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError'); 93 st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError'); 114 94 st.end(); 115 95 }); -
imaps-frontend/node_modules/es-to-primitive/test/es6.js
rd565449 r0c6b92a 4 4 var toPrimitive = require('../es6'); 5 5 var is = require('object-is'); 6 var forEach = require('for each');6 var forEach = require('for-each'); 7 7 var functionName = require('function.prototype.name'); 8 8 var debug = require('object-inspect'); 9 var v = require('es-value-fixtures'); 9 10 10 var hasSymbols = require('has-symbols')(); 11 var hasSymbolToPrimitive = hasSymbols && typeof Symbol.toPrimitive === 'symbol'; 11 /** @typedef {{ toString?: unknown, valueOf?: unknown, [Symbol.toPrimitive]?: unknown }} Coercible */ 12 12 13 13 test('function properties', function (t) { … … 18 18 }); 19 19 20 var primitives = [null, undefined, true, false, 0, -0, 42, NaN, Infinity, -Infinity, '', 'abc'];21 22 20 test('primitives', function (t) { 23 forEach( primitives, function (i) {21 forEach(v.primitives, function (i) { 24 22 t.ok(is(toPrimitive(i), i), 'toPrimitive(' + debug(i) + ') returns the same value'); 25 23 t.ok(is(toPrimitive(i, String), i), 'toPrimitive(' + debug(i) + ', String) returns the same value'); … … 29 27 }); 30 28 31 test('Symbols', { skip: !hasSymbols }, function (t) { 32 var symbols = [ 33 Symbol('foo'), 34 Symbol.iterator, 35 Symbol['for']('foo') // eslint-disable-line no-restricted-properties 36 ]; 37 forEach(symbols, function (sym) { 29 test('Symbols', { skip: !v.hasSymbols }, function (t) { 30 forEach(v.symbols, function (sym) { 38 31 t.equal(toPrimitive(sym), sym, 'toPrimitive(' + debug(sym) + ') returns the same value'); 39 32 t.equal(toPrimitive(sym, String), sym, 'toPrimitive(' + debug(sym) + ', String) returns the same value'); … … 69 62 }); 70 63 71 var coercibleObject = { valueOf: function () { return 3; }, toString: function () { return 42; } }; 72 var valueOfOnlyObject = { valueOf: function () { return 4; }, toString: function () { return {}; } }; 73 var toStringOnlyObject = { valueOf: function () { return {}; }, toString: function () { return 7; } }; 74 var coercibleFnObject = { 75 valueOf: function () { return function valueOfFn() {}; }, 76 toString: function () { return 42; } 77 }; 78 var uncoercibleObject = { valueOf: function () { return {}; }, toString: function () { return {}; } }; 79 var uncoercibleFnObject = { 80 valueOf: function () { return function valueOfFn() {}; }, 81 toString: function () { return function toStrFn() {}; } 82 }; 64 test('Objects', function (t) { 65 t.equal(toPrimitive(v.coercibleObject), v.coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf'); 66 t.equal(toPrimitive(v.coercibleObject, Number), v.coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf'); 67 t.equal(toPrimitive(v.coercibleObject, String), v.coercibleObject.toString(), 'coercibleObject with hint String coerces to non-stringified toString'); 83 68 84 test('Objects', function (t) { 85 t.equal(toPrimitive(coercibleObject), coercibleObject.valueOf(), 'coercibleObject with no hint coerces to valueOf'); 86 t.equal(toPrimitive(coercibleObject, Number), coercibleObject.valueOf(), 'coercibleObject with hint Number coerces to valueOf'); 87 t.equal(toPrimitive(coercibleObject, String), coercibleObject.toString(), 'coercibleObject with hint String coerces to non-stringified toString'); 88 89 t.equal(toPrimitive(coercibleFnObject), coercibleFnObject.toString(), 'coercibleFnObject coerces to non-stringified toString'); 90 t.equal(toPrimitive(coercibleFnObject, Number), coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to non-stringified toString'); 91 t.equal(toPrimitive(coercibleFnObject, String), coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to non-stringified toString'); 69 t.equal(toPrimitive(v.coercibleFnObject), v.coercibleFnObject.toString(), 'coercibleFnObject coerces to non-stringified toString'); 70 t.equal(toPrimitive(v.coercibleFnObject, Number), v.coercibleFnObject.toString(), 'coercibleFnObject with hint Number coerces to non-stringified toString'); 71 t.equal(toPrimitive(v.coercibleFnObject, String), v.coercibleFnObject.toString(), 'coercibleFnObject with hint String coerces to non-stringified toString'); 92 72 93 73 t.equal(toPrimitive({}), '[object Object]', '{} with no hint coerces to Object#toString'); … … 95 75 t.equal(toPrimitive({}, String), '[object Object]', '{} with hint String coerces to Object#toString'); 96 76 97 t.equal(toPrimitive( toStringOnlyObject),toStringOnlyObject.toString(), 'toStringOnlyObject returns non-stringified toString');98 t.equal(toPrimitive( toStringOnlyObject, Number),toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns non-stringified toString');99 t.equal(toPrimitive( toStringOnlyObject, String),toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns non-stringified toString');77 t.equal(toPrimitive(v.toStringOnlyObject), v.toStringOnlyObject.toString(), 'toStringOnlyObject returns non-stringified toString'); 78 t.equal(toPrimitive(v.toStringOnlyObject, Number), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint Number returns non-stringified toString'); 79 t.equal(toPrimitive(v.toStringOnlyObject, String), v.toStringOnlyObject.toString(), 'toStringOnlyObject with hint String returns non-stringified toString'); 100 80 101 t.equal(toPrimitive(v alueOfOnlyObject),valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf');102 t.equal(toPrimitive(v alueOfOnlyObject, Number),valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf');103 t.equal(toPrimitive(v alueOfOnlyObject, String),valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns non-stringified valueOf');81 t.equal(toPrimitive(v.valueOfOnlyObject), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject returns valueOf'); 82 t.equal(toPrimitive(v.valueOfOnlyObject, Number), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint Number returns valueOf'); 83 t.equal(toPrimitive(v.valueOfOnlyObject, String), v.valueOfOnlyObject.valueOf(), 'valueOfOnlyObject with hint String returns non-stringified valueOf'); 104 84 105 t.test('Symbol.toPrimitive', { skip: !hasSymbolToPrimitive }, function (st) { 85 t.test('Symbol.toPrimitive', { skip: !v.hasSymbols || !Symbol.toPrimitive }, function (st) { 86 /** @type {Coercible} */ 106 87 var overriddenObject = { toString: st.fail, valueOf: st.fail }; 107 overriddenObject[Symbol.toPrimitive] = function (hint) { return String(hint); }; 88 overriddenObject[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) { 89 return String(hint); 90 }; 108 91 109 92 st.equal(toPrimitive(overriddenObject), 'default', 'object with Symbol.toPrimitive + no hint invokes that'); … … 111 94 st.equal(toPrimitive(overriddenObject, String), 'string', 'object with Symbol.toPrimitive + hint String invokes that'); 112 95 113 var nullToPrimitive = { toString: coercibleObject.toString, valueOf: coercibleObject.valueOf }; 96 /** @type {Coercible} */ 97 var nullToPrimitive = { toString: v.coercibleObject.toString, valueOf: v.coercibleObject.valueOf }; 114 98 nullToPrimitive[Symbol.toPrimitive] = null; 115 st.equal(toPrimitive(nullToPrimitive), toPrimitive( coercibleObject), 'object with no hint + null Symbol.toPrimitive ignores it');116 st.equal(toPrimitive(nullToPrimitive, Number), toPrimitive( coercibleObject, Number), 'object with hint Number + null Symbol.toPrimitive ignores it');117 st.equal(toPrimitive(nullToPrimitive, String), toPrimitive( coercibleObject, String), 'object with hint String + null Symbol.toPrimitive ignores it');99 st.equal(toPrimitive(nullToPrimitive), toPrimitive(v.coercibleObject), 'object with no hint + null Symbol.toPrimitive ignores it'); 100 st.equal(toPrimitive(nullToPrimitive, Number), toPrimitive(v.coercibleObject, Number), 'object with hint Number + null Symbol.toPrimitive ignores it'); 101 st.equal(toPrimitive(nullToPrimitive, String), toPrimitive(v.coercibleObject, String), 'object with hint String + null Symbol.toPrimitive ignores it'); 118 102 119 103 st.test('exceptions', function (sst) { 104 /** @type {Coercible} */ 120 105 var nonFunctionToPrimitive = { toString: sst.fail, valueOf: sst.fail }; 121 106 nonFunctionToPrimitive[Symbol.toPrimitive] = {}; 122 107 sst['throws'](toPrimitive.bind(null, nonFunctionToPrimitive), TypeError, 'Symbol.toPrimitive returning a non-function throws'); 123 108 109 /** @type {Coercible} */ 124 110 var uncoercibleToPrimitive = { toString: sst.fail, valueOf: sst.fail }; 125 uncoercibleToPrimitive[Symbol.toPrimitive] = function (hint) {111 uncoercibleToPrimitive[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) { 126 112 return { toString: function () { return hint; } }; 127 113 }; 128 114 sst['throws'](toPrimitive.bind(null, uncoercibleToPrimitive), TypeError, 'Symbol.toPrimitive returning an object throws'); 129 115 116 /** @type {Coercible} */ 130 117 var throwingToPrimitive = { toString: sst.fail, valueOf: sst.fail }; 131 throwingToPrimitive[Symbol.toPrimitive] = function (hint) { throw new RangeError(hint); }; 118 throwingToPrimitive[Symbol.toPrimitive] = /** @type {(hint: string) => unknown} */ function (hint) { 119 throw new RangeError(hint); 120 }; 132 121 sst['throws'](toPrimitive.bind(null, throwingToPrimitive), RangeError, 'Symbol.toPrimitive throwing throws'); 133 122 … … 139 128 140 129 t.test('exceptions', function (st) { 141 st['throws'](toPrimitive.bind(null, uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError');142 st['throws'](toPrimitive.bind(null, uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError');143 st['throws'](toPrimitive.bind(null, uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError');130 st['throws'](toPrimitive.bind(null, v.uncoercibleObject), TypeError, 'uncoercibleObject throws a TypeError'); 131 st['throws'](toPrimitive.bind(null, v.uncoercibleObject, Number), TypeError, 'uncoercibleObject with hint Number throws a TypeError'); 132 st['throws'](toPrimitive.bind(null, v.uncoercibleObject, String), TypeError, 'uncoercibleObject with hint String throws a TypeError'); 144 133 145 st['throws'](toPrimitive.bind(null, uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError');146 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError');147 st['throws'](toPrimitive.bind(null, uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError');134 st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject), TypeError, 'uncoercibleFnObject throws a TypeError'); 135 st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, Number), TypeError, 'uncoercibleFnObject with hint Number throws a TypeError'); 136 st['throws'](toPrimitive.bind(null, v.uncoercibleFnObject, String), TypeError, 'uncoercibleFnObject with hint String throws a TypeError'); 148 137 st.end(); 149 138 });
Note:
See TracChangeset
for help on using the changeset viewer.