Skip to content

Commit

Permalink
Update placekey.js (#47)
Browse files Browse the repository at this point in the history
* Update placekey.js

* Update test.yml

Updating node in test

* Update test.yml

Test updates

* Removed yarn changes
  • Loading branch information
jarredSafegraph authored Sep 24, 2024
1 parent 2dc2ce6 commit 51de4ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 18.x

- name: Bootstrap
run: |
Expand Down
7 changes: 5 additions & 2 deletions src/lib/placekey.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ const REPLACEMENT_MAP_FORWARD = {
const FIRST_TUPLE_REGEX = `[${ALPHABET}${REPLACEMENT_CHARS}${PADDING_CHAR}]{3}`;
const TUPLE_REGEX = `[${ALPHABET}${REPLACEMENT_CHARS}]{3}`;
const WHERE_REGEX = new RegExp(`^${[FIRST_TUPLE_REGEX, TUPLE_REGEX, TUPLE_REGEX].join('-')}$`);
const WHAT_REGEX = new RegExp(`^[${ALPHABET}]{3,}(-[${ALPHABET}]{3,})?$`);
const WHAT_REGEX_V1 = new RegExp(`^[${ALPHABET}]{3,}(-[${ALPHABET}]{3,})?$`);
const WHAT_REGEX_V2 = new RegExp('^[01][abcdefghijklmnopqrstuvwxyz234567]{9}$');

// Boolean for whether or not a Placekey is valid.
export function placekeyIsValid(placekey) {
Expand All @@ -82,7 +83,9 @@ export function placekeyIsValid(placekey) {
}

if (what) {
return Boolean(where.match(WHERE_REGEX) && what.match(WHAT_REGEX));
return Boolean(
where.match(WHERE_REGEX) && (what.match(WHAT_REGEX_V1) || what.match(WHAT_REGEX_V2))
);
}
return Boolean(where.match(WHERE_REGEX));
}
Expand Down
1 change: 1 addition & 0 deletions test/placekey.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ test('placekeyIsValid', t => {
t.ok(placekeyIsValid('222-zzz@abc-234-xyz'), 'double tuple what with where');
t.ok(placekeyIsValid('2222-zzz@5vg-7gq-tvz'), 'long address encoding with where');
t.ok(placekeyIsValid('222-zzzz@5vg-7gq-tvz'), 'long poi encoding with where');
t.ok(placekeyIsValid('1wvpg5h3st@628-tgw-z9f'), 'placekey fits V2');
t.ok(
placekeyIsValid('22222222-zzzzzzzzz@5vg-7gq-tvz'),
'long address and poi encoding with where'
Expand Down

0 comments on commit 51de4ac

Please sign in to comment.