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

@textlint-rule/textlint-rule-pattern

v2.0.0

Published

A textlint rule that checks by RegExp patterns.

Downloads

129

Readme

@textlint-rule/textlint-rule-pattern

A textlint rule that checks by RegExp patterns.

Features

  • Support User Defined Patterns
  • Support RegExp patterns
  • Support Replacement texts

Install

Install with npm:

npm install @textlint-rule/textlint-rule-pattern

Usage

Via .textlintrc(Recommended)

{
    "rules": {
        "@textlint-rule/pattern": {
          "patterns": [
            {
              "message": "No todo",
              "pattern": "/TODO:/i"
            },
            {
              "message": "Must to use YYYY-MM-DD instead of YYYY/MM/DD",
              "pattern": "/(\\d{4})/(\\d{2})/(\\d{2})/i",
              "replace": "$1-$2-$3",
              "allows": ["/1000/01/01/"],
              "allowNodeTypes": ["BlockQuote"]
            }
          ]
        }
    }
}

Options

  • patterns: an array of pattern object
{
    "rules": {
        "@textlint-rule/pattern": {
          "patterns": [
            /* Your rules is here! */
          ]
        }
    }
}

Pattern

The pattern object has the following properties.

export type Pattern = {
    /**
     * This error message will be shown when match the pattern
     */
    message: string;
    /**
     * Match pattern string.
     * You can use RegExp-like string.
     * https://github.com/textlint/regexp-string-matcher#regexp-like-string
     */
    pattern: string;
    /**
     * Replace string
     * You can use capture pattern like $1, $2. ($0 will be ignored)
     */
    replace?: string;
    /**
     * An array of excludes pattern.
     * If the text is matched this pattern, suppress the error.
     * You can use RegExp-like string
     * https://github.com/textlint/regexp-string-matcher#regexp-like-string
     */
    allows?: string[];
    /**
     * An array for excludes node type.
     * If the text is in the node type, suppress the error.
     * https://github.com/textlint/textlint/blob/master/docs/txtnode.md#type
     * For example, if you want to ignore the text in block quote and link
     * "allowNodeTypes": ["Link", "BlockQuote"]
     */
    allowNodeTypes?: string[];

    /**
     * This rule ignore Code and CodeBlock by default.
     * If you want to check the code, please put this true
     */
    forceCode?: boolean;
};

RegExp-like String

This textlint rule use RegExp-like string for option value. :memo: g(global) flag and u(unicode) is added by default.

| Input | Ouput | Note | |--------------|---------|----------------------------------------------------| | "str" | /str/gu | convert string to regexp with global | | "/str/" | /str/gu | | | "/str/g" | /str/gu | Duplicated g is just ignored | | "/str/i" | /str/igu | | | "/str/u" | /str/ug | | | "/str/m" | /str/mgu | | | "/str/y" | /str/ygu | | | --- | --- | --- | | "/\\d+/" | /\d+/gu | You should escape meta character like \d | | "/(\\d+)/" | /\d+/gu | You can use capture. replace $1 with the capture |

For more information, please see textlint/regexp-string-matcher README.

Examples

Match by RegExp

If you want to found TODO: text, you can write following:

{
    "rules": {
        "@textlint-rule/pattern": {
          "patterns": [
            {
              "message": "No todo",
              "pattern": "/TODO:/i"
            }
          ]
        }
    }
}

Replace the match

If you want to replace YYYY/DD/MM to YYYY-DD-MM format, you can write following:

e.g. 2000/01/01 will be 2000-01-01 by textlint --fix.

:memo: replace mark is starts with $1.

{
    "rules": {
        "@textlint-rule/pattern": {
          "patterns": [
            {
              "message": "Must to use YYYY-MM-DD instead of YYYY/MM/DD",
              "pattern": "/(\\d{4})/(\\d{2})/(\\d{2})/i",
              "replace": "$1-$2-$3"
            }
          ]
        }
    }
}

Check code texts

If you want to check text in a CodeBlock, you need to enable forceCode flag.

{
    "rules": {
        "@textlint-rule/pattern": {
          "patterns": [
            {
              "message": "No todo in code",
              "pattern": "/TODO \\[Issue #\\d+\\]:/i",
              "forceCode": true
            }
          ]
        }
    }
}

Changelog

See Releases page.

Related

Running tests

Install devDependencies and Run npm test:

npm test

Contributing

Pull requests and stars are always welcome.

For bugs and feature requests, please create an issue.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

License

MIT © azu