🚨 Active Supply Chain Attack:node-ipc Package Compromised.Learn More
Socket
Book a DemoSign in
Socket

@devgrid/common

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@devgrid/common

Some useful primitives

Source
npmnpm
Version
0.4.0
Version published
Weekly downloads
46
15%
Maintainers
1
Weekly downloads
 
Created
Source

@devgrid/common

A comprehensive utility library providing a collection of commonly used JavaScript/TypeScript functions for everyday development tasks.

Installation

npm install @devgrid/common
# or
yarn add @devgrid/common

Features

  • Type-safe implementations
  • Zero dependencies
  • Comprehensive test coverage
  • Tree-shakeable exports

API Documentation

Primitives

Basic utility functions for common operations.

import { noop, identity, truly, falsely, arrify } from '@devgrid/common';

// noop - Does nothing
noop(); // => undefined

// identity - Returns the input value
identity(5); // => 5
identity({ foo: 'bar' }); // => { foo: 'bar' }

// truly - Always returns true
truly(); // => true

// falsely - Always returns false
falsely(); // => false

// arrify - Converts value to array
arrify(null); // => []
arrify(undefined); // => []
arrify(1); // => [1]
arrify([1, 2, 3]); // => [1, 2, 3]

Type Predicates

Functions for type checking and validation.

import { 
  isString, 
  isNumber, 
  isArray, 
  isObject,
  isPromise,
  // ... and many more
} from '@devgrid/common';

// Basic type checks
isString('hello'); // => true
isNumber(123); // => true
isArray([1, 2, 3]); // => true
isObject({}); // => true

// Advanced checks
isPromise(Promise.resolve()); // => true
isSubstring('hello', 'hello world'); // => true
isPrefix('hello', 'hello world'); // => true

Promise Utilities

Advanced promise handling utilities.

import { 
  timeout, 
  retry, 
  delay, 
  props 
} from '@devgrid/common';

// Add timeout to promises
await timeout(fetch('api.example.com'), 5000);

// Retry failed operations
await retry(async () => {
  // Your async operation here
}, {
  max: 3,
  backoffBase: 1000
});

// Delay execution
await delay(1000); // waits for 1 second

// Handle object of promises
await props({
  users: fetchUsers(),
  posts: fetchPosts()
});

Object Utilities

Functions for handling objects and their properties.

import { omit, entries } from '@devgrid/common';

// Omit properties from objects
const user = { name: 'John', age: 30, password: '123' };
omit(user, ['password']); // => { name: 'John', age: 30 }

// Get object entries with advanced options
entries(obj, { 
  enumOnly: true, 
  followProto: false 
});

Advanced Usage

Timeout with AbortController

const controller = new AbortController();

timeout(longOperation(), 5000, { 
  signal: controller.signal,
  unref: true 
});

// Later, if needed:
controller.abort();

Retry with Custom Configuration

await retry(async ({ current }) => {
  console.log(`Attempt ${current}`);
  // Your operation here
}, {
  max: 5,
  backoffBase: 1000,
  backoffExponent: 2,
  match: [NetworkError, TimeoutError],
  report: (message, options, error) => {
    console.log(`${message}: ${error?.message}`);
  }
});

TypeScript Support

This library is written in TypeScript and includes type definitions. All functions are fully typed and provide excellent IDE support.

// Example of TypeScript inference
const result = identity<number>(5); // result is typed as number
const arr = arrify<string>('hello'); // arr is typed as string[]

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License

Keywords

utils

FAQs

Package last updated on 17 Apr 2025

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