Skip to content

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