-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix AJV runtime validation code ESM compatibility (#261)
This is a different approach to the fix in #256 because that was not playing nicely with Rollup bundler.
- Loading branch information
1 parent
74a3d0d
commit cc8722f
Showing
2 changed files
with
20 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export default function ucs2length(str: string): number { | ||
const len = str.length | ||
let length = 0 | ||
let pos = 0 | ||
let value | ||
while (pos < len) { | ||
length++ | ||
value = str.charCodeAt(pos++) | ||
if (value >= 0xd800 && value <= 0xdbff && pos < len) { | ||
// high surrogate, and there is a next character | ||
value = str.charCodeAt(pos) | ||
if ((value & 0xfc00) === 0xdc00) pos++ // low surrogate | ||
} | ||
} | ||
return length | ||
} |