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

sr-data-manipulator

v0.2.2

Published

Implementation of Enum and Pipeline for JS

Downloads

13

Readme

SR_Data_Manipulator

This package has possible to be diveded into some packages, and to be cold to develop when this is version 1.0.0

バージョン1.0.0になる際に、複数のパッケージに分割したのち、このパッケージの開発自体は凍結する可能性があります。

Build Status

const {Result, match} = require("sr-data-manipulator");

const response = new Result.Ok("You can use \"Enum\" on JavaScript !");

match(response).with({
    [Result.$Ok] : message => console.log(message),
    [Result.$Err] : () => console.log()
});

// You can use "Enum" on JavaScript !
const {Enum} = require("sr-data-manipulator");

const OriginalEnum = new Enum("you", "can", "make", "original", "enum", "class");

const foo = new OriginalEnum.you("Each enumeratior can have a value");

// .name() method returns own tag name
console.log(foo.name == "you");   //true

// .tag() method returns Symbol of own tag
console.log(foo.tag == Symbol("you")) //false

// "$" + [tag name] means Sybom of each tags
console.log(foo.tag == OriginalEnum.$you) //true

How to install

> npm install sr-data-manipulator

Caution

This module is beta-version. It means that the module probably will be in radical changing.

require / import

You can require all modules as follows.

// Enum
const {Enum, match, Option, Result, resultOf, $Some, $None, $Ok, $Err} = require("sr-data-manipulator");

// Pipeline
const {Pipeline, Pipe, Adaptor:{$, R}} = require("sr-data-manipulator");

You can import all modules as follows.

// Enum
import {Enum, match, Option, Result, resultOf, $Some, $None, $Ok, $Err} from "sr-data-manipulator";

// Pipeline
import {Pipeline, Pipe, Adaptor:{$, R}} from "sr-data-manipulator";

What's this

This packege give you Enum and pipeline-process.

Enum

Enum(...tags) make enumeration. Tags should be String witch does not begin with "$" .

Enumeration maek enumerator by new [enumeration].[enumerator]([value]) , and enumerator can have a value.

expect

const FooBar = new Enum("Foo", "Bar", "Baz", "Qux");

let mayBeFoo = new FooBar.Foo("fooooo!");

mayBeFoo.expect(FooBar.$Foo)
    .then(val => console.log(val))  // "fooooo!" will be shown
    .catch(val => console.log(val)) // nothing will be shown

mayBeFoo = new FooBar.Bar("FOOOOO!!");

mayBeFoo.expect(FooBar.$Foo)
    .then(val => console.log(val))  // nothing will be shown
    .catch(val => console.log(val)) // "FOOOOO!!" will be shown

mayBeFoo = new FooBar.Baz(10);

const foo = mayBeFoo.expect(FooBar.$Foo)
    .then(val => 10 + 1)
    .catch(val => 10 - 1);

console.log(foo);   // "9" will be shown

match

const FooBar = new Enum("Foo", "Bar", "Baz", "Qux");

let mayBeFoo = mayBeFoo = new FooBar.Foo("hello");

const foo = match(mayBeFoo).with({
    [Foobar.$Foo]   : val =? val + " SR_D_M !", // when foo.tag() equals to Foobar.$Foo
    [Foobar.$Bar]   : val => val,               // when foo.tag() equals to Foobar.$Bar
    _               : _ => "others"             // "_" means default
});

let mayBeFoo = mayBeFoo = new FooBar.Foo("Hello");

const foo = match(mayBeFoo).with({
    [Foobar.$Foo]   : val =? val + " SR_D_M !", // when foo.tag() equals to Foobar.$Foo
    [Foobar.$Bar]   : val => val,               // when foo.tag() equals to Foobar.$Bar
    _               : _ => "Others"             // "_" means default
});

console.log(foo); // "Hello SR_D_M !" will be shown

let mayBeFoo = mayBeFoo = new FooBar.Baz("Hello");

const baz = match(mayBeFoo).with({
    [Foobar.$Foo]   : val =? val + " SR_D_M !", // when foo.tag() equals to Foobar.$Foo
    [Foobar.$Bar]   : val => val,               // when foo.tag() equals to Foobar.$Bar
    _               : _ => "Others"             // "_" means default
});

console.log(baz); // "Others" will be shown

default enums

Option = new Enum("Some", "None");
Result = new Enum("Ok", "Err");

$Some = value => new Option.Some(value);
$None = value => new Option.Some(value);
$Ok = value => new Option.Some(value);
$Err = value => new Option.Some(value);

Pipeline

Pipeline(...Adaptors) make pipeline with adaptors. Adaptor is a function (process: function(any -> any), data: any) -> result: any. Each adaptor means how to adapt previous result to process.

Pipe is default pipeline, witch has $ to pass through previous result and R to undeal Result.Err.

Pipe

const someData = "Pipeline of SR_D_M";
try{
    const result = await (new Pipeline(someData))
        .$(value => value + " !")           //Pipeline of SR_D_M !
        .$(value => $Ok(value))             //Result.Ok("Pipeline of SR_D_M !")
        .R(value => value.length)           //20
        .$(_ => $Err("some thing errored")) //Result.Err("some thing errored")
        .R(value => value + "!")            //will not be dealed
        .R(value => value + "!")            //will not be dealed
        .$("Pipeline_of_SR_D_M !")          //Pipeline_of_SR_D_M !    --you can overwrite previous result
        .$(async value =>{                  //you can use "async" and "await" in pipeline
            await promiseFunction(value);
            await promiseFunction(value);
            await promiseFunction(value);
        })
        .$(some_process).$(some_process).$(some_process)
        .$(some_process).$(some_process).$(some_process)
} catch(err) {
    you_can_get_promise_exception_in_pipeline(err);
}