Skip to content

Commit

Permalink
feat: getNumber as string
Browse files Browse the repository at this point in the history
  • Loading branch information
singuerinc committed Feb 25, 2019
1 parent 7ca0a72 commit 7488782
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/getNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

0 comments on commit 7488782

Please sign in to comment.