Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Remove the need to have numeric suffixes (#150)
Browse files Browse the repository at this point in the history
* Remove the need to have numeric suffixes

* Changeset

* Format
  • Loading branch information
mateuszradomski authored Mar 8, 2024
1 parent 44dbf05 commit d0a563d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
6 changes: 6 additions & 0 deletions packages/discovery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @l2beat/discovery

## 0.44.5

### Patch Changes

- Remove the need to have numeric suffixes in normalizing diff path

## 0.44.4

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/discovery/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@l2beat/discovery",
"description": "L2Beat discovery - engine & tooling utilized for keeping an eye on L2s",
"version": "0.44.4",
"version": "0.44.5",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
Expand Down
20 changes: 5 additions & 15 deletions packages/discovery/src/discovery/utils/normalizeDiffPath.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ describe(normalizeDiffPath.name, () => {
})

it('should throw on different prefix', () => {
expect(() => normalizeDiffPath('test.values.0')).toThrow(
'Expected test.values.0 to have only numeric suffixes',
)
expect(normalizeDiffPath('test.values.0')).toEqual('test.values.0')
})
})

Expand All @@ -69,17 +67,9 @@ describe(removeArraySuffix.name, () => {
})

it('should throw if the suffix is not a decimal number', () => {
expect(() => removeArraySuffix('test.a')).toThrow(
'Expected test.a to have only numeric suffixes',
)
expect(() => removeArraySuffix('test.1a')).toThrow(
'Expected test.1a to have only numeric suffixes',
)
expect(() => removeArraySuffix('test.1e2')).toThrow(
'Expected test.1e2 to have only numeric suffixes',
)
expect(() => removeArraySuffix('test.0.')).toThrow(
'Expected test.0. to have only numeric suffixes',
)
expect(removeArraySuffix('test.a')).toEqual('test.a')
expect(removeArraySuffix('test.1a')).toEqual('test.1a')
expect(removeArraySuffix('test.1e2')).toEqual('test.1e2')
expect(removeArraySuffix('test.0.')).toEqual('test.0.')
})
})
8 changes: 4 additions & 4 deletions packages/discovery/src/discovery/utils/normalizeDiffPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ export function removeArraySuffix(path: string): string {

assert(rest.length >= 1, `Unreachable code`)
assert(name !== undefined, `Unexpected undefined value`)
assert(
rest.every((p) => p.length > 0 && isIntNumeric(p)),
`Expected ${path} to have only numeric suffixes`,
)

if (!rest.every((p) => p.length > 0 && isIntNumeric(p))) {
return path
}
return name
}

Expand Down

0 comments on commit d0a563d

Please sign in to comment.