uncurried-intrinsics 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 (3) hide show
  1. package/README.md +91 -0
  2. package/index.js +32 -0
  3. package/package.json +33 -0
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # uncurry-intrinsics
2
+
3
+ Get an uncurried version of an intrinsic function by name.
4
+
5
+ ## Description
6
+
7
+ Combines `es-intrinsic-cache` and `uncurry-x` to get and uncurry JavaScript intrinsics in one step.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install uncurry-intrinsics
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```javascript
18
+ var uncurryIntrinsic = require("uncurry-intrinsics");
19
+
20
+ // Get uncurried Array.prototype.slice
21
+ var slice = uncurryIntrinsic("Array.prototype.slice");
22
+ slice([1, 2, 3, 4, 5], 1, 3); // [2, 3]
23
+
24
+ // Get uncurried String.prototype.split
25
+ var split = uncurryIntrinsic("String.prototype.split");
26
+ split("foo-bar-baz", "-"); // ["foo", "bar", "baz"]
27
+
28
+ // Get uncurried Array.prototype.map
29
+ var map = uncurryIntrinsic("Array.prototype.map");
30
+ var doubled = map([1, 2, 3], function(x) { return x * 2; }); // [2, 4, 6]
31
+ ```
32
+
33
+ ## API
34
+
35
+ ### `uncurryIntrinsic(intrinsicName)`
36
+
37
+ Gets an intrinsic by name and returns its uncurried version where `this` becomes the first parameter.
38
+
39
+ **Parameters:**
40
+ - `intrinsicName` (string): The name of the intrinsic to get and uncurry (e.g., `"Array.prototype.slice"`)
41
+
42
+ **Returns:**
43
+ - (Function): The uncurried intrinsic function
44
+
45
+ ## Examples
46
+
47
+ ### Array methods
48
+
49
+ ```javascript
50
+ var uncurryIntrinsic = require("uncurry-intrinsics");
51
+
52
+ var push = uncurryIntrinsic("Array.prototype.push");
53
+ var join = uncurryIntrinsic("Array.prototype.join");
54
+
55
+ var arr = [1, 2, 3];
56
+ push(arr, 4, 5); // 5
57
+ join(arr, ", "); // "1, 2, 3, 4, 5"
58
+ ```
59
+
60
+ ### String methods
61
+
62
+ ```javascript
63
+ var uncurryIntrinsic = require("uncurry-intrinsics");
64
+
65
+ var charAt = uncurryIntrinsic("String.prototype.charAt");
66
+ var toUpperCase = uncurryIntrinsic("String.prototype.toUpperCase");
67
+
68
+ charAt("hello", 0); // "h"
69
+ toUpperCase("hello"); // "HELLO"
70
+ ```
71
+
72
+ ### Object methods
73
+
74
+ ```javascript
75
+ var uncurryIntrinsic = require("uncurry-intrinsics");
76
+
77
+ var hasOwnProperty = uncurryIntrinsic("Object.prototype.hasOwnProperty");
78
+
79
+ var obj = { foo: 1, bar: 2 };
80
+ hasOwnProperty(obj, "foo"); // true
81
+ hasOwnProperty(obj, "baz"); // false
82
+ ```
83
+
84
+ ## See Also
85
+
86
+ - [uncurry-x](https://www.npmjs.com/package/uncurry-x) - Uncurry a function
87
+ - [es-intrinsic-cache](https://www.npmjs.com/package/es-intrinsic-cache) - Get cached JavaScript intrinsics
88
+
89
+ ## License
90
+
91
+ MIT
package/index.js ADDED
@@ -0,0 +1,32 @@
1
+ "use strict"
2
+
3
+ var GetIntrinsic = require("es-intrinsic-cache")
4
+ var uncurryThis = require("uncurry-x")
5
+
6
+ /**
7
+ * Gets an intrinsic and returns its uncurried version
8
+ * @param {string} intrinsicName - The name of the intrinsic (e.g., "Array.prototype.slice")
9
+ * @param {boolean} allowMissing - Whether to allow missing intrinsics
10
+ * @returns {Function} The uncurried intrinsic function
11
+ */
12
+ function uncurryIntrinsic(intrinsicName, allowMissing) {
13
+ var intrinsic
14
+ try {
15
+ intrinsic = GetIntrinsic(intrinsicName, allowMissing)
16
+ } catch (e) {
17
+ throw new Error(
18
+ 'Failed to get intrinsic "' + intrinsicName + '": ' + e.message
19
+ )
20
+ }
21
+
22
+ if (!intrinsic) {
23
+ if (allowMissing) {
24
+ return intrinsic
25
+ }
26
+ throw new Error('Intrinsic "' + intrinsicName + '" is not available')
27
+ }
28
+
29
+ return uncurryThis(intrinsic)
30
+ }
31
+
32
+ module.exports = uncurryIntrinsic
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "uncurried-intrinsics",
3
+ "version": "1.0.0",
4
+ "description": "Combines es-intrinsic-cache and uncurry-x to get and uncurry JavaScript intrinsics in one step",
5
+ "keywords": [
6
+ "intrinsics",
7
+ "uncurried",
8
+ "cache",
9
+ "es",
10
+ "call-bind",
11
+ "call-bound",
12
+ "intrinsic"
13
+ ],
14
+ "homepage": "https://github.com/xsfj/uncurried-intrinsics#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/xsfj/uncurried-intrinsics/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/xsfj/uncurried-intrinsics.git"
21
+ },
22
+ "license": "MIT",
23
+ "author": "Fox Jones xsfj",
24
+ "type": "commonjs",
25
+ "main": "index.js",
26
+ "scripts": {
27
+ "test": "echo \"Error: no test specified\" && exit 1"
28
+ },
29
+ "dependencies": {
30
+ "es-intrinsic-cache": "^1.0.1",
31
+ "uncurry-x": "^1.0.1"
32
+ }
33
+ }