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

@ticatec/enhanced-utils

v0.9.0

Published

This is a utility library to enhance the Object and Array, it also provide some basic functions such as: isString, isArray, isEmpty etc.

Downloads

5

Readme

Enhanced Utils

中文版说明

Installation

You can install the library via npm:

npm install @ticatec/enhanced-utils

or

yarn add @ticatec/enhanced-utils

StringUtils

This is a simple JavaScript library that provides utility functions to work with strings.

Usage

import {stringUtils} from '@ticatec/enchance-utils';

isString(s: any)
This function takes any value as input and returns true if the input is a string and false otherwise.

Example:

stringUtils.isString('hello world'); // returns true
stringUtils.isString(123); // returns false

isEmpty(s: string, strict: boolean = true)
This function takes a string and an optional boolean parameter as input. It returns true if the string is empty or contains only whitespace characters. If the strict parameter is set to true (the default), then leading and trailing whitespace characters are also considered when determining if the string is empty.

stringUtils.isEmpty('  '); // returns true
stringUtils.isEmpty('  ', false); // returns false
stringUtils.isEmpty('  hello  '); // returns true
stringUtils.isEmpty('  hello  ', false); // returns false

escapeHtml(text: string): string
Escapes HTML special characters in the given string.

const escapedHtml = utils.escapeHtml("<p>Hello, world!</p>");
console.log(escapedHtml); // logs "&lt;p&gt;Hello, world!&lt;/p&gt;"

Utils

This is a library of utility functions that can be used to enhance the functionality of your TypeScript code.

Usage

Import the utility functions you need from the package, like this:

import { utils } from '@ticatec/enhanced-utils';
if (utils.isArray(myArray)) {
    // do something with the array
}

if (utils.isFunction(myFunction)) {
    // call the function
}

if (utils.isAsyncFunction(myAsyncFunction)) {
    // call the async function
}

await utils.sleep(5); // pause the program for 5 seconds

const sourceObj = {
    name: 'John Doe',
    age: 28,
    address: null,
    emptyString: '',
    emptyArray: [],
    interests: ['sports', 'music']
};

// Clone an object
const clonedObj = clone(sourceObj);

// Clean up an object and remove null values, empty strings, and empty arrays
const purgedObj = objectPurge(sourceObj);

// Merge two objects by copying specific properties from the source object to the destination object
const destObj = { name: 'Jane Doe', age: 25 };
const props = ['name', 'interests'];
objectMerge(destObj, sourceObj, props);

API

isArray(data: any): boolean
Checks whether the given value is an array.

isFunction(fun: any): boolean
Checks whether the given value is a function.

isObject(value: any): boolean Checks where the given value is an object.

isAsyncFunction(fun: any): boolean
Checks whether the given value is an async function.

sleep(n: number): Promise
Pauses the program for the specified number of seconds (n).

clone(obj: any): any Creates a deep copy of an object.

objectPurge(obj: any, strict?: boolean): any Removes null values, empty strings, and empty arrays from an object.

objectMerge(dest: any, src: any, props?: string[]): void Copies specific properties from the source object to the destination object. If props is not provided, all properties of the source object will be copied.

Array Extension

This is a TypeScript code extension for JavaScript Arrays that provides additional functionality.

Features

This extension provides the following features to JavaScript Arrays:

remove(elem: T): boolean
Removes the matching element from the array, and returns true if an element was successfully removed, or false if the element was not found.

replace(elem: T, match: ObjectEqual): boolean
Replaces the matching element in the array with the new element. Returns true if the element was found and replaced, or false if the element was not found.

union(list: Array, match: ObjectEqual): void
Merges the target array with another array, while removing duplicates based on a matching function.

Usage

This extension can be used by copying and pasting the code, or by importing the module. Once installed, the new functions can be accessed from any array instance.

import '@ticatec/enchance-utils';

let arr = [1,2,3];
arr.remove(1); // returns true and the array now is [2,3]

arr.replace(2, (e1, e2) => e1 === e2); // returns true and the array now is [1, 2, 3]

let arr2 = [4,5,6];
arr.union(arr2, (e1, e2) => e1 === e2); // returns void and the array now is [1, 2, 3, 4, 5, 6]

License
The Enhanced-Utils is MIT licensed.