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

ocnparse

v1.2.1

Published

Simple unicode and Baha'i term compatible parser

Downloads

6

Readme

Ocnparse

OcnParse is a set of tokenizing tools compatible with Baha'i terms Since \b in regex cannot deal with words that include unicode, dashes or single quotes

Install the interface module into your node project with:

npm install --save ocnparse

Functionality

// import the parser 
const parser = require('ocnparse')  

parser.tokenize(str, tag='')
// returns array of tokens, each an object with three properties: prefix, word and suffix. 
// .prefix and .suffix contain any punctuation or markup. 
// .word contains the core word (which can also contain <u> markup).
// include a tag if the string being parsed is already word-wrapped (this preserves wrapper tag attributes)

parser.rebuild(tokens, tag='')
// returns the reconstructed text with some options for inserting changes
// include a tag if you want to wrap each word 
// wrapper tags contain any classes in token.info.class[] and data attrs in token.data.data{}

parser.reWrap(str, srcTag='w', destTag='')
// helper function to parse wrapped text, correct tokens and output new word-wrapped string 
// user can use this whenever text is edited -- or change the wrapper tags easily 
// preserves wrapper class and data attributes

Implementation Example:

const parser = require('ocnparse')  

// For example, say we want to wrap each word in a <span>...</span>
let tokens = parser.tokenize("Four score!!!") 
let result = parser.rebuild(tokens, 'span')
// result: "<span>Four </span><span>score!!!</span>"

// For example, say we want to rewrap words wrapped in <span>...</span> to <w>...</w>
let str = `<span class='first'>Four </span><span data-whatever='12'>score!!!</span>`
let result = parser.rewrap(str, 'span', 'w')
// result: `<w class="first">Four </w><w data-whatever="12">score!!!</w>`

// Or our wrapped phrase has been edited and we need to re-wrap to correct it
let str = `Hmm. <span class="first">Four three </span><span data-whatever="12">score!!!</span>`
let result = parser.rewrap(str, 'span')
// result: `<span>Hmm. </span><span class="first">Four </span><span>three </span><span data-whatever="12">score!!!</span>`