@softwear/latestcollectioncore 1.0.1 → 1.0.3
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/dist/ean13.d.ts +1 -1
- package/dist/ean13.js +16 -14
- package/dist/hashBrand.d.ts +1 -0
- package/dist/hashBrand.js +4 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -3
- package/package.json +3 -1
- package/src/ean13.ts +14 -15
- package/src/hashBrand.ts +1 -1
- package/src/index.ts +2 -4
- package/tsconfig.json +1 -1
package/dist/ean13.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export default function (baseNumberAsString: string): number;
|
package/dist/ean13.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
digits
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function default_1(baseNumberAsString) {
|
|
4
|
+
const calculateCheckDigit = function (baseNumberAsString) {
|
|
5
|
+
if (!Number(baseNumberAsString) || baseNumberAsString.length !== 12) {
|
|
6
|
+
throw Error(`Not an EAN 13 base number. Must have a number with 12 digits, got ${baseNumberAsString}`);
|
|
7
|
+
}
|
|
8
|
+
const digits = [];
|
|
9
|
+
for (let i = 0; i < 12; i++) {
|
|
10
|
+
digits.push(Number(baseNumberAsString.charAt(i)));
|
|
11
|
+
}
|
|
12
|
+
const weightedDigitsSum = digits[0] + digits[1] * 3 + digits[2] + digits[3] * 3 + digits[4] + digits[5] * 3 + digits[6] + digits[7] * 3 + digits[8] + digits[9] * 3 + digits[10] + digits[11] * 3;
|
|
13
|
+
const remainder = weightedDigitsSum % 10;
|
|
14
|
+
return remainder === 0 ? 0 : 10 - remainder;
|
|
15
|
+
};
|
|
15
16
|
const checkDigit = calculateCheckDigit(baseNumberAsString);
|
|
16
17
|
return Number(baseNumberAsString) * 10 + checkDigit;
|
|
17
|
-
}
|
|
18
|
+
}
|
|
19
|
+
exports.default = default_1;
|
package/dist/hashBrand.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function (brand?: string): string;
|
package/dist/hashBrand.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function default_1(brand = "") {
|
|
3
4
|
if (typeof brand != "string")
|
|
4
5
|
return "";
|
|
5
6
|
const charactersToRemove = "~<>!@#$%^&*():'\"? ";
|
|
@@ -11,4 +12,5 @@ module.exports = function (brand = "") {
|
|
|
11
12
|
result = result + c;
|
|
12
13
|
}
|
|
13
14
|
return result.toLocaleLowerCase();
|
|
14
|
-
}
|
|
15
|
+
}
|
|
16
|
+
exports.default = default_1;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
hashBrand: require("./hashBrand"),
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
4
|
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.hashBrand = exports.ean13 = void 0;
|
|
7
|
+
var ean13_1 = require("./ean13");
|
|
8
|
+
Object.defineProperty(exports, "ean13", { enumerable: true, get: function () { return __importDefault(ean13_1).default; } });
|
|
9
|
+
var hashBrand_1 = require("./hashBrand");
|
|
10
|
+
Object.defineProperty(exports, "hashBrand", { enumerable: true, get: function () { return __importDefault(hashBrand_1).default; } });
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softwear/latestcollectioncore",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Core functions for LatestCollections applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"build": "tsc -p tsconfig.json",
|
|
8
9
|
"test": "mocha"
|
|
9
10
|
},
|
|
11
|
+
"type": "module",
|
|
10
12
|
"repository": {
|
|
11
13
|
"type": "git",
|
|
12
14
|
"url": "git+ssh://git@gitlab.com/softwearconnect/latestcollectioncore.git"
|
package/src/ean13.ts
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export default function (baseNumberAsString: string): number {
|
|
2
|
+
const calculateCheckDigit = function (baseNumberAsString: string): number {
|
|
3
|
+
if (!Number(baseNumberAsString) || baseNumberAsString.length !== 12) {
|
|
4
|
+
throw Error(`Not an EAN 13 base number. Must have a number with 12 digits, got ${baseNumberAsString}`)
|
|
5
|
+
}
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const digits = <number[]>[]
|
|
8
|
+
for (let i = 0; i < 12; i++) {
|
|
9
|
+
digits.push(Number(baseNumberAsString.charAt(i)))
|
|
10
|
+
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const weightedDigitsSum =
|
|
13
|
+
digits[0] + digits[1] * 3 + digits[2] + digits[3] * 3 + digits[4] + digits[5] * 3 + digits[6] + digits[7] * 3 + digits[8] + digits[9] * 3 + digits[10] + digits[11] * 3
|
|
14
|
+
const remainder = weightedDigitsSum % 10
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = function (baseNumberAsString) {
|
|
16
|
+
return remainder === 0 ? 0 : 10 - remainder
|
|
17
|
+
}
|
|
19
18
|
const checkDigit = calculateCheckDigit(baseNumberAsString)
|
|
20
19
|
return Number(baseNumberAsString) * 10 + checkDigit
|
|
21
20
|
}
|
package/src/hashBrand.ts
CHANGED
package/src/index.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/* Basic Options */
|
|
5
5
|
// "incremental": true, /* Enable incremental compilation */
|
|
6
6
|
"target": "es2021" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
|
|
7
|
-
"module": "
|
|
7
|
+
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
|
|
8
8
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
9
9
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
|
10
10
|
// "checkJs": true, /* Report errors in .js files. */
|