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

@csyakamoz/excel-schema

v0.1.3

Published

read excel in a lazy way

Downloads

16

Readme

Excel Schema

Read excel in a lazy way😑.

Installation

npm install @csyakamoz/excel-schema
# or
yarn add @csyakamoz/excel-schema

Usage

Single Data

If your sheet like the image:

single-data

Then, you can read it like the code below:

const {
  Schema: { array, date, boolean, custom, number, string },
  Executor,
} = require('@csyakamoz/excel-schema');

const data = Executor(
  // excel file
  file,
  // your schema
  {
    no: number().point('A2'),
    firstName: string().point('B2'),
    lastName: string().point('C2'),
    gender: string().point('D2'),
    country: string().point('E2'),
    age: number().point('F2'),
    date: date().point('G2'),
    id: string().point('H2'),
  },
  /**
   * sheet index or sheet name
   * this is optional, the default is 0
   */
  { sheet: 0 }
);

// JSON.stringify(data, null, 4)
{
    "no": 1,
    "firstName": "Dulce",
    "lastName": "Abril",
    "gender": "Female",
    "country": "United States",
    "age": 32,
    "date": "2017-08-01T00:00:00.000Z",
    "id": "1562"
}

Array Data

array-data

const data = Executor(
    file,
    array()
        .range('A2', 'H10')
        .interval(1, 8)
        .item({
            no: number().point('A2'),
            firstName: string().point('B2'),
            lastName: string().point('C2'),
            gender: string().point('D2'),
            country: string().point('E2'),
            age: number().point('F2'),
            date: date().point('G2'),
            id: string().point('H2'),
        }),
);

// JSON.stringify(data, null, 4)
[
    {
        "no": 1,
        "firstName": "Dulce",
        "lastName": "Abril",
        "gender": "Female",
        "country": "United States",
        "age": 32,
        "date": "2017-08-01T00:00:00.000Z",
        "id": "1562"
    },
    /* ... */
    {
        "no": 9,
        "firstName": "Vincenza",
        "lastName": "Weiland",
        "gender": "Female",
        "country": "United States",
        "age": 40,
        "date": "2017-08-09T00:00:00.000Z",
        "id": "6548"
    }
]

Array In Array Data

array-in-array

const data = Executor(
    file,
    array()
        .range('A2', 'E10')
        .interval(1, 5)
        .item({
            no: number().point('A2'),
            name: string().point('B2'),
            favoriteFruits: array()
                .range('C2', 'E2')
                .interval(1, 1) // this line is optional
                .item(string().point('C2')),
        }),
);

// JSON.stringify(data, null, 4)
[
    {
        "no": 1,
        "name": "Dulce",
        "favoriteFruits": [
            "apple",
            "durian",
            "pear"
        ]
    },
    /* ... */
    {
        "no": 9,
        "name": "Vincenza",
        "favoriteFruits": [
            "mulberry",
            "peach",
            "grape"
        ]
    }
]

Custom Data

It supports customizing parsers.

custom-data

const intervalSchema = custom(intervalStr => {
    const pattern = /([([]{1})(\d+),\s*(\d+)([)\]]{1})/;
    const [, leftBracket, begin, end, rightBracket] = intervalStr.match(
        pattern
    );
    const getBoundary = (value, bracket) => {
        const includedList = ['[', ']'];
        return {
            value: Number(value),
            includes: includedList.includes(bracket),
        };
    };

    return [
        getBoundary(begin, leftBracket),
        getBoundary(end, rightBracket),
    ];
});

const data = Executor(
    file,
    array()
        .range('A2', 'B5')
        .interval(1, 2)
        .item({
            interval: intervalSchema().point('A2'),
            discount: number().point('B2'),
        }),
);

// JSON.stringify(data, null, 4)
[
    {
        "interval": [
            {
                "value": 0,
                "includes": true
            },
            {
                "value": 100,
                "includes": false
            }
        ],
        "discount": 0
    },
    /* ... */
    {
        "interval": [
            {
                "value": 10000,
                "includes": true
            },
            {
                "value": 99999999999,
                "includes": false
            }
        ],
        "discount": 0.7
    }
]

License

MIT