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

core-helper-packages

v1.3.0

Published

core-helper-packages is a utility library designed to simplify common programming tasks in JavaScript. It includes a comprehensive set of functions for working with arrays and strings, making your development process faster and more efficient

Downloads

44

Readme

Certainly! Here is a README.md formatted with Markdown language, tailored for your core-helper-packages npm package:

# Core Helper Packages

A collection of utility functions for common array and string operations in JavaScript.

## Installation

To use this package, install it via npm:

```bash
npm install core-helper-packages

Usage

You can import the package into your project using CommonJS or ES Modules syntax:

CommonJS

const coreHelper = require('core-helper-packages');

ES Modules

import * as coreHelper from 'core-helper-packages';

API

String Utilities

isString(value)

Checks if the given value is a string.

  • Parameters: value (any) - The value to check.
  • Returns: boolean - true if the value is a string, otherwise false.

Array Utilities

isArray(value)

Checks if the given value is an array.

  • Parameters: value (any) - The value to check.
  • Returns: boolean - true if the value is an array, otherwise false.

isNull(value)

Checks if the given value is null.

  • Parameters: value (any) - The value to check.
  • Returns: boolean - true if the value is null, otherwise false.

isUndefined(value)

Checks if the given value is undefined.

  • Parameters: value (any) - The value to check.
  • Returns: boolean - true if the value is undefined, otherwise false.

isNullOrUndefined(value)

Checks if the given value is either null or undefined.

  • Parameters: value (any) - The value to check.
  • Returns: boolean - true if the value is null or undefined, otherwise false.

isArrayEmpty(arr)

Checks if an array is empty.

  • Parameters: arr (Array) - The array to check.
  • Returns: boolean - true if the array is empty, otherwise false.
  • Throws: TypeError - If the input is not an array.

getArrayLength(arr)

Gets the length of an array.

  • Parameters: arr (Array) - The array to get the length of.
  • Returns: number - The length of the array.
  • Throws: TypeError - If the input is not an array.

firstElement(arr)

Retrieves the first element of an array.

  • Parameters: arr (Array) - The array to get the first element from.
  • Returns: The first element of the array.
  • Throws: TypeError - If the input is not an array.

lastElement(arr)

Retrieves the last element of an array.

  • Parameters: arr (Array) - The array to get the last element from.
  • Returns: The last element of the array, or undefined if the array is empty.
  • Throws: TypeError - If the input is not an array.

pushElement(arr, element)

Adds an element to the end of an array.

  • Parameters:
    • arr (Array) - The array to modify.
    • element (any) - The element to add.
  • Returns: The array with the new element added.
  • Throws: TypeError - If the first argument is not an array.

popElement(arr)

Removes the last element from an array.

  • Parameters: arr (Array) - The array to modify.
  • Returns: The array with the last element removed.
  • Throws: TypeError - If the input is not an array.

sumArray(arr)

Calculates the sum of all numeric values in an array.

  • Parameters: arr (Array) - The array containing numeric values.
  • Returns: number - The sum of the numeric values in the array.
  • Throws: TypeError - If the input is not an array or contains non-numeric values.

averageArray(arr)

Calculates the average of all numeric values in an array.

  • Parameters: arr (Array) - The array containing numeric values.
  • Returns: number - The average of the numeric values in the array.
  • Throws: TypeError - If the input is not an array or contains non-numeric values.

maxArray(arr)

Finds the maximum value in an array.

  • Parameters: arr (Array) - The array to search.
  • Returns: number - The maximum value in the array.
  • Throws: TypeError - If the input is not a non-empty array.

minArray(arr)

Finds the minimum value in an array.

  • Parameters: arr (Array) - The array to search.
  • Returns: number - The minimum value in the array.
  • Throws: TypeError - If the input is not a non-empty array.

mapArray(arr, callback)

Applies a function to each element of the array and returns a new array.

  • Parameters:
    • arr (Array) - The array to map over.
    • callback (Function) - The function to apply to each element.
  • Returns: A new array with each element transformed by the callback function.
  • Throws: TypeError - If the first argument is not an array or the second argument is not a function.

filterArray(arr, predicate)

Filters elements of the array based on a predicate function and returns a new array.

  • Parameters:
    • arr (Array) - The array to filter.
    • predicate (Function) - The function to test each element.
  • Returns: A new array with elements that pass the predicate function.
  • Throws: TypeError - If the first argument is not an array or the second argument is not a function.

flatArray(arr)

Flattens a nested array into a single-level array.

  • Parameters: arr (Array) - The nested array to flatten.
  • Returns: The flattened array.
  • Throws: TypeError - If the input is not an array.

uniqueArray(arr)

Removes duplicate values from an array.

  • Parameters: arr (Array) - The array from which to remove duplicates.
  • Returns: The array with duplicate values removed.
  • Throws: TypeError - If the input is not an array.

Examples

Here are some example usages for each function:

const coreHelper = require('core-helper-packages');

// String Utilities
console.log(coreHelper.isString("hello")); // true

// Array Utilities
const arr = [1, 2, 3, 4];
console.log(coreHelper.isArray(arr)); // true
console.log(coreHelper.isArrayEmpty([])); // true
console.log(coreHelper.getArrayLength(arr)); // 4
console.log(coreHelper.firstElement(arr)); // 1
console.log(coreHelper.lastElement(arr)); // 4
console.log(coreHelper.pushElement(arr, 5)); // [1, 2, 3, 4, 5]
console.log(coreHelper.popElement(arr)); // [1, 2, 3, 4]
console.log(coreHelper.sumArray(arr)); // 10
console.log(coreHelper.averageArray(arr)); // 2.5
console.log(coreHelper.maxArray(arr)); // 4
console.log(coreHelper.minArray(arr)); // 1
console.log(coreHelper.mapArray(arr, x => x * 2)); // [2, 4, 6, 8]
console.log(coreHelper.filterArray(arr, x => x > 2)); // [3, 4]
console.log(coreHelper.flatArray([[1], [2, 3], [4]])); // [1, 2, 3, 4]
console.log(coreHelper.uniqueArray([1, 2, 2, 3, 4, 4])); // [1, 2, 3, 4]