Skip to content

Commit

Permalink
refactor:関数を外部へ切り出したためimportした関数を使ってオブジェクト内に定義
Browse files Browse the repository at this point in the history
  • Loading branch information
marumoto-goq committed May 2, 2024
1 parent cfb9853 commit 3a47a2f
Showing 1 changed file with 4 additions and 32 deletions.
36 changes: 4 additions & 32 deletions src/test/goqZipCode.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,7 @@
import type { HyphenatedZipCode } from './type/type';
import { checkLength, convertHyphenatedZipCode, convertZipCode } from './utils'

export const goqZipCode = {
convertZipCode: function (testZipCode: string): string {
const halfWidthZipCode: string = testZipCode.replace(
/[0-9]/g,
(s: string) => String.fromCharCode(s.charCodeAt(0) - 65248)
);

const halfWidthZipCodeExcludingHyphen = halfWidthZipCode.replaceAll(
/\D/g,
''
);

return halfWidthZipCodeExcludingHyphen;
},

checkLength: function (isExact: boolean, length: number): boolean {
if (isExact === true && length === 7) {
return true;
}

if (isExact === false && length >= 2 && length <= 7) {
return true;
}

return false;
},

convertHyphenatedZipCode: function (
zipCode: string | HyphenatedZipCode
): HyphenatedZipCode | string {
return `${zipCode.slice(0, 3)}-${zipCode.slice(3)}`;
},
convertZipCode,
checkLength,
convertHyphenatedZipCode,
};

0 comments on commit 3a47a2f

Please sign in to comment.