Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

helper-methods-js

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

helper-methods-js

A package that provides helper methods for common and not-so-common use cases

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

Helper methods

A package that provides helper methods for common and not-so-common use cases

Contributions are welcome!

Installation

npm install helper-methods-js

Methods

  • deepcopy
  • dedupe
  • indexesOf
  • isAsyncFunction
  • trimDelimeters



deepcopy

This method creates a deep copy of the provided object to the given depth. Beyond that depth, the object is shallow copied

ParameterDescriptionDefault Value
objThe object to be copiedN/A
max_depth (optional)Maximum depth to which the function would copy the object. Beyond this depth shallow copies would be created. A value of 0 implies that the entire object should be deep copied.0

Sample usage
import { deepcopy } from 'helper-methods-js'

deepcopy({ name: 'bob' }, 0);


dedupe

This method provides implementation to remove duplicates from an array.

ParameterDescriptionDefault Value
arrayThe array that needs duplicates removedN/A
condition (optional)A function that returns either true or false. This condition is executed for each array value and the values for which it returns true are removed. In case this condition is not provided, elements are removed on equality comparison.N/A

Sample usage
import { dedupe } from 'helper-methods-js'

const cars = [
  { name: "audi", owner: "a" },
  { name: "bmw", owner: "x" },
  { name: "audi", owner: "b" },
  { name: "bmw", owner: "b" },
];

dedupe(cars, (e, i) => e.owner === i.owner)


indexesOf

This method provides implementation to return indexes of all elements that match a specific condition

ParameterDescriptionDefault Value
arrayThe array that needs duplicates removedN/A
conditionIt can either be a value or a functions. In case of a function, the function should return true or false. This condition is executed for each array value and the values for which it returns true are added to the list of indexes returned. In case this condition is not provided, elements are removed on equality comparison.N/A

Sample usage
import { indexesOf } from 'helper-methods-js'

const objs = [
  { age: 21, nationality: "a" },
  { age: 24, nationality: "a" },
  { age: 21, nationality: "b" },
  { age: 32, nationality: "c" },
  { age: 42, nationality: "b" },
  { age: 52, nationality: "c" },
  { age: 21, nationality: "a" },
]

const indexes = indexesOf(objs, (i: any) => i.nationality === "b")


isAsyncFunction

This method returns whether a function is async or not.

ParameterDescriptionDefault Value
fnThe function for which it needs to be determined whether it is async or not.N/A

Sample usage
import { isAsyncFunction } from 'helper-methods-js'

const testFn = async () => {};
isAsyncFunction(testFn) // returns true

const testFnSync = () => {};
isAsyncFunction(testFnSync) // returns false


trimDelimeters

This method takes a string and removes the provided delimeters from the start and end of the string.

ParameterDescriptionDefault Value
strThe string to be trimedN/A
delimetersA list of delimeters to be trimned from the start and/or end of the string provided.N/A
options (optional)An object with values trimStart and trimEnd that represent if the string should only be trimmed from start and/or end respectively.{ trimStart: true, trimEnd: true }

Sample usage
import { trimDelimeters } from 'helper-methods-js'

trimDelimeters("&&*ABC*(&", ["&", "*"]) // outputs "ABC*("

Keywords

FAQs

Package last updated on 29 Apr 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc