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

@ftchinese/cascade

v1.0.3

Published

The methods of building cascade select elements, including the method related with data processing.

Downloads

7

Readme

Cascade

The methods of building cascade select elements, including the method related with data processing.

Introduce

This is a tool for producing a form part comprised of a series of "select" elements. The data of them are cascaded, so there is also a method to convert common data to the data with specified structure.

Installation

npm install "@ftchinese/cascade" --save

Import

import cascade from "@ftchinese/cascade";

API

cascade.dealData(inputData, fieldArr)

Convert common data to data with specified structure.

Usage Example

const dealData = cascade.dealData;
const myDealedData = dealData(myRawData,["province","city","shop","phone"]);

param

  • @param inputData: TYPE Array, it shoud be specfied structure like the Eg Data1:
    [
    {"province":"安徽","city":"蚌埠","shop":"蚌埠分公司"},
    {"province":"安徽","city":"阜阳","shop":"阜阳分公司"},
    {"province":"安徽","city":"合肥","shop":"合肥分公司1"},
    {"province":"安徽","city":"合肥","shop":"合肥分公司2"},
    {"province":"江苏","city":"苏州","shop":"苏州分公司"},
    {"province":"江苏","city":"常州","shop":"常州分公司1"},
    {"province":"江苏","city":"常州","shop":"常州分公司2"},
    {"province":"江苏","city":"常州","shop":"常州分公司3"},
    {"province":"江苏","city":"淮安","shop":"淮安分公司1"},
    {"province":"江苏","city":"淮安","shop":"淮安分公司2"}
    ]
  • @param keyArray:Type Array, each item is a string. The func will process data following the order of this array.Here,it can be:["provice","city","shop"]

more detail

1. How to get the input data in correct structure?

It is simple to get your input data(as structure of Eg Data1).

Usually, our raw data is excel data, like:

province | city | shop ---------|------|----- 安徽|蚌埠|蚌埠分公司 安徽|阜阳|阜阳分公司 安徽|合肥|合肥分公司 安徽|合肥|合肥分公司 江苏|苏州|苏州分公司 江苏|常州|常州分公司1 江苏|常州|常州分公司2 江苏|常州|常州分公司3

There are a lot of tools of translating this excel data to Eg Data1, such as http://www.bejson.com/json/col2json/. What you need to do is just copying the excel data, pasting it in the page, and clicking the convert button. Then you can get the data like Eg Data1.

2. It can only process the data with 3 fields?

No. You can have any number of fields as many as you like.

new cascade.Cascade(myDealeddata,selectElArr)

Loading the structured data to the select elements. Then the select elements can be cascaded.

Usage Example

const Cascade = cascade.Cascade;
const dealData = cascade.dealData;

const myDealedData = dealData(myRawData,["province","city","shop","phone"]);
const mySelectElems = ["province","city","shop","phone"];
const myCascade = new Cascade(myDealedData, mySelectElems);

param

  • @param myDealeddata: TYPE Array, the data returned by executing func dealData(as above), which structure is like Eg Data2:

      [
        {
          "name": "安徽",
          "state": [
            {
              "name": "蚌埠",
              "state": [{
                "name": "蚌埠分公司"
              }]
            },
            {
              "name": "阜阳",
              "state": [{
                "name": "阜阳分公司"
              }]
            },
            {
              "name": "合肥",
              "state": [{
                "name": "合肥分公司1"
              },
              {
                "name": "合肥分公司2"
              }
            }
          ]
        },
        {
          "name": "江苏",
          "state": [
            {
              "name": "苏州",
              "state": [{
                "name": "苏州分公司"
              }]
            }, 
            {
              "name": "常州",
              "state": [
              {
                "name": "常州分公司1"
              },
              {
                "name": "常州分公司2"
              },
              {
                "name": "常州分公司3"
              }]
            },
            ...
          ]
        },
      ]
  • @param selectElArr: Type Array, each item is the id string of a select element in your html file, eg:["province","city","shop"]. The html fragment is like:

      <form>
        ...
        <select name="province" id="province" style="top:290px;">
        </select>
        <select name="city" id="city" style="top:290px;left:192px;">
        </select>
        <select name="shop" id="shop" style="top:387px;width:178px;">
        </select>
        ...
      </form>