caller-arguments 1.0.0

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 (4) hide show
  1. package/README.md +15 -0
  2. package/index.js +8 -0
  3. package/package.json +17 -0
  4. package/test.js +8 -0
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # caller-arguments
2
+ Returns the arguments of the caller.
3
+
4
+ ## Usage
5
+
6
+ ```js
7
+ const args = require('caller-arguments')
8
+ function foo() {
9
+ console.log(args())
10
+ }
11
+
12
+ foo('bar') // outputs "[Arguments] { '0': 'bar' }"
13
+ ```
14
+
15
+ If your file is in strict mode or you try to call `args()` in an arrow function, it will not work and instead throw an error.
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = function args(returnArray) {
2
+ try {
3
+ var callerArguments = args.caller.arguments
4
+ return returnArray ? Array.from(callerArguments) : callerArguments
5
+ } catch {
6
+ throw new Error('caller-arguments cannot be used with arrow functions or in strict mode')
7
+ }
8
+ }
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "caller-arguments",
3
+ "version": "1.0.0",
4
+ "description": "Function that returns the arguments passed into its caller.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [
10
+ "stupid"
11
+ ],
12
+ "author": "me",
13
+ "license": "MIT",
14
+ "dependencies": {
15
+ "is-equal": "^1.7.0"
16
+ }
17
+ }
package/test.js ADDED
@@ -0,0 +1,8 @@
1
+ var args = require('./index')
2
+ var assert = require('node:assert')
3
+ var isEqual = require('is-equal')
4
+
5
+ assert(args()['1'] === require, 'tests failed')
6
+ ;(function() {
7
+ assert(isEqual(Array.from(args()), [1, 2, 3]), 'tests failed')
8
+ })(1, 2, 3)