construct-new 2.0.4 → 2.0.6

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 (3) hide show
  1. package/index.d.ts +1 -3
  2. package/index.js +10 -7
  3. package/package.json +9 -5
package/index.d.ts CHANGED
@@ -5,6 +5,4 @@ type ConstructOptions = {
5
5
  callback: () => void
6
6
  }
7
7
 
8
- function construct(options: ConstructOptions): any
9
-
10
- export = construct
8
+ export default function construct(options: ConstructOptions): any
package/index.js CHANGED
@@ -9,10 +9,13 @@ var isArguments = require('is-arguments')
9
9
  var isFunction = require('is-function')
10
10
  var t = require('true-value')
11
11
  var myTrueValue = t()
12
- var _return = require('@_immo/return')
13
- var intrinsic = require('get-intrinsic')
12
+ var _return = require('identity-function')
13
+ var intrinsic = require('es-intrinsic-cache')
14
14
  var reflectconstruct = intrinsic('%Reflect.construct%')
15
15
  var objcreate = intrinsic('%Object.create%')
16
+ var and = require("es-logical-and-operator")
17
+ var not = require("es-logical-not-operator")
18
+ var isEqual = require("@10xly/strict-equals")
16
19
 
17
20
  function construct({
18
21
  target,
@@ -26,20 +29,20 @@ function construct({
26
29
  if (isNullOrUndefined(args)) args = emptyArray
27
30
  if (isNullOrUndefined(newTarget)) newTarget = target
28
31
  if (isNullOrUndefined(callback)) callback = noop
29
- if (!isConstructable(target)) {
32
+ if (not(isConstructable(target))) {
30
33
  immediateError("Target must be callable with the new operator when constructing a new instance of an object.", ErrorType.TypeError)
31
34
  }
32
- if (!isArray(args) && !isArguments(args)) {
35
+ if (and(not(isArray(args)), not(isArguments(args)))) {
33
36
  immediateError("Arguments must be an array or arguments object.", ErrorType.TypeError)
34
37
  }
35
- if (!isConstructable(newTarget)) {
38
+ if (not(isConstructable(newTarget))) {
36
39
  immediateError("newTarget must be callable with the new operator when constructing a new instance of an object if it is specified.", ErrorType.TypeError)
37
40
  }
38
- if (!isFunction(callback)) {
41
+ if (not(isFunction(callback))) {
39
42
  immediateError("Callback must be a function when constructing a new instance of an object if it is specified.", ErrorType.TypeError)
40
43
  }
41
44
  var result
42
- if (isES2015 === myTrueValue) {
45
+ if (isEqual(isES2015, myTrueValue)) {
43
46
  result = reflectconstruct(target, args, newTarget)
44
47
  } else {
45
48
  result = target.apply(objcreate(target.prototype), args)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "construct-new",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "Like the new operator, but a function.",
5
5
  "main": "index.js",
6
6
  "scripts": {},
@@ -17,8 +17,11 @@
17
17
  "author": "tj-commits",
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
- "@_immo/return": "^1.1.1",
21
- "get-intrinsic": "^1.3.1",
20
+ "construct-new-second": "^1.0.1",
21
+ "es-intrinsic-cache": "^1.0.4",
22
+ "es-logical-and-operator": "^1.0.0",
23
+ "es-logical-not-operator": "^1.0.0",
24
+ "identity-function": "^1.0.0",
22
25
  "immediate-error": "^6.3.0",
23
26
  "is-arguments": "^1.1.1",
24
27
  "is-constructable": "^1.0.0",
@@ -26,8 +29,9 @@
26
29
  "is-function": "^1.0.2",
27
30
  "is-nil": "^1.0.1",
28
31
  "isarray": "^2.0.5",
29
- "noop6": "^1.0.9",
30
- "true-value": "^2.0.5"
32
+ "lodash.stubarray": "^4.13.0",
33
+ "node-call.next": "^1.0.1",
34
+ "noop6": "^1.0.9"
31
35
  },
32
36
  "devDependencies": {
33
37
  "@types/node": "^22.5.5"