construct-new 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +1 -41
  2. package/package.json +4 -14
package/index.js CHANGED
@@ -1,18 +1,3 @@
1
- var noop = require('noop6')
2
- var emptyArray = []
3
- var { immediateError, ErrorType } = require('immediate-error')
4
- var isNullOrUndefined = require('is-nil')
5
- var isES2015 = require('is-es2015')
6
- var isConstructable = require('is-constructable').isConstructable
7
- var isArray = require('isarray')
8
- var isArguments = require('is-arguments')
9
- var isFunction = require('is-function')
10
- var t = require('true-value')
11
- var myTrueValue = t()
12
- var _return = require('@_immo/return')
13
- var intrinsic = require('get-intrinsic')
14
- var reflectconstruct = intrinsic('%Reflect.construct%')
15
- var objcreate = intrinsic('%Object.create%')
16
1
 
17
2
  function construct({
18
3
  target,
@@ -20,32 +5,7 @@ function construct({
20
5
  newTarget,
21
6
  callback
22
7
  }) {
23
- if (isNullOrUndefined(target)) {
24
- immediateError("Target cannot be null when constructing a new instance of an object.", ErrorType.TypeError)
25
- }
26
- if (isNullOrUndefined(args)) args = emptyArray
27
- if (isNullOrUndefined(newTarget)) newTarget = target
28
- if (isNullOrUndefined(callback)) callback = noop
29
- if (!isConstructable(target)) {
30
- immediateError("Target must be callable with the new operator when constructing a new instance of an object.", ErrorType.TypeError)
31
- }
32
- if (!isArray(args) && !isArguments(args)) {
33
- immediateError("Arguments must be an array or arguments object.", ErrorType.TypeError)
34
- }
35
- if (!isConstructable(newTarget)) {
36
- immediateError("newTarget must be callable with the new operator when constructing a new instance of an object if it is specified.", ErrorType.TypeError)
37
- }
38
- if (!isFunction(callback)) {
39
- immediateError("Callback must be a function when constructing a new instance of an object if it is specified.", ErrorType.TypeError)
40
- }
41
- var result
42
- if (isES2015 === myTrueValue) {
43
- result = reflectconstruct(target, args, newTarget)
44
- } else {
45
- result = target.apply(objcreate(target.prototype), args)
46
- }
47
- callback(result)
48
- return _return(result)
8
+ return require("construct-new-second")(target, args, newTarget, callback)
49
9
  }
50
10
 
51
11
  module.exports = construct
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "construct-new",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "Like the new operator, but a function.",
5
5
  "main": "index.js",
6
6
  "scripts": {},
@@ -16,24 +16,14 @@
16
16
  ],
17
17
  "author": "tj-commits",
18
18
  "license": "MIT",
19
- "dependencies": {
20
- "@_immo/return": "^1.1.1",
21
- "get-intrinsic": "^1.3.1",
22
- "immediate-error": "^6.3.0",
23
- "is-arguments": "^1.1.1",
24
- "is-constructable": "^1.0.0",
25
- "is-es2015": "^0.1.6",
26
- "is-function": "^1.0.2",
27
- "is-nil": "^1.0.1",
28
- "isarray": "^2.0.5",
29
- "noop6": "^1.0.9",
30
- "true-value": "^2.0.5"
31
- },
32
19
  "devDependencies": {
33
20
  "@types/node": "^22.5.5"
34
21
  },
35
22
  "repository": {
36
23
  "type": "git",
37
24
  "url": "https://github.com/10xEngineersQualityProgramming/construct-new.git"
25
+ },
26
+ "dependencies": {
27
+ "construct-new-second": "^1.0.0"
38
28
  }
39
29
  }