Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eeue56/ts-core

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eeue56/ts-core

Core library for TypeScript inspired by Elm

  • 3.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by25%
Maintainers
1
Weekly downloads
 
Created
Source

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);

Keywords

FAQs

Package last updated on 22 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc