@jrrembert/luhnjs 1.0.0 → 1.0.1-rc.2

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/README.md CHANGED
@@ -5,14 +5,83 @@
5
5
 
6
6
  A TypeScript implementation of the Luhn algorithm for generating and validating checksums.
7
7
 
8
+ Published as [`@jrrembert/luhnjs`](https://www.npmjs.com/package/@jrrembert/luhnjs) on npm.
9
+
10
+ ## Getting Started
11
+
12
+ ### Prerequisites
13
+
14
+ Install [Node.js](https://nodejs.org/) (>=20.x) and [Yarn](https://yarnpkg.com/).
15
+
16
+ ### Installation
17
+
18
+ ```bash
19
+ # npm
20
+ $ npm install @jrrembert/luhnjs
21
+
22
+ # yarn
23
+ $ yarn add @jrrembert/luhnjs
24
+ ```
25
+
26
+ ### Usage
27
+
28
+ ```typescript
29
+ import {
30
+ generate,
31
+ validate,
32
+ random,
33
+ generateModN,
34
+ validateModN,
35
+ checksumModN,
36
+ } from '@jrrembert/luhnjs';
37
+
38
+ // Generate a checksum
39
+ generate('7992739871'); // '79927398713'
40
+ generate('7992739871', { checkSumOnly: true }); // '3'
41
+
42
+ // Validate a checksum
43
+ validate('79927398713'); // true
44
+
45
+ // Generate a random number with valid checksum
46
+ random('16'); // e.g. '4539148803436467'
47
+
48
+ // Mod-N variants (base 2–36, supports alphanumeric)
49
+ generateModN('1', 16); // '1E'
50
+ validateModN('1E', 16); // true
51
+ checksumModN('12345', 10); // 5
52
+ ```
53
+
54
+ ## Commands
55
+
56
+ ```bash
57
+ # Install dependencies
58
+ $ yarn
59
+
60
+ # Run tests
61
+ $ yarn test
62
+
63
+ # Lint
64
+ $ yarn lint
65
+
66
+ # Build
67
+ $ yarn build
68
+ ```
69
+
8
70
  ## Documentation
9
71
 
10
- - [Continuous Integration](docs/CI.md) - CI/CD workflows and troubleshooting
11
- - [Release and Build Process](docs/RELEASE.md) - Guide for building and publishing releases
12
- - [Specification](docs/SPEC.md) - Cross-language port alignment and API specification
72
+ <!-- TODO: Add link to API reference when published -->
73
+ - [Specification](docs/SPEC.md) - API specification
74
+ - [Release Process](docs/RELEASE.md) - Automated releases via semantic-release
75
+ - [CI/CD](docs/CI.md) - Workflows and troubleshooting
76
+ - [Contributing](CONTRIBUTING.md) - How to contribute
77
+ - [Security](SECURITY.md) - Reporting vulnerabilities
78
+
79
+ ## Contact
80
+
81
+ Email: [J. Ryan Rembert](mailto:j.ryan.rembert@gmail.com)
13
82
 
14
83
  ## License
15
84
 
16
85
  [MIT](LICENSE)
17
86
 
18
- Copyright © 2022-2026 J. Ryan Rembert
87
+ Copyright © 2022-2026 J. Ryan Rembert
@@ -1,6 +1,5 @@
1
- declare class GenerateOptions {
1
+ interface GenerateOptions {
2
2
  checkSumOnly: boolean;
3
- constructor();
4
3
  }
5
4
  /**
6
5
  * Calculate and append Luhn algorithm checksum to a given value
package/dist/src/luhn.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checksumModN = exports.validateModN = exports.generateModN = exports.random = exports.validate = exports.generate = void 0;
3
+ exports.generate = generate;
4
+ exports.validate = validate;
5
+ exports.random = random;
6
+ exports.generateModN = generateModN;
7
+ exports.validateModN = validateModN;
8
+ exports.checksumModN = checksumModN;
4
9
  const CODE_POINTS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
5
- class GenerateOptions {
6
- constructor() {
7
- this.checkSumOnly = false;
8
- }
9
- }
10
10
  /**
11
11
  * Validates that input is a non-empty string that can be converted to a number
12
12
  *
@@ -74,7 +74,6 @@ function generate(value, options) {
74
74
  const checkSum = generateCheckSum(value).toString();
75
75
  return (options === null || options === void 0 ? void 0 : options.checkSumOnly) ? checkSum : value.concat(checkSum);
76
76
  }
77
- exports.generate = generate;
78
77
  /**
79
78
  * Determine if the Luhn checksum for a given number is correct
80
79
  *
@@ -89,7 +88,6 @@ function validate(value) {
89
88
  const valueWithoutCheckSum = value.substring(0, value.length - 1);
90
89
  return value === generate(valueWithoutCheckSum);
91
90
  }
92
- exports.validate = validate;
93
91
  /**
94
92
  * Generate a random number with valid Luhn checksum
95
93
  *
@@ -114,7 +112,6 @@ function random(length) {
114
112
  }).join('');
115
113
  return generate(random);
116
114
  }
117
- exports.random = random;
118
115
  /**
119
116
  * Calculate and append a Luhn mod-N checksum to a numeric string
120
117
  *
@@ -132,7 +129,6 @@ function generateModN(value, n, options) {
132
129
  const checkChar = CODE_POINTS[checkSum];
133
130
  return (options === null || options === void 0 ? void 0 : options.checkSumOnly) ? checkChar : value.concat(checkChar);
134
131
  }
135
- exports.generateModN = generateModN;
136
132
  /**
137
133
  * Determine if the Luhn mod-N checksum for a given value is correct
138
134
  *
@@ -156,7 +152,6 @@ function validateModN(value, n) {
156
152
  const valueWithoutCheckSum = value.substring(0, value.length - 1);
157
153
  return value === generateModN(valueWithoutCheckSum, n);
158
154
  }
159
- exports.validateModN = validateModN;
160
155
  /**
161
156
  * Convert a character to its code point index (0-9, A-Z, case-insensitive)
162
157
  */
@@ -195,4 +190,3 @@ function checksumModN(value, n) {
195
190
  }
196
191
  return (n - (sum % n)) % n;
197
192
  }
198
- exports.checksumModN = checksumModN;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jrrembert/luhnjs",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-rc.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
@@ -9,6 +9,9 @@
9
9
  "repository": "https://github.com/jrrembert/luhnjs.git",
10
10
  "license": "MIT",
11
11
  "private": false,
12
+ "engines": {
13
+ "node": ">=22"
14
+ },
12
15
  "scripts": {
13
16
  "build": "tsc && node dist/index.js",
14
17
  "lint": "eslint .",
@@ -16,14 +19,15 @@
16
19
  "prepublishOnly": "yarn lint && yarn test && yarn build"
17
20
  },
18
21
  "devDependencies": {
19
- "@types/jest": "^29.2.3",
22
+ "@types/jest": "^30.0.0",
20
23
  "@typescript-eslint/eslint-plugin": "^5.44.0",
21
24
  "@typescript-eslint/parser": "^5.62.0",
22
25
  "eslint": "^8.28.0",
23
- "jest": "^29.3.1",
26
+ "jest": "^30.0.0",
27
+ "semantic-release": "^25.0.0",
24
28
  "ts-jest": "^29.4.6",
25
29
  "ts-node": "^10.9.2",
26
- "semantic-release": "^24.0.0",
27
- "typescript": "^4.9.3"
30
+ "tslib": "^2.8.1",
31
+ "typescript": "^5.8.2"
28
32
  }
29
33
  }