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

patternfinder

v0.0.1

Published

This tool helps you find patterns in text. It's handy for spotting particular sequences in public keys, making it easier to locate addresses. Plus, it adds a bit of fun to pattern hunting.

Downloads

3

Readme

CircleCI

Pattern Finder

This tool helps you find patterns in text. It's handy for spotting particular sequences in public keys, making it easier to locate addresses. Plus, it adds a bit of fun to pattern hunting.

For Inspiration: 12 Zeros Address

Quickstart

npm i patternfinder
import { PatternFinder } from 'patternfinder'
const patternFinder = new PatternFinder()
const result = patternFinder
    .getResult( { 
        'str': '0000abcdefghijklmnop00000', 
        'presetKey': 'startsAndEndsWithZeros',
        'flattenResult': false
    } )
console.log( JSON.stringify( result, null, 4 ) )

Table of Contents

  • Pattern Finder
  • Quickstart
  • Table of Contents
  • Methods
    • getPresetKeys()
    • getResult()
    • setPreset()
  • Challenges
  • License

Methods

The module has the main method .getResults() that processes a string using predefined presets in just a few lines. You can query all loaded preset keys with getPresetKeys(). You can create your custom presets using setPreset(), which are then available through .getResults().

getPresetKeys()

This method returns all available presets, including those added later via .setPresets().

import { PatternFinder } from 'patternfinder'
const patternFinder = new PatternFinder()
const presetKeys = patternFinder.getPresetKeys()
console.log( `Available PresetsKeys: ${presetKeys.join( ', ' )}` )

getResult()

.getResult( { str, presetKey, flattenResult=false } )

| Key | Type | Description | Required | | ------------- | ------ | --------------------------------------------------- | -------- | | str | String | The string to be analyzed. | true | | presetKey | String | The preset to use. | true | | flattenResult | Object, Boolean | Override the default values to force a detailed result. Depending on the method, additional information may be available. | true |

import { PatternFinder } from 'patternfinder'
const patternFinder = new PatternFinder()
const result = patternFinder
    .getResult( { 
        'str': '0000abcdefghijklmnop00000', 
        'presetKey': 'startsAndEndsWithZeros',
        'flattenResult': false
    } )
console.log( JSON.stringify( result, null, 4 ) )

setPreset()

This method allows you to preload your custom challenges so that they can be accessed via getResult().

.setPreset( { presetKey, challenge } )

| Key | Type | Description | Required | | ------------- | ------ | --------------------------------------------------- | -------- | | presetKey | String | Expects the key under which the challenge is to be found. | true | | challenge | Object | Contains all the information needed to perform a challenge. | true |

import { PatternFinder } from 'patternfinder'
const patternFinder = new PatternFinder()
const preset = {
    'presetKey': 'customPreset',
    'challenge':         {
        'logic': {
            'and': [
                {
                    'value': '0',
                    'description': 'Search for a given character.',
                    'method': 'inSuccession',
                    'option':  'startsWith', // 'inBetween', // 'endsWith',
                    'expect': {
                        'logic': '>=',
                        'value': 2
                    }
                }
            ]
        }
    }
}

const search = '000abcdefghi'
const result = patternFinder
    .setPreset( preset )
    .getResult( { 
        'str': search, 
        'presetKey': 'customPreset',
        'flattenResult': true
    } )

console.log( JSON.stringify( result, null, 4 ) )

You can find all default presets here: ./src/data/presets.mjs

Challenges

A preset consists of a presetKey name, an optional description, and the actual logic section.

| Operator | Description | | -------- | ------------------------------------------------------ | | and | Requires that all patterns be found. | | or | Requires that at least one pattern be found. |

The following basic operators are available: and and or. and expects all patterns to be found, while or expects at least one pattern to be found.

| Search Type | Description | Options | Logic | | ----------------- | ----------------------------------------------------------- | ----------------- | --------- | | regularExpression | Allows complex search patterns using regular expressions. | | = | | inSuccession | Allows counting the same characters at the beginning, end, or anywhere in the text and comparing with a number. | startsWith, endsWith, inBetween | =, >, >=, <, <= |

There are currently two different basic search types: regularExpression and inSuccession. regularExpression allows for high complexity, while inSuccession allows counting the same characters at the beginning (startsWith), end (endsWith), or anywhere in the text (inBetween). You can specify a number using the expect.value key and a comparison operator using expect.logic.

These individual patterns can be grouped as described above using and and or, and the additional function in getResults({ ... flattenResults: 'true' }) simplifies the output with a Boolean value.

In this example, it searches for 0s that are in sequence at the beginning of the string. If there are at least 2, it is considered true.

const preset = {
    'presetKey': 'customPreset',
    'challenge': {
        'logic': {
            'and': [
                {
                    'value': '0',
                    'description': 'Search for a given character.',
                    'method': 'inSuccession',
                    'option':  'startsWith', // 'inBetween', // 'endsWith',
                    'expect': {
                        'logic': '>=',
                        'value': 2
                    }
                }
            ]
        }
    }
}

You can find all default presets here: ./src/data/presets.mjs

License

This project is licensed under the MIT License - see the LICENSE file for details.