save code
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"root": true,
|
||||
|
||||
"extends": "@ljharb",
|
||||
|
||||
"rules": {
|
||||
"id-length": "off",
|
||||
"new-cap": ["error", {
|
||||
"capIsNewExceptions": [
|
||||
"GetIntrinsic"
|
||||
],
|
||||
}],
|
||||
"no-extra-parens": "off",
|
||||
},
|
||||
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["test/**/*.js"],
|
||||
"rules": {
|
||||
"id-length": "off",
|
||||
"max-lines-per-function": "off",
|
||||
"multiline-comment-style": "off",
|
||||
"no-empty-function": "off",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"all": true,
|
||||
"check-coverage": false,
|
||||
"reporter": ["text-summary", "text", "html", "json"],
|
||||
"lines": 86,
|
||||
"statements": 85.93,
|
||||
"functions": 82.43,
|
||||
"branches": 76.06,
|
||||
"exclude": [
|
||||
"coverage",
|
||||
"test"
|
||||
]
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Jordan Harband and contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
var gOPD = require('gopd');
|
||||
var bind = require('function-bind');
|
||||
|
||||
var unbound = gOPD && gOPD(function () {}, 'length');
|
||||
// @ts-expect-error ts(2555) TS is overly strict with .call
|
||||
var bound = gOPD && gOPD(bind.call(function () {}), 'length');
|
||||
|
||||
var functionsHaveConfigurableLengths = !!(unbound && unbound.configurable);
|
||||
|
||||
var functionsHaveWritableLengths = !!(unbound && unbound.writable);
|
||||
|
||||
var boundFnsHaveConfigurableLengths = !!(bound && bound.configurable);
|
||||
|
||||
var boundFnsHaveWritableLengths = !!(bound && bound.writable);
|
||||
|
||||
/** @type {import('./env')} */
|
||||
module.exports = {
|
||||
__proto__: null,
|
||||
boundFnsHaveConfigurableLengths: boundFnsHaveConfigurableLengths,
|
||||
boundFnsHaveWritableLengths: boundFnsHaveWritableLengths,
|
||||
functionsHaveConfigurableLengths: functionsHaveConfigurableLengths,
|
||||
functionsHaveWritableLengths: functionsHaveWritableLengths
|
||||
};
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
var GetIntrinsic = require('get-intrinsic');
|
||||
var define = require('define-data-property');
|
||||
var hasDescriptors = require('has-property-descriptors')();
|
||||
var gOPD = require('gopd');
|
||||
|
||||
var $TypeError = require('es-errors/type');
|
||||
var $floor = GetIntrinsic('%Math.floor%');
|
||||
|
||||
/** @type {import('.')} */
|
||||
module.exports = function setFunctionLength(fn, length) {
|
||||
if (typeof fn !== 'function') {
|
||||
throw new $TypeError('`fn` is not a function');
|
||||
}
|
||||
if (typeof length !== 'number' || length < 0 || length > 0xFFFFFFFF || $floor(length) !== length) {
|
||||
throw new $TypeError('`length` must be a positive 32-bit integer');
|
||||
}
|
||||
|
||||
var loose = arguments.length > 2 && !!arguments[2];
|
||||
|
||||
var functionLengthIsConfigurable = true;
|
||||
var functionLengthIsWritable = true;
|
||||
if ('length' in fn && gOPD) {
|
||||
var desc = gOPD(fn, 'length');
|
||||
if (desc && !desc.configurable) {
|
||||
functionLengthIsConfigurable = false;
|
||||
}
|
||||
if (desc && !desc.writable) {
|
||||
functionLengthIsWritable = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (functionLengthIsConfigurable || functionLengthIsWritable || !loose) {
|
||||
if (hasDescriptors) {
|
||||
define(/** @type {Parameters<define>[0]} */ (fn), 'length', length, true, true);
|
||||
} else {
|
||||
define(/** @type {Parameters<define>[0]} */ (fn), 'length', length);
|
||||
}
|
||||
}
|
||||
return fn;
|
||||
};
|
||||
Reference in New Issue
Block a user