Skip to content

Commit

Permalink
chore: change module type && add return types
Browse files Browse the repository at this point in the history
  • Loading branch information
bingtsingw committed Apr 4, 2024
1 parent 2c6a81a commit 6d78dbe
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 16 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
"email": "[email protected]",
"url": "https://github.com/bingtsingw"
},
"type": "module",
"exports": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/datetime/interval-overlap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Exception } from '../exception';

export const areIntervalsOverlap = (intervalLeft: Interval, intervalRight: Interval) => {
export const areIntervalsOverlap = (intervalLeft: Interval, intervalRight: Interval): boolean | never => {
if (intervalLeft.start > intervalLeft.end || intervalRight.start > intervalRight.end) {
throw new Exception.Server.InternalErrorException('时间段无效');
}
Expand Down
2 changes: 1 addition & 1 deletion src/format/bytes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const formatBytes = (bytes: number, decimals = 2) => {
export const formatBytes = (bytes: number, decimals = 2): string => {
if (bytes === 0) return '0 B';

const k = 1024;
Expand Down
2 changes: 1 addition & 1 deletion src/format/currency.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const formatCurrency = (
currency: number,
options?: { decimals?: number; symbol?: string; sign?: boolean; F2Y?: boolean },
) => {
): string => {
const { decimals = 2, symbol = '¥', sign = false } = options || {};

const dm = decimals < 0 ? 0 : decimals;
Expand Down
11 changes: 4 additions & 7 deletions src/misc/get-distance.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { number, object, safeParse } from 'valibot';
import { Exception } from '../exception';

const vPoint = object({
latitude: number(),
longitude: number(),
});

const deg2rad = (deg: number) => {
const deg2rad = (deg: number): number => {
return deg * (Math.PI / 180);
};

Expand All @@ -24,7 +19,9 @@ const deg2rad = (deg: number) => {
export const getDistance = (
point1: { latitude: number; longitude: number },
point2: { latitude: number; longitude: number },
) => {
): number => {
const vPoint = object({ latitude: number(), longitude: number() });

if (!safeParse(vPoint, point1).success || !safeParse(vPoint, point2).success) {
throw new Exception.BadRequestException('坐标参数错误');
}
Expand Down
4 changes: 2 additions & 2 deletions src/misc/stringify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InternalErrorException } from '../exception/500';

// https://stackoverflow.com/questions/9804777/how-to-test-if-a-string-is-json-or-not
const isJson = (value: any) => {
const isJson = (value: any): boolean => {
let _value = typeof value !== 'string' ? JSON.stringify(value) : value;

try {
Expand All @@ -12,7 +12,7 @@ const isJson = (value: any) => {
}
};

export const stringify = (value: any) => {
export const stringify = (value: any): string => {
if (!isJson(value)) {
throw new InternalErrorException('Not Valid JSON');
}
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"noUncheckedIndexedAccess": true,
Expand Down

0 comments on commit 6d78dbe

Please sign in to comment.