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

@mkholt/utilities

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mkholt/utilities

Fully typed small utility functions that I often need

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
0
Created
Source

TS Utilities

npm License TypeScript

Overview

The TS Utilities is a collection of small common utility functions to simplify common programming tasks. It is designed to be lightweight, efficient, and easy to use.

The functions are fully typescript typed, and implement type-assertion where relevant.

Installation

You can install the library using npm:

npm install @mkholt/utilities

or using yarn:

yarn add @mkholt/utilities

Usage

Here is an example of how to use the Utilities Library:

import { chunkArray } from "@mkholt/utilities";

// Example usage
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
 for (const chunk of chunkArray(arr, 3)) {
    console.log(chunk)
 }
 // [1, 2, 3]
 // [4, 5, 6]
 // [7, 8, 9]

 const arr2 = [1, 2, 3, 1, 2, 3, 4, 5]
 const unique = arr2.filter(isUnique)
 // unique = [1, 2, 3, 4, 5]

Features

  • assert: assert(condition, "error"): Given a boolean condition, checks the condition and throws and error if it is false.
  • chunkArray: chunkArray(arr, size): Given an array, returns an iterator which returns the array in chunks of the given size
  • isDefined: isDefined(obj): Returns true if the object is defined and non-null.
  • isUnique: isUnique(value, index, arr): Returns true if this is the first occurence of the value in the given array arr, false otherwise.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For any questions or feedback, please open an issue on GitHub.

FAQs

Package last updated on 03 Oct 2024

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