help-curry 0.1.0 → 0.2.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.
package/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
- MIT License
2
1
 
3
- Copyright (c) 2021 Paul Nodet.
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2025 Paul Nodet
4
5
 
5
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,50 +1,65 @@
1
1
  # help-curry
2
- > Small js package I use to quickly curry functions
2
+ > A tiny curry helper for fixed-arity functions
3
3
 
4
- [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)
5
- [![GitHub workflow status](https://img.shields.io/github/workflow/status/pnxdxt/help-curry/CI)](https://github.com/pnxdxt/help-curry)
6
- [![npm bundle size](https://img.shields.io/bundlephobia/min/help-curry)](https://bundlephobia.com/package/help-curry)
4
+ [![CI](https://github.com/pnodet/help-curry/actions/workflows/check.yml/badge.svg)](https://github.com/pnodet/help-curry/actions/workflows/check.yml)
5
+ [![npm version](https://img.shields.io/npm/v/help-curry)](https://www.npmjs.com/package/help-curry)
7
6
  [![npm downloads](https://img.shields.io/npm/dt/help-curry)](https://www.npmjs.com/package/help-curry)
8
7
 
9
8
  ## Install
9
+
10
+ ```bash
11
+ npm install help-curry
10
12
  ```
11
- $ npm install pkg-name
13
+
14
+ ```bash
15
+ pnpm add help-curry
12
16
  ```
13
- ## Import
14
17
 
15
- This package is pure [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). It cannot be `require()`'d from CommonJS.
18
+ ```bash
19
+ bun add help-curry
20
+ ```
16
21
 
17
- Use `import foo from 'foo'` instead of `const foo = require('foo')` to import the package.
22
+ ## Usage
18
23
 
19
24
  ```js
20
- // Load entire build
21
25
  import curry from 'help-curry';
22
- ```
23
- If the package is used in an async context, you could use [`await import(…)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#dynamic_imports) from CommonJS instead of `require(…)`.
24
26
 
25
- **You also need to make sure you're on the latest minor version of Node.js. At minimum Node.js 12.20, 14.14, or 16.0.**
27
+ const sum = (a, b, c) => a + b + c;
28
+ const curriedSum = curry(sum);
29
+
30
+ curriedSum(1, 2, 3); // 6
31
+ curriedSum(1)(2, 3); // 6
32
+ curriedSum(1)(2)(3); // 6
33
+ ```
26
34
 
27
- Read more here: [sindresorhus/esm-package](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)
35
+ ## API
28
36
 
37
+ ### `curry(fn)`
29
38
 
30
- ## Usage
39
+ Creates a curried version of `fn` that can be called with any number of arguments
40
+ until the original function arity is satisfied. The arity is taken from
41
+ `fn.length`.
31
42
 
32
- ```js
43
+ - Preserves the `this` context when calling the original function
44
+ - Works well with fixed-arity functions
45
+ - Ships with TypeScript types
33
46
 
34
- function sum(a, b, c) {
35
- return a + b + c;
36
- }
47
+ ## Development
37
48
 
38
- let curriedSum = curry(sum);
49
+ ```bash
50
+ bun install
51
+ ```
39
52
 
40
- curriedSum(1, 2, 3);
41
- //=> 6, still callable normally
53
+ ```bash
54
+ bun test
55
+ ```
42
56
 
43
- curriedSum(1)(2,3)
44
- //=> 6, currying of 1st arg
57
+ ```bash
58
+ bun run lint
59
+ ```
45
60
 
46
- curriedSum(1)(2)(3)
47
- //=> 6, full currying
61
+ ```bash
62
+ bun run build
48
63
  ```
49
64
 
50
65
  ## License
package/dist/index.cjs ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = curry;
4
+ function curry(func) {
5
+ function curried(...args) {
6
+ if (args.length >= func.length) {
7
+ return func.apply(this, args);
8
+ }
9
+ return function (...args2) {
10
+ return curried.apply(this, args.concat(args2));
11
+ };
12
+ }
13
+ return curried;
14
+ }
15
+ module.exports = exports.default;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Makes f(a,b,c) callable as f(a)(b)(c)
3
+ * @param {Function} func
4
+ * @returns {Function}
5
+ * @example
6
+ * function sum(a, b, c) {
7
+ * return a + b + c;
8
+ * }
9
+ *
10
+ * let curriedSum = curry(sum);
11
+ * alert( curriedSum(1, 2, 3) ); // 6, still callable normally
12
+ * alert( curriedSum(1)(2,3) ); // 6, currying of 1st arg
13
+ * alert( curriedSum(1)(2)(3) ); // 6, full currying
14
+ */
15
+ type Curried<Args extends Array<unknown>, R> = Args extends [
16
+ infer A,
17
+ ...infer Rest
18
+ ] ? ((arg: A) => Curried<Rest, R>) & ((...args: Args) => R) : R;
19
+ export default function curry<Args extends Array<unknown>, R>(func: (...args: Args) => R): Curried<Args, R>;
20
+ export {};
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,KAAK,OAAO,CAAC,IAAI,SAAS,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,IAAI,SAAS;IAC1D,MAAM,CAAC;IACP,GAAG,MAAM,IAAI;CACd,GACG,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,CAAC,GACvD,CAAC,CAAC;AAEN,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAC1D,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,GACzB,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAYlB"}
@@ -12,4 +12,10 @@
12
12
  * alert( curriedSum(1)(2,3) ); // 6, currying of 1st arg
13
13
  * alert( curriedSum(1)(2)(3) ); // 6, full currying
14
14
  */
15
- export default function curry(func: () => any): () => void;
15
+ type Curried<Args extends Array<unknown>, R> = Args extends [
16
+ infer A,
17
+ ...infer Rest
18
+ ] ? ((arg: A) => Curried<Rest, R>) & ((...args: Args) => R) : R;
19
+ export default function curry<Args extends Array<unknown>, R>(func: (...args: Args) => R): Curried<Args, R>;
20
+ export {};
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,KAAK,OAAO,CAAC,IAAI,SAAS,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,IAAI,SAAS;IAC1D,MAAM,CAAC;IACP,GAAG,MAAM,IAAI;CACd,GACG,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,CAAC,GACvD,CAAC,CAAC;AAEN,MAAM,CAAC,OAAO,UAAU,KAAK,CAAC,IAAI,SAAS,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAC1D,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,CAAC,GACzB,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAYlB"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export default function curry(func) {
2
+ function curried(...args) {
3
+ if (args.length >= func.length) {
4
+ return func.apply(this, args);
5
+ }
6
+ return function (...args2) {
7
+ return curried.apply(this, args.concat(args2));
8
+ };
9
+ }
10
+ return curried;
11
+ }
package/package.json CHANGED
@@ -1,53 +1,67 @@
1
1
  {
2
2
  "name": "help-curry",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Small template I use to quickly create npm packages",
5
- "scripts": {
6
- "lint": "xo --fix",
7
- "test": "xo && ava && tsd",
8
- "watch:test": "ava --watch"
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "homepage": "https://github.com/pnodet/help-curry",
11
+ "bugs": {
12
+ "url": "https://github.com/pnodet/help-curry/issues"
9
13
  },
10
14
  "repository": {
11
15
  "type": "git",
12
- "url": "git+https://github.com/pnxdxt/help-curry.git"
13
- },
14
- "type": "module",
15
- "exports": "./index.js",
16
- "engines": {
17
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
16
+ "url": "git+https://github.com/pnodet/help-curry.git"
18
17
  },
19
- "files": [
20
- "index.js",
21
- "index.d.ts"
22
- ],
23
18
  "author": {
24
19
  "name": "Paul Nodet",
25
- "email": "paul.nodet@gmail.com",
26
20
  "url": "https://pnodet.com"
27
21
  },
28
- "license": "MIT",
29
- "bugs": {
30
- "url": "https://github.com/pnxdxt/help-curry/issues"
31
- },
32
- "homepage": "https://github.com/pnxdxt/help-curry#readme",
33
- "devDependencies": {
34
- "ava": "^3.15.0",
35
- "tsd": "^0.17.0",
36
- "xo": "^0.44.0"
37
- },
38
- "xo": {
39
- "singleQuote": true,
40
- "prettier": true
41
- },
42
- "prettier": {
43
- "trailingComma": "all",
44
- "singleQuote": true,
45
- "bracketSpacing": false,
46
- "jsxBracketSameLine": false
47
- },
48
22
  "keywords": [
49
23
  "helper",
50
- "template",
24
+ "curry",
51
25
  "javascript"
52
- ]
26
+ ],
27
+ "scripts": {
28
+ "dev": "bun run --watch src/index.ts",
29
+ "lint": "biome check",
30
+ "lint:fix": "biome check --write",
31
+ "test": "bun test",
32
+ "build": "bunx zshy",
33
+ "prepack": "bunx zshy",
34
+ "prepare": "bunx lefthook install",
35
+ "ts": "tsc --noEmit --incremental"
36
+ },
37
+ "dependencies": {},
38
+ "peerDependencies": {
39
+ "typescript": "^5"
40
+ },
41
+ "devDependencies": {
42
+ "@biomejs/biome": "2.3.10",
43
+ "@commitlint/cli": "20.2.0",
44
+ "@commitlint/config-conventional": "20.2.0",
45
+ "@nivalis/biome-config": "2.3.10",
46
+ "@total-typescript/ts-reset": "0.6.1",
47
+ "@types/bun": "1.3.5",
48
+ "@types/node": "24.2.0",
49
+ "lefthook": "2.0.12",
50
+ "typescript": "5.9.3",
51
+ "zshy": "0.6.0"
52
+ },
53
+ "zshy": "./src/index.ts",
54
+ "files": [
55
+ "dist"
56
+ ],
57
+ "main": "./dist/index.cjs",
58
+ "module": "./dist/index.js",
59
+ "types": "./dist/index.d.cts",
60
+ "exports": {
61
+ ".": {
62
+ "types": "./dist/index.d.cts",
63
+ "import": "./dist/index.js",
64
+ "require": "./dist/index.cjs"
65
+ }
66
+ }
53
67
  }
package/index.js DELETED
@@ -1,12 +0,0 @@
1
- /* eslint-disable unicorn/prefer-spread */
2
- export default function curry(func) {
3
- return function curried(...args) {
4
- if (args.length >= func.length) {
5
- return func.apply(this, args);
6
- }
7
-
8
- return function (...args2) {
9
- return curried.apply(this, args.concat(args2));
10
- };
11
- };
12
- }