Skip to content

Commit

Permalink
Update return type to throw Error instead of return null (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
svemat01 authored Jan 2, 2022
1 parent ef404ca commit aa9d1c7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/hex2dec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const parseToDigitsArray = (str: string, base: number) => {
for (let i = digits.length - 1; i >= 0; i--) {
let n = parseInt(digits[i], base);

if (isNaN(n)) return null;
if (isNaN(n)) throw new Error(`'${digits[i]}' is not a valid digit in base ${base}`);

ary.push(n);
}
Expand All @@ -57,8 +57,6 @@ const parseToDigitsArray = (str: string, base: number) => {
const convertBase = (str: string, fromBase: number, toBase: number) => {
let digits = parseToDigitsArray(str, fromBase);

if (digits === null) return null;

let outArray: number[] = [];
let power = [1];
for (let i = 0; i < digits.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type SunflakeConfig = {
epoch?: number;
};

export const generateSunflake = (config: SunflakeConfig) => async (time: number = Date.now()) => {
export const generateSunflake = (config: SunflakeConfig) => async (time: number = Date.now()): Promise<string> => {
let { machineID = 1, epoch = 1640988001000 } = config;

lastTime = time;
Expand Down

0 comments on commit aa9d1c7

Please # to comment.