Socket
Socket
Sign inDemoInstall

@cosmjs/utils

Package Overview
Dependencies
0
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cosmjs/utils


Version published
Weekly downloads
173K
decreased by-0.97%
Maintainers
1
Created
Weekly downloads
 

Package description

What is @cosmjs/utils?

@cosmjs/utils is a utility library for JavaScript and TypeScript that provides a collection of helper functions for common tasks. It is part of the CosmJS suite, which is designed to interact with the Cosmos SDK and other blockchain technologies. The utilities in this package help with data manipulation, encoding/decoding, and other common operations.

What are @cosmjs/utils's main functionalities?

Data Manipulation

The `arrayContentEquals` function checks if two arrays have the same content. This is useful for comparing arrays without worrying about the order of elements.

const { arrayContentEquals } = require('@cosmjs/utils');

const array1 = [1, 2, 3];
const array2 = [1, 2, 3];
const array3 = [4, 5, 6];

console.log(arrayContentEquals(array1, array2)); // true
console.log(arrayContentEquals(array1, array3)); // false

Encoding/Decoding

The `toHex` and `fromHex` functions are used to convert data to and from hexadecimal strings. This is particularly useful for encoding binary data in a human-readable format.

const { toHex, fromHex } = require('@cosmjs/utils');

const data = new Uint8Array([1, 2, 3, 4]);
const hexString = toHex(data);
console.log(hexString); // '01020304'

const decodedData = fromHex(hexString);
console.log(decodedData); // Uint8Array [ 1, 2, 3, 4 ]

String Manipulation

The `assert` and `assertDefined` functions are used for validation. `assert` checks if a condition is true, while `assertDefined` ensures that a value is not undefined. These functions help in writing robust code by enforcing certain conditions.

const { assert, assertDefined } = require('@cosmjs/utils');

const value = 'Hello, World!';
assert(value.length > 0, 'Value should not be empty');

const definedValue = 'CosmJS';
assertDefined(definedValue, 'Value should be defined');

Other packages similar to @cosmjs/utils

Readme

Source

@cosmjs/utils

npm version

Utility functions independent of blockchain applications. Primarily used for testing but stuff like sleep can also be useful at runtime.

License

This package is part of the cosmjs repository, licensed under the Apache License 2.0 (see NOTICE and LICENSE).

FAQs

Last updated on 29 Oct 2020

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc