@natlibfi/issn-verify 1.0.6 → 2.0.0-alpha.1

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.
@@ -4,6 +4,10 @@ name: Melinda-node-tests
4
4
 
5
5
  on: push
6
6
 
7
+ permissions:
8
+ id-token: write # Required for OIDC
9
+ contents: read
10
+
7
11
  jobs:
8
12
  build-node-versions:
9
13
  name: Node version matrix
@@ -11,14 +15,14 @@ jobs:
11
15
 
12
16
  strategy:
13
17
  matrix:
14
- node-version: [18.x, 20.x, 22.x]
18
+ node-version: [22.x, 24.x]
15
19
  # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
16
20
 
17
21
  steps:
18
22
  - name: Checkout the code
19
- uses: actions/checkout@v4
23
+ uses: actions/checkout@v5
20
24
  - name: Use Node.js ${{ matrix.node-version }}
21
- uses: actions/setup-node@v4
25
+ uses: actions/setup-node@v6
22
26
  with:
23
27
  node-version: ${{ matrix.node-version }}
24
28
  cache: 'npm'
@@ -33,10 +37,11 @@ jobs:
33
37
  njsscan:
34
38
  name: Njsscan-check
35
39
  runs-on: ubuntu-latest
40
+ container: node:22
36
41
 
37
42
  steps:
38
43
  - name: Checkout the code
39
- uses: actions/checkout@v4
44
+ uses: actions/checkout@v5
40
45
  - name: nodejsscan scan
41
46
  id: njsscan
42
47
  uses: ajinabraham/njsscan-action@master
@@ -46,26 +51,36 @@ jobs:
46
51
  license-scan:
47
52
  name: License compliance check
48
53
  runs-on: ubuntu-latest
54
+ container: node:22
49
55
 
50
56
  steps:
51
- - uses: actions/checkout@v4
52
- - uses: mikaelvesavuori/license-compliance-action@v1.0.3
57
+ - uses: actions/checkout@v5
58
+ - uses: mikaelvesavuori/license-compliance-action@v1
53
59
  with:
54
60
  exclude_pattern: /^@natlibfi/
55
61
 
56
62
  publish:
57
63
  runs-on: ubuntu-latest
64
+ container: node:22
58
65
  needs: [build-node-versions, njsscan]
59
66
  if: contains(github.ref, 'refs/tags/')
60
67
 
61
68
  steps:
62
- - uses: actions/checkout@v4
69
+ - uses: actions/checkout@v5
63
70
  # Setup .npmrc file to publish to npm
64
- - uses: actions/setup-node@v4
71
+ - uses: actions/setup-node@v6
65
72
  with:
66
- node-version: '18.x'
73
+ node-version: '22.x'
67
74
  registry-url: 'https://registry.npmjs.org'
