diff --git a/src/getNumber.js b/src/getNumber.js index 86a106a..5793791 100644 --- a/src/getNumber.js +++ b/src/getNumber.js @@ -9,24 +9,29 @@ import { _partsNew, _partsOld, _partsSpecial } from "./_utils"; * @returns {number} * @since 0.0.5 * @example - * getNumber("2345BCF"); // => 2345 - * getNumber("GI-1234-CS"); // => 1234 + * getNumber("2345BCF"); // => "2345" + * getNumber("GI-1234-CS"); // => "1234" */ function getNumber(value) { const str = !value ? "" : value; + let n; if (isOld(str) === true) { const [, num] = _partsOld(str); - return parseInt(num, 10); + n = num; } else if (isSpecial(str) === true) { const [, num] = _partsSpecial(str); - return parseInt(num, 10); + n = num; } else if (isValid(str)) { const [num] = _partsNew(str); - return parseInt(num, 10); + n = num; + } else { + return null; } - return null; + return parseInt(n, 10) + .toString() + .padStart(4, "0"); } export { getNumber };