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

string-harmony

v0.0.3

Published

A utility class for performing various file operations such as reading, writing, appending, and inserting lines both synchronously and asynchronously.

Downloads

16

Readme

string-harmony

A utility class for performing various file operations such as reading, writing, appending, and inserting lines both synchronously and asynchronously. Ideal for manipulating text files efficiently in Node.js projects.

Installation

To install the package, use the following npm command:

pnpm install string-harmony

Usage

Here are some example code snippets demonstrating how to use the string-harmony package:

import StringHarmony from 'string-harmony'

// Initialize with file path
const stringHarmony = new StringHarmony('path/to/your/file.txt')

  // Asynchronous usage
  (async () => {
    // Read file
    const lines = await stringHarmony.readFileAsync()
    console.log(lines)

    // Write file
    await stringHarmony.writeFileAsync(['line1', 'line2'])

    // Append line
    await stringHarmony.appendLineAsync('new line')

    // Prepend line
    await stringHarmony.prependLineAsync('first line')

    // Insert line at specific index
    await stringHarmony.insertLineAtAsync('inserted line', 1)

    // Append line at specific index
    await stringHarmony.appendLineAtAsync('appended line', 1)

    // Prepend line at specific index
    await stringHarmony.prependLineAtAsync('prepended line', 1)
  })()

// Synchronous usage
try {
  // Read file
  const lines = stringHarmony.readFileSync()
  console.log(lines)

  // Write file
  stringHarmony.writeFileSync(['line1', 'line2'])

  // Append line
  stringHarmony.appendLineSync('new line')

  // Prepend line
  stringHarmony.prependLineSync('first line')

  // Insert line at specific index
  stringHarmony.insertLineAtSync('inserted line', 1)

  // Append line at specific index
  stringHarmony.appendLineAtSync('appended line', 1)

  // Prepend line at specific index
  stringHarmony.prependLineAtSync('prepended line', 1)
} catch (error) {
  console.error(error)
}

Configuration Options or Parameters

There are no specific configuration options required to use this package. Simply provide the file path during the initialization of the StringHarmony instance.

API Details

Main Functions and Methods

Asynchronous Methods

  • readFileAsync(): Reads the file asynchronously and returns an array of lines.
  • writeFileAsync(lines: string[]): Writes an array of lines to the file asynchronously.
  • appendLineAsync(line: string): Appends a line to the file asynchronously.
  • prependLineAsync(line: string): Prepends a line to the file asynchronously.
  • insertLineAtAsync(line: string, index: number): Inserts a line at a specified index asynchronously.
  • appendLineAtAsync(line: string, index: number): Appends a line after a specified index asynchronously.
  • prependLineAtAsync(line: string, index: number): Prepends a line before a specified index asynchronously.

Synchronous Methods

  • readFileSync(): Reads the file synchronously and returns an array of lines.
  • writeFileSync(lines: string[]): Writes an array of lines to the file synchronously.
  • appendLineSync(line: string): Appends a line to the file synchronously.
  • prependLineSync(line: string): Prepends a line to the file synchronously.
  • insertLineAtSync(line: string, index: number): Inserts a line at a specified index synchronously.
  • appendLineAtSync(line: string, index: number): Appends a line after a specified index synchronously.
  • prependLineAtSync(line: string, index: number): Prepend a line before a specified index synchronously.

Parameters

  • line: string: The line to be added to the file.
  • index: number: The position at which the line should be inserted.

Returns

  • readFileAsync() and readFileSync(): Return an array of strings, where each string represents a line from the file.
  • Other methods return void.

Contributing

Guidelines for Contributing

  • Fork the repository.
  • Create a new branch for your feature or bug fix.
  • Ensure that your code follows the existing coding standards.
  • Write tests for your code.
  • Submit a pull request.

Coding Standards

  • Follow the eslint rules specified in the project.
  • Ensure that all new features and bug fixes are covered by tests.

Tests

  • Ensure that all tests pass before submitting a pull request.
  • Write tests using Vitest.

License

This package is distributed under the MIT License.

Contact

For support or issues, you can reach out via the issue tracker on GitHub.