68
- - run: npm ci
69
- - run: npm publish
70
- env:
71
- NODE_AUTH_TOKEN: ${{ secrets.ISSN_VERIFY_NPM_TOKEN }}
75
+ - name: Update npm
76
+ run: npm install -g npm@latest
77
+ - name: Clean install
78
+ run: npm ci
79
+ # Publish stable release with --tag latest
80
+ - name: Publish stable release
81
+ if: ${{!contains(github.ref, '-alpha')}}
82
+ run: npm publish --tag=latest
83
+ # Publish pre-release without --tag latest
84
+ - name: Publish pre-release
85
+ if: contains(github.ref, '-alpha')
86
+ run: npm publish --tag=next
package/README.md CHANGED
@@ -39,6 +39,6 @@ if ( issn(test) ) {
39
39
  ## License and copyright
40
40
  **This software is fork of https://github.com/malantonio/issn-verify with updated dependencies**
41
41
 
42
- Copyright (c) 2018, 2023-2024 **University Of Helsinki (The National Library Of Finland)**
42
+ Copyright (c) 2018, 2023-2025 **University Of Helsinki (The National Library Of Finland)**
43
43
 
44
44
  This project's source code is licensed under the terms of **MIT License** or any later version.
@@ -0,0 +1,19 @@
1
+ export function issn(input) {
2
+ if (input.length < 8) {
3
+ input = input.padStart(8, "0");
4
+ }
5
+ const reg = /^\d{4}\-?\d{3}[\dX]$/;
6
+ if (!input.match(reg)) {
7
+ return false;
8
+ }
9
+ const num = input.substr(0, input.length - 1).replace(/\-/, "").split("").reverse().reduce(function(prv, cur, idx) {
10
+ let i = idx + 2;
11
+ return prv + cur * i;
12
+ }, 0) % 11;
13
+ const check = num === 0 ? 0 : 11 - num;
14
+ if (check === 10) {
15
+ return "X" === input.substr(-1);
16
+ }
17
+ return check === parseInt(input.substr(-1));
18
+ }
19
+ //# sourceMappingURL=issnVerify.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/issnVerify.js"],
4
+ "sourcesContent": ["export function issn(input) {\n if (input.length < 8) {\n input = input.padStart(8, '0');\n }\n\n const reg = /^\\d{4}\\-?\\d{3}[\\dX]$/;\n if (!input.match(reg)) {\n return false;\n }\n\n const num = input.substr(0, (input.length - 1))\n .replace(/\\-/, '')\n .split('')\n .reverse()\n .reduce(function (prv, cur, idx) {\n let i = idx + 2;\n return prv + (cur * i);\n }, 0)\n % 11;\n\n const check = num === 0 ? 0 : 11 - num;\n\n if (check === 10) {\n return \"X\" === input.substr(-1);\n }\n\n return check === parseInt(input.substr(-1));\n}\n"],
5
+ "mappings": "AAAO,gBAAS,KAAK,OAAO;AACxB,MAAI,MAAM,SAAS,GAAG;AAClB,YAAQ,MAAM,SAAS,GAAG,GAAG;AAAA,EACjC;AAEA,QAAM,MAAM;AACZ,MAAI,CAAC,MAAM,MAAM,GAAG,GAAG;AACnB,WAAO;AAAA,EACX;AAEA,QAAM,MAAM,MAAM,OAAO,GAAI,MAAM,SAAS,CAAE,EACzC,QAAQ,MAAM,EAAE,EAChB,MAAM,EAAE,EACR,QAAQ,EACR,OAAO,SAAU,KAAK,KAAK,KAAK;AAC7B,QAAI,IAAI,MAAM;AACd,WAAO,MAAO,MAAM;AAAA,EACxB,GAAG,CAAC,IACF;AAEN,QAAM,QAAQ,QAAQ,IAAI,IAAI,KAAK;AAEnC,MAAI,UAAU,IAAI;AACd,WAAO,QAAQ,MAAM,OAAO,EAAE;AAAA,EAClC;AAEA,SAAO,UAAU,SAAS,MAAM,OAAO,EAAE,CAAC;AAC9C;",
6
+ "names": []
7
+ }
@@ -0,0 +1,53 @@
1
+ // Eslint configuration object for src
2
+ const configSrc = {
3
+ files: [
4
+ "src/*",
5
+ "tests/*"
6
+ ],
7
+ linterOptions: {
8
+ reportUnusedDisableDirectives: true,
9
+ },
10
+ rules: {
11
+ "no-console": "warn",
12
+ "eqeqeq": ["error", "always"],
13
+ "no-const-assign": "error",
14
+ "max-depth": ["warn", 4],
15
+ "max-lines": ["warn", 500],
16
+ "max-lines-per-function": ["warn", {"max": 100}],
17
+ "no-else-return": ["error", {allowElseIf: false}],
18
+ "no-plusplus": [
19
+ "error",
20
+ {
21
+ "allowForLoopAfterthoughts": true
22
+ }
23
+ ],
24
+ "array-callback-return": [
25
+ "error",
26
+ {
27
+ "checkForEach": false
28
+ }
29
+ ],
30
+ "no-unused-vars": [
31
+ "error",
32
+ {
33
+ "argsIgnorePattern": "next"
34
+ }
35
+ ],
36
+ "no-warning-comments": "off"
37
+ }
38
+ };
39
+
40
+ // Eslint configuration object for globally ignoring .js files
41
+ // - ignore all files that start with a dot
42
+ // - ignore all files inside directories named 'dist'
43
+ const configIgnores = {
44
+ ignores: [
45
+ "**/.*",
46
+ "**/dist/"
47
+ ]
48
+ };
49
+
50
+ export default [
51
+ configSrc,
52
+ configIgnores
53
+ ];
package/package.json CHANGED
@@ -1,31 +1,6 @@
1
1
  {
2
2
  "name": "@natlibfi/issn-verify",
3
- "version": "1.0.6",
4
- "homepage": "https://github.com/malantonio/issn-verify-js",
5
- "bugs": {
6
- "url": "https://github.com/malantonio/issn-verify-js/issues"
7
- },
8
- "repository": {
9
- "type": "git",
10
- "url": "https://github.com/malantonio/issn-verify-js"
11
- },
12
3
  "description": "Verify ISSN (International Standard Serial Number)",
13
- "main": "issnVerify.js",
14
- "publishConfig": {
15
- "access": "public"
16
- },
17
- "directories": {
18
- "test": "test"
19
- },
20
- "devDependencies": {
21
- "tape": "^5.8.1"
22
- },
23
- "scripts": {
24
- "test": "node test/test.js"
25
- },
26
- "keywords": [
27
- "issn"
28
- ],
29
4
  "contributors": [
30
5
  {
31
6
  "name": "Adam Malantonio"
@@ -34,5 +9,36 @@
34
9
  "name": "The National Library of Finland"
35
10
  }
36
11
  ],
37
- "license": "MIT"
12
+ "keywords": [
13
+ "issn"
14
+ ],
15
+ "homepage": "https://www.npmjs.com/package/@natlibfi/issn-verify",
16
+ "bugs": {
17
+ "url": "https://github.com/NatLibFi/issn-verify-js/issues"
18
+ },
19
+ "repository": {
20
+ "url": "https://github.com/NatLibFi/issn-verify-js"
21
+ },
22
+ "license": "MIT",
23
+ "version": "2.0.0-alpha.1",
24
+ "main": "./dist/issnVerify.js",
25
+ "type": "module",
26
+ "engines": {
27
+ "node": ">=22"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "prepare": "npm run build",
34
+ "build": "esbuild \"src/**/*.js\" --sourcemap --platform=node --outdir=dist",
35
+ "lint": "eslint ./src",
36
+ "test": "npm run lint && npm run test:base",
37
+ "test:base": "node --test --experimental-test-coverage --test-reporter=spec './test/*.test.js'"
38
+ },
39
+ "dependencies": {},
40
+ "devDependencies": {
41
+ "esbuild": "^0.25.11",
42
+ "eslint": "^9.38.0"
43
+ }
38
44
  }
