Skip to content

Commit

Permalink
refactor: change function names to avoid name collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
bohongu committed Feb 18, 2025
1 parent b52bb5c commit f0780be
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 70 deletions.
4 changes: 2 additions & 2 deletions src/date-util/date-util-base.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {
DATE_FORMAT,
DATETIME_FORMAT,
DATETIME_FORMAT_WITH_MILLIS,
TIMEZONE_UTC,
TIMEZONE_PST,
TIMEZONE_TOKYO,
TIMEZONE_SEOUL,
TIMEZONE_TOKYO,
TIMEZONE_UTC,
} from './date-util.const';

export type DateType = string | number | Date;
Expand Down
26 changes: 13 additions & 13 deletions src/date-util/date-util.spec.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import {
isValidDate,
parseDate,
parseByFormatDate,
parseTimestamp,
parseUnixTime,
calcDatetime,
startOfDate,
startOfByTimezone,
endOfByTimezone,
getTimezoneOffsetInHours,
isLastDateOfMonth,
diffDate,
minDate,
durationTo,
endOfByTimezone,
formatDate,
formatInIso8601,
fromNow,
getDateString,
getDatetimeString,
getTimestampString,
durationTo,
fromNow,
getTimezoneOffsetInHours,
isAdult,
isLastDateOfMonth,
isValidDate,
minDate,
parseByFormatDate,
parseDate,
parseTimestamp,
parseUnixTime,
startOfByTimezone,
startOfDate,
} from './date-util';
import {
DATE_FORMAT,
Expand Down
2 changes: 1 addition & 1 deletion src/date-util/date-util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LoggerFactory } from '../logger';
import { DatePropertyType, DateType, TimeZoneType } from './date-util-base.type';
import {
ADULT_AGE_DEFAULT,
DATE_FORMAT,
DATETIME_FORMAT,
LOCAL_DATETIME_FORMAT,
Expand All @@ -12,7 +13,6 @@ import {
ONE_MINUTE_IN_SECOND,
ONE_SECOND_IN_MILLI,
TIMESTAMP_FORMAT,
ADULT_AGE_DEFAULT,
} from './date-util.const';
import type { TimeAnnotationSet } from './date-util.interface';
import type { CalcDatetimeOpts, DatetimeFormatOpts, IsoDatetimeFormatOpts } from './date-util.type';
Expand Down
43 changes: 19 additions & 24 deletions src/date-util/index.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
export {
isValidDate,
parseDate,
parseByFormatDate,
parseTimestamp,
parseUnixTime,
calcDatetime,
startOfDate,
startOfByTimezone,
endOfByTimezone,
getTimezoneOffsetInHours,
isLastDateOfMonth,
diffDate,
minDate,
formatDate,
formatInIso8601,
getDateString,
getDatetimeString,
getTimestampString,
getTimeStringFromSeconds,
diffMonth,
durationTo,
endOfByTimezone,
format12HourInLocale,
formatDate,
fromNow,
getTimezoneOffsetInHours,
getTimezoneOffsetString,
isAdult,
isLastDateOfMonth,
isValidDate,
minDate,
parseByFormatDate,
parseDate,
parseTimestamp,
parseUnixTime,
startOfByTimezone,
startOfDate,
subtractOneDayIfLocalTimeIsMidnight,
format12HourInLocale,
getTimezoneOffsetString,
diffMonth,
} from './date-util';
export type { DatePropertyType, DateType, Iso8601FormatType, LocaleType, TimeZoneType } from './date-util-base.type';
export {
DATE_FORMAT,
DATE_FORMAT_DOT_TYPE,
DATE_FORMAT_US,
DATETIME_FORMAT,
DATETIME_FORMAT_WITH_MILLIS,
LOCAL_DATETIME_FORMAT,
Expand All @@ -39,12 +37,9 @@ export {
ONE_MINUTE_IN_SECOND,
ONE_SECOND_IN_MILLI,
TIMESTAMP_FORMAT,
DATE_FORMAT_DOT_TYPE,
DATE_FORMAT_US,
TIMEZONE_SEOUL,
TIMEZONE_PST,
TIMEZONE_SEOUL,
TIMEZONE_TOKYO,
} from './date-util.const';
export type { DatetimeProperties, FormatOpts } from './date-util.interface';
export type { CalcDatetimeOpts, DatetimeFormatOpts, IsoDatetimeFormatOpts } from './date-util.type';
export type { DatePropertyType, DateType, Iso8601FormatType, LocaleType, TimeZoneType } from './date-util-base.type';
2 changes: 1 addition & 1 deletion src/number-util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export {
fromPermyriad,
intValueOf,
isNumeric,
parseNumber,
toPermyriad,
valueOfNumber,
} from './number-util';
24 changes: 12 additions & 12 deletions src/number-util/number-util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
fromPermyriad,
intValueOf,
isNumeric,
parseNumber,
toPermyriad,
valueOfNumber,
} from './number-util';

describe('intValueOf', () => {
Expand All @@ -28,20 +28,20 @@ describe('intValueOf', () => {
});
});

describe('parseNumber', () => {
describe('valueOfNumber', () => {
it('should throw with incompatible input', () => {
expect(() => parseNumber('abc')).toThrow();
expect(() => parseNumber('4a')).toThrow();
expect(() => parseNumber('1.2.3')).toThrow();
expect(() => parseNumber('')).toThrow();
expect(() => valueOfNumber('abc')).toThrow();
expect(() => valueOfNumber('4a')).toThrow();
expect(() => valueOfNumber('1.2.3')).toThrow();
expect(() => valueOfNumber('')).toThrow();
});
it('should return parameter in number type', () => {
expect(parseNumber('-1')).toEqual(-1);
expect(parseNumber('0')).toEqual(0);
expect(parseNumber('1.2')).toEqual(1.2);
expect(parseNumber('-1.2')).toEqual(-1.2);
expect(parseNumber('-93339.228883747849')).toEqual(-93339.22888374786);
expect(parseNumber('9488848.29000004833')).toEqual(9488848.290000048);
expect(valueOfNumber('-1')).toEqual(-1);
expect(valueOfNumber('0')).toEqual(0);
expect(valueOfNumber('1.2')).toEqual(1.2);
expect(valueOfNumber('-1.2')).toEqual(-1.2);
expect(valueOfNumber('-93339.228883747849')).toEqual(-93339.22888374786);
expect(valueOfNumber('9488848.29000004833')).toEqual(9488848.290000048);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/number-util/number-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function intValueOf(numStr: string): number {
return result;
}

export function parseNumber(numStr: string): number {
export function valueOfNumber(numStr: string): number {
const result = Number(numStr);

if (!numStr || !Number.isFinite(result)) {
Expand Down
4 changes: 2 additions & 2 deletions src/string-util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ export {
getNonce,
isValidEmail,
isValidKoreaPhoneNumber,
join,
joinStrings,
joinTags,
maskPrivacy,
normalizePhoneNumber,
renderTemplate,
split,
splitString,
splitTags,
} from './string-util';
export { UTF8_BOM_STR } from './string-util.const';
Expand Down
20 changes: 10 additions & 10 deletions src/string-util/string-util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
getNonce,
isValidEmail,
isValidKoreaPhoneNumber,
join,
joinStrings,
joinTags,
maskPrivacy,
normalizePhoneNumber,
renderTemplate,
split,
splitString,
splitTags,
} from './string-util';
import { TemplateOpts } from './string-util.interface';
Expand Down Expand Up @@ -454,17 +454,17 @@ describe('splitTags', () => {
});
});

describe('split', () => {
describe('splitString', () => {
it('should return array of text', () => {
const str = 'one, two , , three , four ,five six ';
expect(split(str)).toEqual(['one', 'two', 'three', 'four', 'five six']);
expect(splitString(str)).toEqual(['one', 'two', 'three', 'four', 'five six']);
});
it('should return empty array when tags are invalid', () => {
const str = ' , , ';
expect(split(str)).toEqual([]);
expect(splitString(str)).toEqual([]);
});
it('should return empty array when empty string is given', () => {
expect(split('')).toEqual([]);
expect(splitString('')).toEqual([]);
});
});

Expand All @@ -481,16 +481,16 @@ describe('joinTags', () => {
});
});

describe('join', () => {
describe('joinStrings', () => {
it('should return string when a list of text is given', () => {
const textList = ['one ', ' two', ' three ', 'four', 'five six'];
expect(join(textList)).toBe('one,two,three,four,five six');
expect(joinStrings(textList)).toBe('one,two,three,four,five six');
});
it('should return empty string when only empty strings are given', () => {
expect(join([' ', ' '])).toBe('');
expect(joinStrings([' ', ' '])).toBe('');
});
it(`should return '' when empty array is given`, () => {
expect(join([])).toBe('');
expect(joinStrings([])).toBe('');
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/string-util/string-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ export function isValidEmail(str: string): boolean {
}

export function splitTags(str: string, separator = ','): Tag[] {
return split(str, separator).map((text) => {
return splitString(str, separator).map((text) => {
return { text };
});
}

export function split(str: string, separator = ','): string[] {
export function splitString(str: string, separator = ','): string[] {
return str.split(separator).reduce((textList: string[], text) => {
text = text.trim();
if (text.length > 0) {
Expand All @@ -187,10 +187,10 @@ export function joinTags(tags: Readonly<Tag[]>, separator = ','): string {
const textList = tags.map((tag) => {
return tag.text;
});
return join(textList, separator);
return joinStrings(textList, separator);
}

export function join(textList: string[], separator = ','): string {
export function joinStrings(textList: string[], separator = ','): string {
return textList.reduce((joinedText: string, text) => {
if (joinedText) {
joinedText += separator;
Expand Down

0 comments on commit f0780be

Please sign in to comment.