regex-helper-ease
v0.0.3
Published
A lightweight JavaScript library that helps structure regex quickly and easily. This library does not replace learning regex but assists in their usage by removing the concrete implementation of regex and focus on results instead.
Downloads
87
Maintainers
Readme
Regex-helper-ease
A lightweight JavaScript library that helps structure regex quickly and easily. This library does not replace learning regex but assists in their usage by removing the concrete implementation of regex and focus on results instead.
Getting started
Package installation
Installation:
npm install regex-helper-ease
Documentation
Find the complete documentation here.
Example
const regex = new RegexHelper()
.query({
// pre build regex (dd/mm/yyyy)
regex: `${EUFullDate}`,
// the name of your regex
name: 'fullDate',
// text to display if no value has been found
valueIfNotFound: 'Date not found',
})
.query({
regex: `(?:service|article) :? (${anyDigits})`,
name: 'articleOrService',
// this will capture the value of the first group (index: 1)
capturingGroup: [{ name: 'articleNumber', index: 1 }],
})
.query({
regex: `has been paid`,
name: 'isPaid',
// test only for presence (returns a boolean string, "true" | "false")
test: true,
})
// the text where to perform searching
.findIn('The article: 471 has been paid on 12/12/2022.')
// can be: 'data' | 'debug' | 'general'
.get('data');
Results
The regex displays following results:
{
fullDate: '12/12/2022',
articleOrService: 'article: 471',
articleNumber: '471',
isPaid: 'true'
}
Developer experience
This library comes with a serie of pre build regex. Special attention has been given on developer experience. Properties and methods are exhaustively documented and typed. Use your IDE's autocompletion or hover on properties and methods for help. Errors (see 'pitfalls' here) will be logged in console with explicit messages.
File a bug, got a new idea, or want to contribute?
Feel free! Open a ticket.
Changelog
V0.0.2: [MINOR] Improved typescript return type of the results.
V0.0.3: [MINOR] Escaping empty regex at initialisation and adding a general success rate in percentage in the General interface. Bug corrections and adding tests.
Discover others libraries
All libraries are permanently supported. Discover them here.