Socket
Socket
Sign inDemoInstall

@ethersproject/strings

Package Overview
Dependencies
3
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ethersproject/strings

String utility functions.


Version published
Weekly downloads
837K
increased by8.82%
Maintainers
1
Install size
517 kB
Created
Weekly downloads
 

Package description

What is @ethersproject/strings?

@ethersproject/strings is a utility library for handling and manipulating strings in the context of Ethereum and blockchain development. It provides functions for UTF-8 encoding/decoding, hex string manipulation, and other string-related operations that are commonly needed when working with Ethereum smart contracts and transactions.

What are @ethersproject/strings's main functionalities?

UTF-8 Encoding and Decoding

This feature allows you to convert a string to its UTF-8 byte representation and vice versa. This is useful for encoding data to be sent over the network or stored in smart contracts.

const { toUtf8Bytes, toUtf8String } = require('@ethersproject/strings');

const utf8Bytes = toUtf8Bytes('Hello, Ethereum!');
console.log(utf8Bytes); // Uint8Array of UTF-8 bytes

const utf8String = toUtf8String(utf8Bytes);
console.log(utf8String); // 'Hello, Ethereum!'

Hex String Manipulation

This feature provides utilities for working with hexadecimal strings, such as converting byte arrays to hex strings and validating hex strings. This is particularly useful for handling Ethereum addresses and transaction data.

const { hexlify, isHexString } = require('@ethersproject/strings');

const hexString = hexlify([0x12, 0x34, 0x56]);
console.log(hexString); // '0x123456'

const isValidHex = isHexString(hexString);
console.log(isValidHex); // true

Base64 Encoding and Decoding

This feature allows you to encode and decode strings to and from Base64 format. This can be useful for encoding binary data as a string for storage or transmission.

const { toBase64, fromBase64 } = require('@ethersproject/strings');

const base64String = toBase64('Hello, Ethereum!');
console.log(base64String); // 'SGVsbG8sIEV0aGVyZXVtIQ=='

const originalString = fromBase64(base64String);
console.log(originalString); // 'Hello, Ethereum!'

Other packages similar to @ethersproject/strings

Readme

Source

String Manipulation Utilities

This sub-module is part of the ethers project.

It contains functions to safely convert between UTF-8 data, strings and Bytes32 strings (i.e. "short strings").

For more information, see the documentation.

Importing

Most users will prefer to use the umbrella package, but for those with more specific needs, individual components can be imported.

const {

    toUtf8Bytes,
    toUtf8CodePoints,
    toUtf8String,

    formatBytes32String,
    parseBytes32String,

    nameprep

    // Enums

    Utf8ErrorFuncs,
    Utf8ErrorReason,

    UnicodeNormalizationForm

    // Types

    Utf8ErrorFunc,

} = require("@ethersproject/strings");

License

MIT License

Keywords

FAQs

Last updated on 24 May 2022

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