New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

standard-utils

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

standard-utils

A very small library for making development with typescript easier.

latest
Source
npmnpm
Version
1.0.4
Version published
Maintainers
1
Created
Source

standard-utils

A very small library for making development with typescript easier. Contains utility functions I wish was there in typescript.

Note: This library uses monkey patching to extend native prototypes.

Installation

Install using npm

npm install --save standard-utils

Usage

Import the whole library as follows:

import "standard-utils";

or you can import specific utility functions as follows:

import "standard-utils/dist/strain";

if you want to use only the strain utility and not anything else.

You can then use the imported utility functions within your application.

Utils

Strain

This is a utility that lets you filter an array for a single element and returns that element. If more than one elements remain in the filtered array, the first element is returned.

let arr = [
  {
    name: "blackberry",
    type: "fruit"
  },
  {
    name: "orange",
    type: "fruit"
  },
  {
    name: "eggplant",
    type: "vegetable"
  }
];

let obj = arr.strain(el => el.name === "blackberry");
console.log(obj); //{name: "blackberry",type: "fruit"}

Distinct

This is a function that returns the distinct elements within an array.

let arr = [1, 2, 3, 4, 5, 4, 3, 2, 1];

let obj = arr.distinct();
console.log(obj); //[1, 2, 3, 4, 5]

Intersection

This is a function that returns the intersection of two arrays

let characters = [
  {
    name: "Cersei",
    house: "Lannister"
  },
  {
    name: "Arya",
    house: "Stark"
  },
  {
    name: "Olenna",
    house: "Tyrell"
  }
];
let starks = [
  {
    name: "Brandon",
    house: "Stark"
  },
  {
    name: "Arya",
    house: "Stark"
  }
];
console.log(Array.prototype.intersection(characters, starks)); //[{ name: "Arya", house: "Stark" }]);

Difference

This is a function that returns the difference between two arrays.

const shoppingList = ["Apple", "Toothpaste", "Boots"];
const unavailableItems = ["Gasoline", "Ribbon", "Apple"];
const newShoppingList = shoppingList.difference(unavailableItems);
console.log(newShoppingList); //["Toothpaste", "Boots"]

Licence

Standard MIT Licence.

Keywords

Utils

FAQs

Package last updated on 25 Oct 2018

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