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

@eeue56/ts-core

v3.0.1

Published

Core library for TypeScript inspired by Elm

Downloads

29

Readme

ts-core

Core library for TypeScript inspired by Elm. It contains only some of the more relevant data structures and functions.

Part of the Hiraeth collection.

Installation

npm install --save-dev @eeue56/ts-core

Testing

npm run build
npm run test

Usage

Basics

See src

Some useful tools for functional programming - piping, and composing. Both of these can be used to chain functions.

import { Basics } from '@eeue56/ts-core';

// take an argument then pipe it to a variable number of functions
// for example this is 10
const doubleLength = Basics.pipe(
    'hello',
    (str: string) => {
        return str.length;
    },
    (length: number) => {
        return length + length;
    }
);

// a function that turns composes each function given as an argument
const func = Basics.compose(
    (str: string) => {
        return str.length;
    },
    (length: number) => {
        return length + length;
    }
);

// this is 10
const anotherDoubleLength = func('hello');
console.log('Expecting 10', anotherDoubleLength);

Debug

See src

Not particularly useful in JS as impurity doesn't matter, but sometimes it's nice to log what you're returning.

import { Debug } from '@eeue56/ts-core';

// returns the same object as was logged
function getSomeObject(someObject){
    return Debug.log("My name is", someObject);
}

Maybe

See src

A Maybe/Optional type. Useful for when dealing with a value that can either be a value, or nothing.

import { Maybe } from '@eeue56/ts-core';

const someNothingMaybe = Maybe.Nothing();
const aValueOfZeroFromTheMaybe = Maybe.withDefault(0, someNothingMaybe);

const identity = (x) => x;
const someJustMaybe = Maybe.Just(10);
const newMaybe = Maybe.map(identity, someJustMaybe);
const aValueOfTenFromTheMaybe = Maybe.withDefault(0, someJustMaybe);

Result

See src

A Result type. Useful for when dealing with a value that can either be a value, or an error.

import { Result } from '@eeue56/ts-core';

const someResult = Result.Ok(10);
const double = (x) => x + x;
const newResult = Result.map(double, someResult);
const someResultValue = Result.withDefault(0, newResult);

const someError = Result.Err("Failed to parse on line 10");
const strLength = (x) => x.length;
const newError = Result.mapError(strLength, someError);

const someStringResult = Result.Ok("Hello");
const hello = Result.either(someStringResult);
const failedToParseOnLine10 = Result.either(someError);

Tuple

See src

A Tuple type of size 2. Useful for combining a pair of values. Generally named objects are more useful than Tuples, however.

import { Tuple } from '@eeue56/ts-core';

const someTuple = Tuple.pair(10, "okay");
const someNewTuple = Tuple.mapFirst(double, someTuple);
const someOtherTuple = Tuple.mapSecond(strLength, someTuple);
const someFirstValue = Tuple.first(someOtherTuple);
const someSecondValue = Tuple.second(someOtherTuple);