semver-parser
Advanced tools
Comparing version 4.1.2 to 4.1.3
@@ -13,4 +13,4 @@ /** | ||
const BASE = 10; | ||
const INT = '(?:0|[1-9]\\d*)'; | ||
const ALPHA_NUM = '\\d*[A-z-][A-z\\d-]*'; | ||
const INT = '0|[1-9]\\d*'; | ||
const ALPHA_NUM = '\\d*[A-Za-z-][A-Za-z\\d-]*'; | ||
const PRE_PART = `(?:${ALPHA_NUM}|${INT})`; | ||
@@ -20,4 +20,5 @@ const PRE = `${PRE_PART}(?:\\.${PRE_PART})*`; | ||
const BUILD = `${BUILD_PART}(?:\\.${BUILD_PART})*`; | ||
const SEMVER = `(${INT}(?:\\.${INT}){2})(?:-(${PRE}))?(?:\\+(${BUILD}))?`; | ||
const REGEXP_INT = new RegExp(`^${INT}$`); | ||
const SEMVER = | ||
`((?:${INT})(?:\\.(?:${INT})){2})(?:-(${PRE}))?(?:\\+(${BUILD}))?`; | ||
const REGEXP_INT = new RegExp(`^(?:${INT})$`); | ||
const REGEXP_SEMVER = new RegExp(`^v?${SEMVER}$`); | ||
@@ -68,9 +69,12 @@ const REGEXP_SEMVER_STRICT = new RegExp(`^${SEMVER}$`); | ||
} | ||
let parsedPart; | ||
if (REGEXP_INT.test(part)) { | ||
part = parseInt(part, BASE); | ||
if (!Number.isSafeInteger(part)) { | ||
throw new RangeError(`${part} exceeds ${Number.MAX_SAFE_INTEGER}.`); | ||
parsedPart = parseInt(part, BASE); | ||
if (!Number.isSafeInteger(parsedPart)) { | ||
throw new RangeError(`${parsedPart} exceeds ${Number.MAX_SAFE_INTEGER}.`); | ||
} | ||
} else { | ||
parsedPart = part; | ||
} | ||
return part; | ||
return parsedPart; | ||
}; | ||
@@ -109,4 +113,6 @@ | ||
const [, bRel, bPre] = base.match(reg); | ||
const [vMajor, vMinor, vPatch] = vRel.split('.').map(parseVersionPart); | ||
const [bMajor, bMinor, bPatch] = bRel.split('.').map(parseVersionPart); | ||
const [vMajor, vMinor, vPatch] = | ||
vRel.split('.').map(part => parseVersionPart(part)); | ||
const [bMajor, bMinor, bPatch] = | ||
bRel.split('.').map(part => parseVersionPart(part)); | ||
if (vMajor > bMajor) { | ||
@@ -182,3 +188,3 @@ result = 1; | ||
const [, vRel, vPre, vBuild] = version.match(reg); | ||
[major, minor, patch] = vRel.split('.').map(parseVersionPart); | ||
[major, minor, patch] = vRel.split('.').map(part => parseVersionPart(part)); | ||
if (vPre) { | ||
@@ -203,3 +209,3 @@ pre = vPre.split('.').map(part => parseVersionPart(part, true)); | ||
* @param {boolean} [strict] - reject 'v' prefixed | ||
* @returns {number} | ||
* @returns {Promise.<number>} | ||
* - -1 or negative number, if version is less than base version | ||
@@ -219,3 +225,3 @@ * 0, if version is equal to base version | ||
* @param {boolean} [strict] - reject 'v' prefixed | ||
* @returns {boolean} - result | ||
* @returns {Promise.<boolean>} - result | ||
*/ | ||
@@ -232,3 +238,3 @@ const isValidSemVerAsync = async (version, strict = false) => { | ||
* @param {boolean} [strict] - reject 'v' prefixed | ||
* @returns {SemVerObject} - result | ||
* @returns {Promise.<SemVerObject>} - result | ||
*/ | ||
@@ -235,0 +241,0 @@ const parseSemVerAsync = async (version, strict = false) => { |
@@ -18,3 +18,3 @@ { | ||
"chai": "^4.3.7", | ||
"eslint": "^8.34.0", | ||
"eslint": "^8.35.0", | ||
"eslint-config-standard": "^17.0.0", | ||
@@ -26,2 +26,3 @@ "eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"eslint-plugin-regexp": "^1.12.0", | ||
"mocha": "^10.2.0", | ||
@@ -36,3 +37,3 @@ "typescript": "^4.9.5" | ||
}, | ||
"version": "4.1.2" | ||
"version": "4.1.3" | ||
} |
{ | ||
"include": ["index.js"], | ||
"compilerOptions": { | ||
@@ -9,5 +8,10 @@ "allowJs": true, | ||
"emitDeclarationOnly": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"newLine": "LF", | ||
"removeComments": true | ||
} | ||
"removeComments": true, | ||
"resolveJsonModule": true, | ||
"target": "esnext" | ||
}, | ||
"include": ["index.js"] | ||
} |
@@ -19,5 +19,5 @@ export function isValidSemVer(version: string, strict?: boolean): boolean; | ||
}; | ||
declare function compareSemVerAsync(version: string, base: string, strict?: boolean): number; | ||
declare function isValidSemVerAsync(version: string, strict?: boolean): boolean; | ||
declare function parseSemVerAsync(version: string, strict?: boolean): SemVerObject; | ||
declare function compareSemVerAsync(version: string, base: string, strict?: boolean): Promise<number>; | ||
declare function isValidSemVerAsync(version: string, strict?: boolean): Promise<boolean>; | ||
declare function parseSemVerAsync(version: string, strict?: boolean): Promise<SemVerObject>; | ||
export {}; |
18477
305
12