@credentum/is-cusip 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Credentum
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # @credentum/is-cusip
2
+
3
+ Zero-dependency CUSIP validator for JavaScript and TypeScript.
4
+
5
+ Validates 9-character [CUSIP](https://en.wikipedia.org/wiki/CUSIP) identifiers used to identify North American financial securities. Uses the Modulus 10 Double Add Double check digit algorithm.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @credentum/is-cusip
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```js
16
+ const isCUSIP = require('@credentum/is-cusip');
17
+
18
+ isCUSIP('037833100'); // true — Apple Inc.
19
+ isCUSIP('17275R102'); // true — Cisco Systems
20
+ isCUSIP('68389X106'); // false — bad check digit
21
+ ```
22
+
23
+ ### ESM
24
+
25
+ ```js
26
+ import isCUSIP from '@credentum/is-cusip';
27
+ // or
28
+ import { isCUSIP, sanitizeCUSIP } from '@credentum/is-cusip';
29
+ ```
30
+
31
+ ### Sanitize before validating
32
+
33
+ ```js
34
+ const { isCUSIP, sanitizeCUSIP } = require('@credentum/is-cusip');
35
+
36
+ const raw = ' 037-833-100 ';
37
+ isCUSIP(sanitizeCUSIP(raw)); // true
38
+ ```
39
+
40
+ `sanitizeCUSIP` trims whitespace, removes dashes and spaces, and uppercases the input. It does not validate.
41
+
42
+ ## API
43
+
44
+ ### `isCUSIP(input: string): boolean`
45
+
46
+ Returns `true` if the input is a valid 9-character CUSIP with a correct check digit.
47
+
48
+ ### `sanitizeCUSIP(input: string): string`
49
+
50
+ Cleans raw input for validation. Trims, removes `-` and spaces, uppercases.
51
+
52
+ ## License
53
+
54
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Validate a CUSIP identifier.
3
+ *
4
+ * CUSIP is a 9-character alphanumeric code identifying North American
5
+ * financial securities. The 9th character is a check digit computed
6
+ * using the Modulus 10 Double Add Double algorithm.
7
+ *
8
+ * @param input - The CUSIP string to validate.
9
+ * @returns True if the input is a valid CUSIP.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import isCUSIP from '@credentum/is-cusip';
14
+ *
15
+ * isCUSIP('037833100'); // true (Apple Inc.)
16
+ * isCUSIP('17275R102'); // true (Cisco Systems)
17
+ * isCUSIP('INVALID01'); // false
18
+ * ```
19
+ */
20
+ declare function isCUSIP(input: string): boolean;
21
+
22
+ /**
23
+ * Sanitize a string for CUSIP validation.
24
+ *
25
+ * Trims whitespace, removes dashes and spaces, and uppercases.
26
+ * Does NOT validate — call isCUSIP() on the result.
27
+ *
28
+ * @param input - Raw input that might contain a CUSIP.
29
+ * @returns Cleaned string ready for isCUSIP() validation.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { sanitizeCUSIP, isCUSIP } from '@credentum/is-cusip';
34
+ *
35
+ * const raw = ' 037-833-100 ';
36
+ * isCUSIP(sanitizeCUSIP(raw)); // true
37
+ * ```
38
+ */
39
+ declare function sanitizeCUSIP(input: string): string;
40
+
41
+ export { isCUSIP, sanitizeCUSIP };
42
+ export default isCUSIP;
package/index.js ADDED
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * CUSIP character value lookup.
5
+ * Digits 0-9 map to 0-9, letters A-Z map to 10-35,
6
+ * special characters: * = 36, @ = 37, # = 38.
7
+ */
8
+ function charValue(c) {
9
+ var code = c.charCodeAt(0);
10
+ if (code >= 48 && code <= 57) return code - 48; // '0'-'9'
11
+ if (code >= 65 && code <= 90) return code - 55; // 'A'-'Z' -> 10-35
12
+ if (c === '*') return 36;
13
+ if (c === '@') return 37;
14
+ if (c === '#') return 38;
15
+ return -1;
16
+ }
17
+
18
+ /**
19
+ * Validate a CUSIP identifier.
20
+ *
21
+ * CUSIP is a 9-character alphanumeric code identifying North American
22
+ * financial securities. The 9th character is a check digit computed
23
+ * using the Modulus 10 Double Add Double algorithm.
24
+ *
25
+ * @param {string} input - The CUSIP string to validate.
26
+ * @returns {boolean} True if the input is a valid CUSIP.
27
+ */
28
+ function isCUSIP(input) {
29
+ if (typeof input !== 'string') return false;
30
+ if (input.length !== 9) return false;
31
+
32
+ var sum = 0;
33
+ for (var i = 0; i < 8; i++) {
34
+ var v = charValue(input.charAt(i));
35
+ if (v < 0) return false;
36
+
37
+ // Double the value at even-indexed positions (0-based: positions 1,3,5,7)
38
+ if (i % 2 === 1) v = v * 2;
39
+
40
+ // Sum the digits: integer division by 10 + remainder
41
+ sum = sum + Math.floor(v / 10) + (v % 10);
42
+ }
43
+
44
+ var checkDigit = (10 - (sum % 10)) % 10;
45
+ var lastChar = charValue(input.charAt(8));
46
+ if (lastChar < 0) return false;
47
+
48
+ return lastChar === checkDigit;
49
+ }
50
+
51
+ /**
52
+ * Sanitize a string for CUSIP validation.
53
+ *
54
+ * Trims whitespace, removes common separators (dashes, spaces),
55
+ * and uppercases the input. Does NOT validate — call isCUSIP()
56
+ * on the result for validation.
57
+ *
58
+ * @param {string} input - Raw input that might contain a CUSIP.
59
+ * @returns {string} Cleaned string ready for isCUSIP() validation.
60
+ */
61
+ function sanitizeCUSIP(input) {
62
+ if (typeof input !== 'string') return '';
63
+ return input.trim().replace(/[\s\-]/g, '').toUpperCase();
64
+ }
65
+
66
+ module.exports = isCUSIP;
67
+ module.exports.isCUSIP = isCUSIP;
68
+ module.exports.sanitizeCUSIP = sanitizeCUSIP;
69
+ module.exports.default = isCUSIP;
package/index.mjs ADDED
@@ -0,0 +1,52 @@
1
+ /**
2
+ * CUSIP character value lookup.
3
+ * Digits 0-9 map to 0-9, letters A-Z map to 10-35,
4
+ * special characters: * = 36, @ = 37, # = 38.
5
+ */
6
+ function charValue(c) {
7
+ const code = c.charCodeAt(0);
8
+ if (code >= 48 && code <= 57) return code - 48;
9
+ if (code >= 65 && code <= 90) return code - 55;
10
+ if (c === '*') return 36;
11
+ if (c === '@') return 37;
12
+ if (c === '#') return 38;
13
+ return -1;
14
+ }
15
+
16
+ /**
17
+ * Validate a CUSIP identifier.
18
+ *
19
+ * @param {string} input - The CUSIP string to validate.
20
+ * @returns {boolean} True if the input is a valid CUSIP.
21
+ */
22
+ export function isCUSIP(input) {
23
+ if (typeof input !== 'string') return false;
24
+ if (input.length !== 9) return false;
25
+
26
+ let sum = 0;
27
+ for (let i = 0; i < 8; i++) {
28
+ let v = charValue(input.charAt(i));
29
+ if (v < 0) return false;
30
+ if (i % 2 === 1) v = v * 2;
31
+ sum = sum + Math.floor(v / 10) + (v % 10);
32
+ }
33
+
34
+ const checkDigit = (10 - (sum % 10)) % 10;
35
+ const lastChar = charValue(input.charAt(8));
36
+ if (lastChar < 0) return false;
37
+
38
+ return lastChar === checkDigit;
39
+ }
40
+
41
+ /**
42
+ * Sanitize a string for CUSIP validation.
43
+ *
44
+ * @param {string} input - Raw input that might contain a CUSIP.
45
+ * @returns {string} Cleaned string ready for isCUSIP() validation.
46
+ */
47
+ export function sanitizeCUSIP(input) {
48
+ if (typeof input !== 'string') return '';
49
+ return input.trim().replace(/[\s\-]/g, '').toUpperCase();
50
+ }
51
+
52
+ export default isCUSIP;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@credentum/is-cusip",
3
+ "version": "1.0.0",
4
+ "description": "Zero-dependency CUSIP validator. Validates 9-character CUSIP identifiers using the Modulus 10 Double Add Double check digit algorithm.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./index.d.ts",
10
+ "require": "./index.js",
11
+ "import": "./index.mjs"
12
+ }
13
+ },
14
+ "files": [
15
+ "index.js",
16
+ "index.mjs",
17
+ "index.d.ts"
18
+ ],
19
+ "scripts": {
20
+ "test": "node test.js"
21
+ },
22
+ "keywords": [
23
+ "cusip",
24
+ "is-cusip",
25
+ "validate-cusip",
26
+ "cusip-validator",
27
+ "financial",
28
+ "securities",
29
+ "check-digit",
30
+ "modulus-10",
31
+ "isin",
32
+ "sedol",
33
+ "figi"
34
+ ],
35
+ "author": "Credentum <hello@credentum.com>",
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "https://github.com/credentum/is-cusip"
40
+ },
41
+ "engines": {
42
+ "node": ">=12"
43
+ }
44
+ }