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

@shvmerc/development

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shvmerc/development

This package provides some tools to improve `javascript` and `typescript` development.

latest
Source
npmnpm
Version
0.1.0-alpha
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Development Tools

This package provides a set of tools to improve the development in javascript and typescript.

Dictionary

This feature provides a set of tools for working with objects in a way similar to working with arrays.

In typescript, this feature uses generic types to remember the type of object values, but not to remember the keys, assuming the keys are just of type string, so the objects will be handled internally as Record<string, T>.

There are two different ways to use this feature. The first is through the dictionary() function, and the other is by using an instance of the Dictionary class.

dictionary()

Provides a set of functions that perform various operations and transformations on the object without directly modifying it, eliminating the need to create a copy of the object or destructure it when passing it as an argument.

Functions that performs modifications will return a new object instead.

const { dictionary } = require('@shvmerc/development')

const object = { a: 1, b: 2, c: 3 }

const result1 = dictionary(object).map((value) => (value * 100))
console.log(result1) // { a: 100, b: 200, c: 300 }

const result2 = dictionary(result1).rename((value, key) => (key.toUpperCase()))
console.log(result2) // { A: 100, B: 200, C: 300 }

console.log(object) // { a: 1, b: 2, c: 3 }
console.log(object === result1) // false
console.log(object === result2) // false

new Dictionary()

Creates an instance of the Dictionary class linked to the provided object. The methods of this class allow various operations and transformations on the original object.

Methods that perform modifications will return this instead of returning the object directly, requiring the use of the .value() method to get the actual object.

const { Dictionary } = require('@shvmerc/development')

const object = { a: 1, b: 2, c: 3 }

const dictionary = new Dictionary(object)

dictionary.map((value) => (value * 100))
console.log(dictionary.value()) // { a: 100, b: 200, c: 300 }

dictionary.rename((value, key) => (key.toUpperCase()))
console.log(dictionary.value()) // { A: 100, B: 200, C: 300 }

console.log(object) // { A: 100, B: 200, C: 300 }
console.log(object === dictionary.value()) // true

Methods

method / functiondescription
.keys()Returns an array of keys from the object.
.values()Returns an array of values from the object.
.entries()Returns an array of key-value pairs from the object.
.size()Returns the number of properties in the object.
.at()Returns the value associated with the specified key.
.set()Modifies the value of the provided property.
.has()Checks if all specified keys are present in the object.
.hasOneOf()Checks if at least one of the specified keys is present in the object.
.includes()Checks if all specified values are present in the object.
.includesOneOf()Checks if at least one of the specified values is present in the object.
.random()Returns a random value from the object.
.times()Creates a map by counting the number of times that the values provided appear in the object.
.clear()Removes all the properties.
.copy()Creates a copy of the object.
.merge()Merges the object with all the provided objects, rewriting repeated properties.
.pick()Removes all, except the provided properties.
.delete()Removes the provided properties.
.forEach()Executes the provided callback function once for each property in the object.
.some()Checks if at least one property in the object satisfies the provided condition.
.every()Checks if all properties in the object satisfies the provided condition.
.find()Finds the first property in the object that satisfies the provided condition.
.filter()Removes the properties that not satisfies the provided condition.
.rename()Rename the properties based on the provided callback function.
.map()Transform the property values based on the provided callback function.
.remake()Rename and transform the properties based on the provided callback function.
.array()Creates an array of values based on a provided callback function.
.count()Counts the number of properties in the object that satisfies a provided condition.
.reduce()Reduces the object to a single value based on a provided callback function.

Keywords

object

FAQs

Package last updated on 25 Mar 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