Skip to content

refactor(rfc): abbreviate charClass and charRange #40

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

Merged
merged 2 commits into from
Dec 30, 2023

Conversation

mdjastrzebski
Copy link
Member

Summary

Change following names to shorter:

  • characterClass => charClass
  • characterRange =>charRange

Motivation

The usage of characterClass & characterRange (frequently together) creates lengthy expressions.

const hexDigit = characterClass(
  characterRange('a', 'f'),
  characterRange('A', 'F'),
  characterRange('0', '9')
);

These names are much longer then other regex components (anyOf, capture, oneOrMore, etc.), yet are relatively frequently used. In order to reduce the taken space I propose using char instead of character in their names.

const hexDigit = charClass(charRange('a', 'f'), charRange('A', 'F'), charRange('0', '9'));

The char abbreviation is already used in 1st party JS APIs: e.g.,:

  • String.charAt()
  • String.charCodeAt()
  • String.fromCharCode()

@okwasniewski, @jaworek wdyt?

@mdjastrzebski mdjastrzebski merged commit de93567 into main Dec 30, 2023
@mdjastrzebski mdjastrzebski deleted the refactor/rfc-char-abbreviation branch December 30, 2023 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant