Skip to content
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

docs: difference between @stdlib/regexp/whitespace and \s? #3107

Open
2 tasks done
xuhdev opened this issue Nov 12, 2024 · 8 comments
Open
2 tasks done

docs: difference between @stdlib/regexp/whitespace and \s? #3107

xuhdev opened this issue Nov 12, 2024 · 8 comments
Labels
Documentation Improvements, additions, or changes to documentation. Help Wanted Extra attention is needed.

Comments

@xuhdev
Copy link

xuhdev commented Nov 12, 2024

Description

The doc of regex/whitespace says:

Returns a regular expression to match a white space character.

But \s does the same thing:

Matches a single white space character, including space, tab, form feed, line feed, and other Unicode spaces. Equivalent to [\f\n\r\t\v\u0020\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]. For example, /\s\w*/ matches " bar" in "foo bar".

I think an explanation in the doc can be helpful. The git history of the library also doesn't shed any light on the reason. (Perhaps it was created at a time when JS was less powerful?)

Related Issues

No response

Questions

No response

Demo

No response

Reproduction

Expected Results

Actual Results

Version

No response

Environments

N/A

Browser Version

No response

Node.js / npm Version

No response

Platform

No response

Checklist

  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
@stdlib-bot
Copy link
Contributor

👋 Hi there! 👋

And thank you for opening your first issue! We will get back to you shortly. 🏃 💨

@kgryte kgryte changed the title Unclear documentation: Why would someone use @stdlib/regexp/whitespace instead of \s? docs: Why would someone use @stdlib/regexp/whitespace instead of \s? Nov 12, 2024
@kgryte
Copy link
Member

kgryte commented Nov 13, 2024

@xuhdev Thanks for raising this issue. The two are not equivalent. E.g.,

In [1]: var s = '\u0085'
Out[1]: '\x85'

In [2]: /\s/.test(s)
Out[2]: false

In [3]: reWhitespace.REGEXP.test(s)
Out[3]: true

You are right that we should be more explicit in the documentation. We do implicitly document the difference in the source code:

Namely, ECMAScript does not consider the NEL unicode character to be whitespace, as demonstrated above; however, we consider the line terminator to be whitespace.

@kgryte kgryte changed the title docs: Why would someone use @stdlib/regexp/whitespace instead of \s? docs: difference between @stdlib/regexp/whitespace and \s? Nov 13, 2024
@kgryte kgryte added Documentation Improvements, additions, or changes to documentation. Help Wanted Extra attention is needed. labels Nov 13, 2024
@yuvi-mittal
Copy link
Contributor

Can i work on this issue ?

@kgryte
Copy link
Member

kgryte commented Nov 18, 2024

@yuvi-mittal Feel free to submit a PR.

@AyushkhatiDev
Copy link

AyushkhatiDev commented Nov 18, 2024

let me solve this issue

@yuvi-mittal
Copy link
Contributor

yuvi-mittal commented Nov 18, 2024 via email

@yours7himanshu
Copy link

@xuhdev Thanks for raising this issue. The two are not equivalent. E.g.,

In [1]: var s = '\u0085'
Out[1]: '\x85'

In [2]: /\s/.test(s)
Out[2]: false

In [3]: reWhitespace.REGEXP.test(s)
Out[3]: true
You are right that we should be more explicit in the documentation. We do implicitly document the difference in the source code:

stdlib/lib/node_modules/@stdlib/regexp/whitespace/lib/regexp.js

Line 54 in b8259d3

    • \u0085
      Namely, ECMAScript does not consider the NEL unicode character to be whitespace, as demonstrated above; however, we consider the line terminator to be whitespace.

@kgryte there is only one line difference between the two - @stdlib/regexp/whitespace considers the NEL Unicode character (\u0085) as whitespace, while ECMAScript's \s does not as simple as that i have to submit the PR request for this can u please tell which repo consist the source code of stlib.io/docs website?

@kgryte
Copy link
Member

kgryte commented Dec 10, 2024

@yours7himanshu You should update the respective package README in this repository, as this repository contains all relevant source documentation. The website is simply the collection of package READMEs converted to HTML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements, additions, or changes to documentation. Help Wanted Extra attention is needed.
Projects
None yet
Development

No branches or pull requests

6 participants