Skip to content

Commit

Permalink
add regex fallback to splitAddress1 function, release v0.7.0 of TS pa…
Browse files Browse the repository at this point in the history
…ckage
  • Loading branch information
gabypancu committed Oct 1, 2024
1 parent 5210dee commit b95457f
Show file tree
Hide file tree
Showing 24 changed files with 618 additions and 34 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Security in case of vulnerabilities.

## [Unreleased]
- Nil.
- Add address1_regex to regions [#281](https://github.com/Shopify/worldwide/pull/281)
- Add address1_regex for BE, CL, MX, ES, IL [#282](https://github.com/Shopify/worldwide/pull/282)
- Add address1_regex for DE [#286](https://github.com/Shopify/worldwide/pull/286)

---

Expand Down
3 changes: 3 additions & 0 deletions db/data/regions/BE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ format:
show: "{firstName} {lastName}_{company}_{address1}_{address2}_{zip} {city}_{country}_{phone}"
format_extended:
edit: "{country}_{firstName}{lastName}_{company}_{streetName}{streetNumber}_{address2}_{zip}{city}_{phone}"
address1_regex:
- "^(?<streetName>[^\\d,]+),? (?<streetNumber>\\d+(?: ?[a-z])?)$"
- "^(?<streetNumber>\\d+(?: ?[a-z])?),? (?<streetName>[^\\d,]+)$"
additional_address_fields:
- name: streetName
required: true
Expand Down
2 changes: 2 additions & 0 deletions db/data/regions/BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ format:
show: "{firstName} {lastName}_{company}_{address1}_{address2}_{zip} {city} {province}_{country}_{phone}"
format_extended:
edit: "{country}_{firstName}{lastName}_{company}_{zip}_{streetName}{streetNumber}_{line2}{neighborhood}_{city}{province}_{phone}"
address1_regex:
- "^(?<streetName>(?!.*\\bnúmero\\b)[^\\d,]+(?<!\\s))(?:,? ?)(?<streetNumber>\\d+(?: ?[a-z])?)$"
additional_address_fields:
- name: streetName
required: true
Expand Down
2 changes: 2 additions & 0 deletions db/data/regions/CL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ format:
show: "{firstName} {lastName}_{company}_{address1}_{address2}_{zip} {city}_{province}_{country}_{phone}"
format_extended:
edit: "{country}_{firstName}{lastName}_{company}_{streetName}{streetNumber}_{line2}{neighborhood}_{zip}{city}_{province}_{phone}"
address1_regex:
- "^(?<streetName>[^\\d,]+?),? (?<streetNumber>(?:n|n\\.|nº|número|no\\.|no|#)? ?\\d+(?: ?[a-z])?)$"
additional_address_fields:
- name: streetName
required: true
Expand Down
3 changes: 3 additions & 0 deletions db/data/regions/DE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ format:
show: "{firstName} {lastName}_{company}_{address1}_{address2}_{zip} {city}_{country}_{phone}"
format_extended:
edit: "{country}_{firstName}{lastName}_{company}_{streetName}{streetNumber}_{address2}_{zip}{city}_{phone}"
address1_regex:
- "^(?<streetName>[^\\d,]+?\\.?)[, ]{1,2}(?<streetNumber>\\d+(?: ?[a-z])?)$"
- "^(?<streetName>[^\\d,]+\\.)(?<streetNumber>\\d+(?: ?[a-z])?)$"
additional_address_fields:
- name: streetName
required: true
Expand Down
2 changes: 2 additions & 0 deletions db/data/regions/ES.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ format:
show: "{firstName} {lastName}_{company}_{address1}_{address2}_{zip} {city}_{province}_{country}_{phone}"
format_extended:
edit: "{country}_{firstName}{lastName}_{company}_{streetName}{streetNumber}_{address2}_{zip}{city}{province}_{phone}"
address1_regex:
- "^(?<streetName>[^\\d,]+?),? (?<streetNumber>(?:n|n\\.|nº|número|no\\.|no|#)? ?\\d+(?: ?[a-z])?)$"
additional_address_fields:
- name: streetName
required: true
Expand Down
3 changes: 3 additions & 0 deletions db/data/regions/IL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ format:
show: "{firstName} {lastName}_{company}_{address1}_{address2}_{zip} {city}_{country}_{phone}"
format_extended:
edit: "{country}_{firstName}{lastName}_{company}_{streetName}{streetNumber}_{address2}_{zip}{city}_{phone}"
address1_regex:
- "^(?<streetName>[^\\d,]+),? (?<streetNumber>\\d+(?:\/\\d+)?)$"
- "^(?<streetNumber>\\d+(?:\/\\d+)?),? (?<streetName>[^\\d,]+)$"
additional_address_fields:
- name: streetName
required: true
Expand Down
2 changes: 2 additions & 0 deletions db/data/regions/MX.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ format:
show: "{firstName} {lastName}_{company}_{address1}_{address2}_{zip} {city} {province}_{country}_{phone}"
format_extended:
edit: "{country}_{firstName}{lastName}_{company}_{streetName}{streetNumber}_{line2}{neighborhood}_{zip}{city}{province}_{phone}"
address1_regex:
- "^(?<streetName>[^\\d,]+?),? (?<streetNumber>(?:n|n\\.|nº|número|no\\.|no|#)? ?\\d+(?: ?[a-z])?)$"
additional_address_fields:
- name: streetName
required: true
Expand Down
2 changes: 2 additions & 0 deletions db/data/regions/NL.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ format:
show: "{firstName} {lastName}_{company}_{address1}_{address2}_{zip} {city}_{country}_{phone}"
format_extended:
edit: "{country}_{firstName}{lastName}_{company}_{streetName}{streetNumber}_{address2}_{zip}{city}_{phone}"
address1_regex:
- "^(?<streetName>[^\\d]+) (?<streetNumber>\\d+(?: ?[a-z])?)$"
additional_address_fields:
- name: streetName
required: true
Expand Down
2 changes: 1 addition & 1 deletion lang/typescript/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"selector": "property",
"format": ["strictCamelCase"],
"filter": {
"regex": "^(combined_address_format)$",
"regex": "^(combined_address_format|address1_regex)$",
"match": false
}
}
Expand Down
26 changes: 26 additions & 0 deletions lang/typescript/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# @shopify/worldwide

## 0.7.0

### Minor Changes

- bbacde1: Add address1 regex for BE, BR, CL, ES, IL, MX
- b6e1c7f: Add address1 regex for DE
- ee7b7a9: Add optional tryRegexFallback param to splitAddress1 function to attempt splitting address lines that do not contain the reserved delimiter

## 0.7.0-next.2

### Minor Changes

- 3bfb56a: Add address1 regex for DE

## 0.7.0-next.1

### Minor Changes

- Add address1 regex for BE, BR, CL, ES, IL, MX

## 0.7.0-next.0

### Minor Changes

- 1f5d405: Add optional tryRegexFallback param to splitAddress1 function to attempt splitting address lines that do not contain the reserved delimiter

## 0.6.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion lang/typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@shopify/worldwide",
"description": "Utilities for parsing and formatting address fields",
"version": "0.6.0",
"version": "0.7.0",
"repository": "git@github.com:Shopify/worldwide.git",
"author": "Shopify Inc.",
"homepage": "https://github.com/Shopify/worldwide/tree/main/lang/typescript#readme",
Expand Down
7 changes: 6 additions & 1 deletion lang/typescript/rollup-plugin-regions-yaml/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const regionYamlSchema = z.object({
})
.strict()
.optional(),
address1_regex: z.optional(z.array(z.string())),
});
export type RegionYaml = z.infer<typeof regionYamlSchema>;

Expand Down Expand Up @@ -106,7 +107,10 @@ export function validateRegionYaml(
return regionYaml;
}

export type MinimalRegionYaml = Pick<RegionYaml, 'combined_address_format'>;
export type MinimalRegionYaml = Pick<
RegionYaml,
'combined_address_format' | 'address1_regex'
>;

/**
* Strip the YAML data down to only what we need to keep the resulting JS
Expand All @@ -115,5 +119,6 @@ export type MinimalRegionYaml = Pick<RegionYaml, 'combined_address_format'>;
export function transformRegionYaml(regionYaml: RegionYaml): MinimalRegionYaml {
return {
combined_address_format: regionYaml.combined_address_format,
address1_regex: regionYaml.address1_regex,
};
}
Loading

0 comments on commit b95457f

Please sign in to comment.