npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pattern-matcha

v1.4.1

Published

Performs formatting and sanitization on English and Arabic text based on regular expressions to produce consistent texts.

Downloads

28

Readme

Pattern Matcha

This is a library that compiles a collection of useful regex patterns to be able to format texts in English and Arabic in a consistent manner.

This is useful for translators that want to be able to produce consistent looking translations with their original source texts in various lifecycles of any given text.

At the moment there are three phases for formatting:

  1. onPaste: These are formatting one wants to apply to a text when a text is pasted into a input field. Generally these are preformatting rules.
  2. onBlur: These are the formatting one wants to apply to a text anytime a text field containing the text is unfocused (ie: the blur event).
  3. onSanitize: These are formatting one wants to apply during a sanitization phase, generally saves or querying and normalization of text so that an app can eliminate noise such as diacritics from the text.

Table of Contents

  1. Installation
  2. API Usage
  3. Performance Considerations
  4. License

Demo

See it in action here.

Installation

To install Pattern Matcha, use npm:

npm install pattern-matcha

API Usage

getArabicRules

Returns a Rules object with rules applicable for Arabic text formatting.

import { getArabicRules } from 'pattern-matcha';

const arabicRules = getArabicRules();

getEnglishRules

Returns a Rules object with rules applicable for English text formatting.

import { getEnglishRules } from 'pattern-matcha';

const englishRules = getEnglishRules();

getArabicFormattingRules

Retrieves rules for Arabic text formatting, specifically for scenarios where text is pasted or loses focus.

import { getArabicFormattingRules } from 'pattern-matcha';

const formattingRules = getArabicFormattingRules();

getArabicSanitizingRules

Retrieves rules for sanitizing Arabic text.

import { getArabicSanitizingRules } from 'pattern-matcha';

const sanitizingRules = getArabicSanitizingRules();

getEnglishOnBlurRules

Retrieves rules for English text formatting typically on onBlur events.

import { getEnglishOnBlurRules } from 'pattern-matcha';

const onBlurRules = getEnglishOnBlurRules();

getArabicOnBlurRules

Retrieves rules for Arabic text formatting on onBlur events.

import { getArabicOnBlurRules } from 'pattern-matcha';

const arabicOnBlurRules = getArabicOnBlurRules();

getArabicOnPasteRules

Retrieves rules for Arabic text formatting on onPaste events.

import { getArabicOnPasteRules } from 'pattern-matcha';

const arabicOnPasteRules = getArabicOnPasteRules();

getEnglishOnPasteRules

Retrieves rules for English text formatting on onPaste events.

import { getEnglishOnPasteRules } from 'pattern-matcha';

const englishOnPasteRules = getEnglishOnPasteRules();

getArabicOnSanitizeRules

Retrieves rules for Arabic text formatting on onSanitize events.

import { getArabicOnSanitizeRules } from 'pattern-matcha';

const arabicOnSanitizeRules = getArabicOnSanitizeRules();

getRulesByName

Returns a new Rules object containing rules specified by their names.

import { getRulesByName } from 'pattern-matcha';

const specificRules = getRulesByName('applySmartQuotes', 'cleanSpacesBeforePeriod');

Performance Considerations

  • Regex Complexity: Given the reliance on regular expressions, performance may vary based on the complexity and length of the patterns and the text being processed. Complex regex patterns can lead to increased time complexity, particularly for longer texts.
  • Number of Rules: The runtime complexity increases with the number of rules being applied, as each rule implies a separate scan of the text.
  • Text Length: Longer texts will naturally take more time to process as each rule needs to be applied across the entire text body.

License

Pattern Matcha is MIT licensed.