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

poliparser

v2.0.0

Published

The only parser you need

Downloads

19

Readme

Poliparser

Build Status Coverage Status npm license size npm

Poliparse is used to extract and parse data from strings, files, urls and many other objects in a simple and fast way.

The Default modules allows you to parse:

  • String
  • Array
  • Object
  • DOM Elements
  • JSON
  • CSV
  • Hash & Chipertext

You can use the default modules or easily add your custom one ( see all the modules on the Examples page ).

Install

npm install --save poliparser 

Usage

Import and Instantiate Poliparser

const Poliparser = require('poliparser');

let p = new Poliparser();

set a parser template, In this example is used the module between from str library.

p.setParser({
	m: 'str_between',
	from: '<title>',
	to: '</title>'
});
let data = `<title>hello</title>
	<div class=".container">
		<a href="link1.html">link1</a>
	</div>`;

let output = p.parse(data);

console.log(output);

output

hello

ps. The fastest way is to pass it in the declaration like this

let p = new Poliparser({
	m: 'between',
	from: '<title>',
	to: '</title>'
});

Documentation

See Here for complete modules documentation and Here for real world examples.

Add Module

You can use setModule() and requireModule() to add custom modules.

let p = new Poliparser();

p.setModule('my_parse_module', (data, block) => {
	return data.map(x => x * block.value);
});

p.setParser({
	m: 'my_parse_module',
	value: 3
});

let out = p.parse([1,2,3]);

console.log(out);

same as

let p = new Poliparser();

p.requireModule('my_parse_module', 'myModule.js');

p.setParser({
	m: 'my_parse_module',
	value: 3
});

let out = p.parse([1,2,3]);

console.log(out);
//myModule.js
module.exports = (data, block) => {
	return data.map(x => x * block.value);
};

output

[ 3, 6, 9 ]

Add Library

You can add a new library with the setLibrary or requireLibrary method.

let p = new Poliparser();

p.setLibrary('myLib', {
	mul: (data, block) => {
		return data * block.value;
	},
	sum: (data, block) => {
		return data + block.value;
	}
});

p.setParser([{
	m: 'myLib_mul',
	value: 3
},{
	m: 'myLib_sum',
	value: 2
}]);

let out = p.parse(10);

console.log(out);

same as

let p = new Poliparser();

p.requireLibrary('myLib', 'myLib.js');

p.setParser([{
	m: 'myLib_mul',
	value: 3
},{
	m: 'myLib_sum',
	value: 2
]);

let out = p.parse(10);

console.log(out);
//myLib.js
module.exports = {
	mul: (data, block) => {
		return data * block.value;
	},
	sum: (data, block) => {
		return data + block.value;
	}
}

output

32