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

carbon-filter

v1.1.0

Published

Data filters for the CarbonJS Framework or to be used standalone

Downloads

24

Readme

CarbonJS Filters / carbon-filter

The carbon-filter module provides a set of commonly used data filters. This means you can run your data through a set of filters after you've received user's input or before you insert data into your database. You can use it as a stand-alone module or most commonly with carbon-form module which filters form data automatically for you.

If you've ever worked with any Zend_Filter filter from the Zend Framework you will be familiar with it's sintax and if you haven't then scroll down to the "Usage" section and you'll be up-and-running in no time.

Installation

npm install carbon-filter [--save]

Usage

The carbon-filter module packs some of the most used filters which share the same interface. Each filter provides public access to the function filter which receives only one parameter and returns filtered data. Some filters have options so that you can customize it to your needs.

The function filter has the following prototype Filter.prototype.filter = function(value) and it is common to all filters. It has 1 parameter:

  • value - Input value that needs to be filtered.

Stand-alone

var Filter = require("carbon-filter");

var stripTags = new Filter.StripTags({
    allowedTags: ["div", "span", "h1", "br"]
});

var inputValue = "...";
var filteredValue = stripTags.filter(inputValue);

With carbon-form

var Form = require("carbon-form");
var Filter = require("carbon-filter");

var form = new Form();

form.addElements([
    new Form.Element.Text("name", {
        label: "Name",
        filters: [
            new Filter.StringTrim(),
            new Filter.StripTags({
                allowedTags: ["div", "span"],
                allowedAttributes: ["id", "class"]
            })
        ]
    });
]);

Filters

StringTrim

Trims the beginning and the end of a string.

StripTags

Strips HTML tags from the input. You can specify which tags or attributes you'd like to leave (if any).

Options

  • allowedTags [Array] - Tags from the input that you want to keep in the output.
  • allowedAttributes [Array] - Attributes of HTML tags from the input that you want to keep in the output.

Contributing

If you're willing to contribute to this project feel free to report issues, send pull request, write tests or simply contact me - Amir Ahmetovic

Licence

This software is available under the following licenses:

  • MIT