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

peeler

v1.4.0

Published

parser for only bracket.

Downloads

4

Readme

peeler npm version GitHub Actions

NPM

parser for only bracket.

Install

$ npm install peeler
$ yarn add peeler

Usage

> import peeler from 'peeler'
> peeler('before(hit)after')
[ { nodeType: 'text',
    pos: { start: 0, end: 6, depth: 0 },
    content: 'before' },
  { nodeType: 'bracket',
    pos: { start: 6, end: 10, depth: 0 },
    open: '(',
    close: ')',
    nodes:
     [ { nodeType: 'text',
         pos: { start: 7, end: 10, depth: 1 },
         content: 'hit' } ] },
  { nodeType: 'text',
    pos: { start: 11, end: 16, depth: 0 },
    content: 'after' } ]

> peeler('aa(bb{cc}bb)aa')
[ { nodeType: 'text',
    pos: { start: 0, end: 2, depth: 0 },
    content: 'aa' },
  { nodeType: 'bracket',
    pos: { start: 2, end: 11, depth: 0 },
    open: '(',
    close: ')',
    nodes:
     [ { nodeType: 'text',
         pos: { start: 3, end: 5, depth: 1 },
         content: 'bb' },
       { nodeType: 'bracket',
         pos: { start: 5, end: 8, depth: 1 },
         open: '{',
         close: '}',
         nodes:
          [ { nodeType: 'text',
              pos: { start: 6, end: 8, depth: 2 },
              content: 'cc' } ] },
       { nodeType: 'text',
         pos: { start: 9, end: 11, depth: 1 },
         content: 'bb' } ] },
  { nodeType: 'text',
    pos: { start: 12, end: 14, depth: 0 },
    content: 'aa' } ]

API

peeler(name, [option])

input

Type: string

text to parse.

return

Type: PNode[]

type PNode = PNodeText | PNodeBracket
type PNodeText = {
  nodeType: 'text',     // plain text part
  content: string,  // innerText
  pos: {
    start: number,    // position of text
    end: number,
    depth: number,    // nest count
  }
}

type PNodeBracket = {
  nodeType: 'bracket',
  open: string,     // bracket charactor
  close: string,
  nodes: PNode[],   // children nodes
  pos: {
    start: number,
    end: number,
    depth: number,
  },
}

pair option

default ['()', '{}', '[]']

> peeler('[(__)]', { pairs: ['[]', '<>'] }) // skip '(' bracket
[ { nodeType: 'bracket',
    pos: { start: 0, end: 5, depth: 0 },
    open: '[',
    close: ']',
    nodes:
     [ { nodeType: 'text',
         pos: { start: 1, end: 5, depth: 1 },
         content: '(__)' } ] } ]

quotes option

default []

> peeler(`( < escape [[( > " ' \\" " )`, {
    quotes: [ `"`, `'`, `<>`, /* pair enable */ ],
  })

[ { nodeType: 'bracket',
    open: '(',
    close: ')',
    nodes:
      [ { nodeType: 'text',
          pos: { start: 1, end: 26, depth: 1 },
          content: ` < escape [[( > " ' \\" " ` } ],
    pos: { start: 0, depth: 0, end: 26 },
    content: `( < escape [[( > " ' \\" " )`,
    innerContent: ` < escape [[( > " ' \\" " ` } ]

default Options

const defaultOptions: Options = {
  pairs: ['()', '{}', '[]'],
  nestMax: 100,
  escape: '\\',
  includeEmpty: false,
  quotes: [],
}

more example

import peeler from '.'
import type { PNode } from './types'

const print = (node: PNode) => {
  const nest = '- '.repeat(node.pos.depth)
  if (node.nodeType === 'text') {
    console.log(nest + node.content)
    return
  } else {
    console.log(nest + node.open)
    node.nodes.map(print)
    console.log(nest + node.close)
  }
}

peeler(`(hello(world(\\\\('ω'\\)/){[A](B)}))`).map(print)
(
- hello
- (
- - world
- - (
- - - \('ω')/
- - )
- - {
- - - [
- - - - A
- - - ]
- - - (
- - - - B
- - - )
- - }
- )
)

Related works

License

MIT © elzup

Contributors

Thanks goes to these wonderful people (emoji key):

| elzup💻 ⚠️ | | :---: |

This project follows the all-contributors specification. Contributions of any kind welcome!