PHP 7.4.33
Preview: index.js Size: 1.24 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/set-function-length/index.js
'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;
};

Directory Contents

Dirs: 1 × Files: 11
Name Size Perms Modified Actions
.github DIR
- drwxr-xr-x 2025-03-28 11:04:36
Edit Download
404 B lrw-r--r-- 2025-03-28 11:04:36
Edit Download
216 B lrw-r--r-- 2025-03-28 11:04:36
Edit Download
4.76 KB lrw-r--r-- 2025-03-28 11:04:36
Edit Download
222 B lrw-r--r-- 2025-03-28 11:04:36
Edit Download
867 B lrw-r--r-- 2025-03-28 11:04:36
Edit Download
256 B lrw-r--r-- 2025-03-28 11:04:36
Edit Download
1.24 KB lrw-r--r-- 2025-03-28 11:04:36
Edit Download
1.06 KB lrw-r--r-- 2025-03-28 11:04:36
Edit Download
2.64 KB lrw-r--r-- 2025-03-28 11:04:36
Edit Download
2.12 KB lrw-r--r-- 2025-03-28 11:04:36
Edit Download
116 B lrw-r--r-- 2025-03-28 11:04:36
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).