From 820455abe581fdb6db6984e6e84b9b43a98df0dc Mon Sep 17 00:00:00 2001 From: avo Date: Sun, 19 Mar 2023 00:26:42 +0200 Subject: [PATCH 1/2] feat: add ua postal code --- src/scalars/PostalCode.ts | 4 +++- tests/PostalCode.test.ts | 14 ++++++++++++++ website/src/pages/docs/scalars/postal-code.mdx | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/scalars/PostalCode.ts b/src/scalars/PostalCode.ts index 3eab5cbb9..be4fb695a 100644 --- a/src/scalars/PostalCode.ts +++ b/src/scalars/PostalCode.ts @@ -27,6 +27,7 @@ import { createGraphQLError } from '../error.js'; // LU - Luxembourg // IR - Iran // JP - Japan +// UA - Ukraine // // This is really a practical decision of weight (of the package) vs. completeness. // @@ -53,7 +54,8 @@ const POSTAL_CODE_REGEXES = [ /* CH */ /*#__PURE__*//^\d{4}$/, /* LU */ /*#__PURE__*//^\d{4}$/, /* IR */ /*#__PURE__*//^[1,3-9]{10}$/, - /* JP */ /*#__PURE__*//^\d{3}-\d{4}$/ + /* JP */ /*#__PURE__*//^\d{3}-\d{4}$/, + /* UA */ /*#__PURE__*//^\d{5}$/, ]; function _testPostalCode(postalCode: string) { diff --git a/tests/PostalCode.test.ts b/tests/PostalCode.test.ts index 4f0363b39..a586ac8f8 100644 --- a/tests/PostalCode.test.ts +++ b/tests/PostalCode.test.ts @@ -235,6 +235,20 @@ describe('PostalCode', () => { expect(GraphQLPostalCode.parseLiteral({ value: '123-4567', kind: Kind.STRING }, {})).toBe('123-4567'); }); }); + + describe('Ukraine', () => { + test('serialize', () => { + expect(GraphQLPostalCode.serialize('08001')).toBe('08001'); + }); + + test('parseValue', () => { + expect(GraphQLPostalCode.parseValue('08001')).toBe('08001'); + }); + + test('parseLiteral', () => { + expect(GraphQLPostalCode.parseLiteral({ value: '08001', kind: Kind.STRING }, {})).toBe('08001'); + }); + }); }); describe('invalid', () => { diff --git a/website/src/pages/docs/scalars/postal-code.mdx b/website/src/pages/docs/scalars/postal-code.mdx index d5f3408df..18eacd55d 100644 --- a/website/src/pages/docs/scalars/postal-code.mdx +++ b/website/src/pages/docs/scalars/postal-code.mdx @@ -20,6 +20,7 @@ Which gives us the following countries: - IN - India - IR - Iran - JP - Japan +- UA - Ukraine This is a practical decision of weight (of the package) vs. completeness. From f68f75df06e284a3148fce15e70991100b4ef545 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Fri, 24 Mar 2023 14:45:54 +0300 Subject: [PATCH 2/2] Support UA postal code in PostalCode scalar --- .changeset/silly-tigers-change.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/silly-tigers-change.md diff --git a/.changeset/silly-tigers-change.md b/.changeset/silly-tigers-change.md new file mode 100644 index 000000000..12f88ae83 --- /dev/null +++ b/.changeset/silly-tigers-change.md @@ -0,0 +1,5 @@ +--- +'graphql-scalars': patch +--- + +Support UA postal code in PostalCode scalar