@@ -0,0 +1,28 @@
1
+ export function issn(input) {
2
+ if (input.length < 8) {
3
+ input = input.padStart(8, '0');
4
+ }
5
+
6
+ const reg = /^\d{4}\-?\d{3}[\dX]$/;
7
+ if (!input.match(reg)) {
8
+ return false;
9
+ }
10
+
11
+ const num = input.substr(0, (input.length - 1))
12
+ .replace(/\-/, '')
13
+ .split('')
14
+ .reverse()
15
+ .reduce(function (prv, cur, idx) {
16
+ let i = idx + 2;
17
+ return prv + (cur * i);
18
+ }, 0)
19
+ % 11;
20
+
21
+ const check = num === 0 ? 0 : 11 - num;
22
+
23
+ if (check === 10) {
24
+ return "X" === input.substr(-1);
25
+ }
26
+
27
+ return check === parseInt(input.substr(-1));
28
+ }
@@ -0,0 +1,26 @@
1
+ import assert from 'node:assert';
2
+ import {describe, it} from 'node:test';
3
+ import {issn} from '../src/issnVerify.js';
4
+
5
+ describe('issn validation tests', function () {
6
+ it('returns false for non-matching numbers', () => {
7
+ assert.equal(issn('000000000'), false);
8
+ });
9
+
10
+ it('matches oclc examples', () => {
11
+ assert.equal(issn('7369956'), true);
12
+ assert.equal(issn('07369956'), true);
13
+ assert.equal(issn('0736-9956'), true);
14
+ });
15
+
16
+ it('works with "X" check digit', () => {
17
+ assert.equal(issn('1550-235X'), true);
18
+ });
19
+
20
+ it('rejects strings', () => {
21
+ assert.equal(issn('a123-4567'), false);
22
+ });
23
+ });
24
+
25
+
26
+
package/issnVerify.js DELETED
@@ -1,61 +0,0 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Copyright 2014 Adam Malantonio
6
- * Copyright 2020 University Of Helsinki (The National Library Of Finland)
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
- *
10
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
- *
12
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
- *
14
- * @licend The above is the entire license notice
15
- * for the JavaScript code in this file.
16
- *
17
- */
18
-
19
- if ( module && typeof module.exports !== 'undefined' ) {
20
- module.exports = issnVerify;
21
- }
22
-
23
- function issnVerify(input) {
24
- var reg = /^\d{4}\-?\d{3}[\dX]$/
25
- , check
26
- , num
27
- ;
28
-
29
- if ( input.length < 8 ) {
30
- input = pad(input);
31
- }
32
-
33
- if ( !input.match(reg) ) {
34
- return false;
35
- }
36
-
37
- num = input.substr(0, (input.length - 1))
38
- .replace(/\-/, '')
39
- .split('')
40
- .reverse()
41
- .reduce(function(prv, cur, idx) {
42
- var i = idx + 2;
43
- return prv + (cur * i);
44
- }, 0)
45
- % 11;
46
-
47
- check = num == 0 ? 0 : 11 - num;
48
-
49
- if ( check == 10 ) {
50
- check = "X";
51
- }
52
-
53
- return check == input.substr(-1);
54
- }
55
-
56
- function pad(inp) {
57
- while ( inp.length < 8 ) {
58
- inp = "0" + inp;
59
- }
60
- return inp;
61
- }
package/test/test.js DELETED
@@ -1,49 +0,0 @@
1
- /**
2
- *
3
- * @licstart The following is the entire license notice for the JavaScript code in this file.
4
- *
5
- * Copyright 2014 Adam Malantonio
6
- * Copyright 2020 University Of Helsinki (The National Library Of Finland)
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
- *
10
- * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11
- *
12
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
- *
14
- * @licend The above is the entire license notice
15
- * for the JavaScript code in this file.
16
- *
17
- */
18
-
19
- var test = require('tape');
20
- var issn = require('../issnVerify');
21
-
22
- test('returns false for non-matching numbers', function(t) {
23
- t.notOk(issn('000000000'));
24
- t.end();
25
- });
26
-
27
- test('matches oclc examples', function(t) {
28
- var ex = [
29
- '7369956'
30
- , '07369956'
31
- , '0736-9956'
32
- ];
33
-
34
- ex.forEach(function(num) {
35
- t.ok(issn(num));
36
- });
37
-
38
- t.end();
39
- });
40
-
41
- test('works with "X" check digit', function(t) {
42
- t.ok(issn('1550-235X'));
43
- t.end()
44
- });
45
-
46
- test('rejects strings', function(t) {
47
- t.notOk(issn('a123-4567'));
48
- t.end();
49
- })