-
-
Notifications
You must be signed in to change notification settings - Fork 600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: refactor truncate string package #1097
base: develop
Are you sure you want to change the base?
Conversation
Coverage Report
The above coverage report was generated for the changes in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@steff456 Similar to string/reverse
(pr: #1082), would you mind renaming truncate-code-point
and truncate-grapheme-cluster
to truncate-code-points
and truncate-grapheme-clusters
, respectively? As in that PR, it makes sense to use the plural; otherwise, the package name suggests that one truncates a single code point or grapheme cluster, which is not the case.
Coverage Report
The above coverage report was generated for the changes in this PR. |
Coverage Report
The above coverage report was generated for the changes in this PR. |
Coverage Report
The above coverage report was generated for the changes in this PR. |
Coverage Report
The above coverage report was generated for the changes in this PR. |
lib/node_modules/@stdlib/string/base/truncate-code-points/README.md
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/string/base/truncate-code-points/README.md
Outdated
Show resolved
Hide resolved
Coverage Report
The above coverage report was generated for the changes in this PR. |
lib/node_modules/@stdlib/string/base/truncate-code-points/README.md
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/string/base/truncate-code-points/README.md
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/string/base/truncate-code-points/README.md
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/string/base/truncate-code-points/benchmark/benchmark.js
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt
Outdated
Show resolved
Hide resolved
Coverage Report
The above coverage report was generated for the changes in this PR. |
Coverage Report
The above coverage report was generated for the changes in this PR. |
Coverage Report
The above coverage report was generated for the changes in this PR. |
Coverage Report
The above coverage report was generated for the changes in this PR. |
Coverage Report
The above coverage report was generated for the changes in this PR. |
lib/node_modules/@stdlib/string/num-code-points/benchmark/benchmark.js
Outdated
Show resolved
Hide resolved
} | ||
data = data.toString(); | ||
if ( flags.lines ) { | ||
lines = data.split( RE_EOL ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be refactored. See https://github.com/stdlib-js/stdlib/blob/30019b1fc159eb3fcf59b182e62ef53997a7675f/lib/node_modules/%40stdlib/string/camelcase/bin/cli.
Please open an issue about num-grapheme-clusters
.
Coverage Report
The above coverage report was generated for the changes in this PR. |
lib/node_modules/@stdlib/string/base/truncate-code-points/README.md
Outdated
Show resolved
Hide resolved
lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: Athan <[email protected]>
lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js
Outdated
Show resolved
Hide resolved
Signed-off-by: Athan <[email protected]>
// Check for an unpaired surrogate at the end of the input string... | ||
if ( i === len - endingLength - 1 ) { | ||
// We found an unpaired surrogate... | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@steff456 Given that we break
here, does this mean we could end up with a string having fewer than the desired number of Unicode code points?
The comment on L96 says the end of the input string, but this is not precise, as it is at the end of the "eligible" string. There could be a low surrogate at the next code unit, but we don't process that character, and I believe we should be.
Is my understanding correct?
|
||
str = '𐒻𐓟𐒻𐓟𐒻𐓟𐒻𐓟𐒻𐓟'; | ||
len = 5; | ||
expected = '𐒻...'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case seems odd to me. Isn't the 𐒻
character comprised of a high and low surrogate? If so, that is a single Unicode code point, but the expected output is only 4 code point (visual) characters. Is this the intended behavior?
|
||
str = '\uD800𐓟𐒻𐓟𐒻𐓟𐒻𐓟𐒻𐓟'; | ||
len = 4; | ||
expected = '...'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, we are omitting the unpaired surrogate entirely, resulting in a string of 3 Unicode code points, which is less than len
. This also doesn't make sense to me.
I would think that we should treat unpaired high surrogates as simply another code unit. In which case, for this test, I'd expect \uD800...
.
Part of #1062
Description
This pull request:
@stdlib/string/truncate
@stdlib/string/base/truncate
@stdlib/string/base/truncate-code-point
@stdlib/string/base/truncate-grapheme-cluster
@stdlib/string/num-code-points
Related Issues
This pull request:
Questions
No.
Other
No.
Checklist
@stdlib-js/reviewers