Coder Social home page Coder Social logo

a6b8 / patternfinder Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 31 KB

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.

Home Page: https://www.npmjs.com/package/patternfinder

License: MIT License

JavaScript 100.00%
patterns publickey regex

patternfinder's Introduction

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 ) )

Find more Informations here: ...data/presets.mjs#L53

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. null, undefined =
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.

patternfinder's People

Contributors

a6b8 avatar

Watchers

 avatar  avatar

patternfinder's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.