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

react-lens

v1.0.0-alpha.1

Published

Angular like simple and quick data filter / formatter to show for React.

Downloads

27

Readme

Build Status dependencies Status peerDependencies Status

NPM

react-lens

Angular like simple and quick data filter / formatter to show for React.

react-lens is under development now, It is time to contribute :blush:.

If you have created your own lens and you think it is useful that should be built-in lens, then open pull-request now :zap:.

Table of Content

Demos

Here is a simple demo for collections of built-in lenses. Go to demo page.

Install

npm install react-lens

Usage / Example

With Ecma Script 6 and React Loaders

import React from 'react';
import ReactDOM from 'react-dom';
import Lens from 'react-lens';

const Example = props => (
  <div>
    <Lens filter="currency">{5.2}</Lens>
  </div>
);

ReactDOM.render(<Example />, document.getElementById('dom_id'));

It will print $ 5.20 without any customizations. For more examples go to demo page.

Properties

  • container specifies return element tag of <Lens />. Default is span.
  • filter selects which lens will be used to filter / format given value.

Built-in Lenses (Filters)

  • currency Formats number to show as currency. Parameters;

    1. Currency symbol. Default is $.
    2. Specifies number of decimals. Default is 2.
    3. Direction of currency symbol. Options are R and L. Default is L.
  • date Formats date. Parameters;

    1. Date format. For formatting dateformat npm package is used. Default is dd.mm.yyyy.
  • json Stringifies objects

  • lowercase Makes string lower case

  • uppercase Makes string upper case

  • foreach Divides given array in to elements. Parameters;

    1. Child element tag.

Making New Lenses (Filters)

You can jump directly to An Example to Create Lens - repeater instead of reading API.

Or you can look into src/lenses - built-in lenses.

Importing make

import { make } from 'react-lens';

make Function Interface

make (lensName: string, inputType: string, rendererCallbackFunction: function): void

  • lensName is lens / filter name to use as filter props of <Lens /> instance.
  • inputType is type of child that will be given through <Lens />.
  • renderer is called when that filter is used and the child is given as parameter.

renderer Callback Interface

rendererCallbackFunction (content: <inputType>, param1: string, param2: string ,...): string | number | React.Component | Array<React.Component>

  • content is content to filter / format given as child through <Lens />.

  • Other repeatable parameters comes from filter props of <Lens />. For example;

    <Lens filter="yourfilter : param1 : param2">{content}</Lens>

An Example to Create Lens - repeater

Let's make a filter that repeats given content given param times.

// File: lens-repeater.js
import { make } from 'react-lens';

make('repeater', 'string', (content, times = 2) => {
  let result = '';
  for(let i = 0; i < times; i++) {
    result += content;
  }
  return result;
});
// File: example.js
import React form 'react';
import ReactDOM form 'react-dom';
import Lens from 'react-lens';
import './lens-repeater';

ReactDOM.render(
  <div>
    <h3>Repeater Lens Example</h3>
    <Lens filter="repeater : 3">Hello</Lens>
  </div>,
  document.getElementById('dom_id')
);

It will prompt "HelloHelloHello".

By the way, have to say that, in example.js we imported ./lens-repeater. You don't have to import our lenses in each file which you use that lens. It's enough to import once in any parent or root file.

Development / Contributing

If you like to add or improve something, follow these steps.

# Change dir to your playground folder and clone repository.
git clone [email protected]:alpertuna/react-lens.git

# Enter cloned folder and install necessary development node libraries
cd react-lens
npm install

Folders and Files

  • src folder keeps all source files of react-lens
  • demo is playground folder to develop react-lens.

Under demo folder, index.html is index file of our web server. You don't need to touch here if you don't want to add any other external js or css files. App.js file is entry point for our react application, and you can test your alterations in here. There is a working example in App.js and it imports react-lens directly from source code, that's why there is no need to build it while developing.

To run dev server,

npm start

And open localhost:8080 in browser. Dev server uses webpack and it has hot modul replecament plugins, so when you change and save any source file, it will rebuild virtual bundle and send signal browser to refresh page automaticly.

Source Code Writing Standarts

For source code quality, I applied Airbnb rules.

Other Scripts

# Builds js dist file
npm run build-dist-js

# Builds minified js dist file
npm run build-dist-js-min

# Builds all dist files
npm run build-dist

# Lints js files according to Airbnb rules using Eslint
npm run lint-confs
npm run lint-src
npm run lint-demo

# Runs all necessary test scripts
npm test