Skip to content

A versatile utility designed to handle conversions between various base encodings, including Base64, Base32, Base58, and more. Available as both a command-line tool and a web application, it allows users to seamlessly encode, decode, or transform data between different base formats with ease and efficiency.

License

Notifications You must be signed in to change notification settings

anonymByte-404/base-string-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

base-string-converter

AGPL-3.0 License CLI Tool Version Web Tool Version Express TypeScript Definitions TypeScript ESLint Plugin TypeScript ESLint Parser ESLint Version ESLint Config Prettier ESLint Plugin Prettier Prettier Version TS-Node Version TypeScript Version CRA Template Version React Version React DOM Version React Router DOM Version React Scripts Version Web Vitals Version

A versatile tool for converting data between various base encodings, including Base64, Base32, Base58, and more. Available as a command-line tool and a web application, it empowers users to quickly encode, decode, or convert data seamlessly.

Note

The main functionality of this tool is now stable and fully operational. However, it is still in active development, and additional features and updates may be added in the future. Please expect occasional changes as development continues.

Table of Contents


Features

  • πŸ”„ Seamless Conversion: Convert between numeral systems and base encodings (e.g., Base64 to Base32, Base58 to Base64).
  • πŸ”€ String Encoding: Effortlessly transform strings into base encodings (e.g., text to Base64).
  • 🧩 Decoding Made Easy: Decode base encodings back into readable text (e.g., Base64 to plain text).
  • ⚑ Intuitive Interface: Simple and user-friendly command-line prompts for quick and hassle-free usage.
  • πŸš€ High Performance: Lightweight, fast, and optimized for efficiency.
  • πŸ”’ Versatile Utility: Perfect for data transformations, encoding workflows, and cryptographic tasks.
  • πŸ’Ύ Persistent History: The conversion history is saved in a JSON file, allowing you to revisit past conversions at any time.

Installation

To install this package, follow these steps:

  1. Clone the repository:
    First, clone the repository to your local machine to create a copy of it:

    git clone https://github.com/anonymByte-404/base-string-converter.git
  2. Navigate to the project directory:
    After cloning, move into the project directory where all the files are located:

    cd base-string-converter
  3. Install dependencies using npm:
    Install the required dependencies for the project by running:

    npm install

    This will install all the necessary libraries and packages specified in the package.json file.

  4. Run the application:
    Once the dependencies are installed, start the application using the following command:

    npm start

    This will launch the application, and you should be able to use it as intended.

Usage

  1. Select the type of conversion:
    Choose the type of conversion you want to perform (e.g., String, Base).
    image1

  2. Choose the target base:
    Select the target numeral system for your conversion (e.g., Base64, Base32, etc.).
    image2

  3. Input the string to convert:
    Provide the string or data you wish to convert into the selected base or encoding.
    image3

  4. View the conversion output:
    Check the conversion result and decide whether to proceed with further actions, such as repeating the conversion or returning to the main menu.
    image4

Code Example

Below is an illustrative example of how you could use this tool programmatically in a Node.js application:

import inquirer from 'inquirer'
import chalk from 'chalk'

// Type for the answers in prompts
interface Answers {
  conversionType: string
  selectedBase?: string
}

// Base choices for conversion
const baseChoices: string[] = Array.from({ length: 64 }, (_, i) => `Base ${i + 1}`)

/**
 * Handles errors by logging the error message to the console.
 * 
 * @param {unknown} error - The error to handle.
 * @param {string} context - The context in which the error occurred.
 */
const handleError = (error: unknown, context: string): void => {
  const errorMessage = error instanceof Error ? error.message : String(error)
  console.error(chalk.red(`${context}: ${errorMessage}`))
}

/**
 * Logs and displays a success message when a conversion type is selected.
 * 
 * @param {string} conversionType - The conversion type selected by the user.
 */
const logConversionSelection = (conversionType: string): void => {
  console.log(chalk.green(`Selected Conversion: ${conversionType}`))
}

/**
 * Main prompt logic to allow the user to choose the type of conversion.
 * 
 * @returns {Promise<void>} - A promise that resolves when the conversion type is selected and handled.
 */
const mainPrompt = async (): Promise<void> => {
  try {
    const answers = await inquirer.prompt<Answers>([
      {
        type: 'list',
        name: 'conversionType',
        message: 'Select the type of conversion you want to perform:',
        choices: ['String Conversion', 'Base Conversion'],
      },
    ])

    logConversionSelection(answers.conversionType)

    if (answers.conversionType === 'String Conversion') {
      // Placeholder function for string conversion logic
      return stringConverter()
    }

    return await baseConversionPrompt()
  } catch (error: unknown) {
    handleError(error, 'An error occurred during the initial prompt')
  }
}

/**
 * Prompts the user to choose the target base for conversion.
 * 
 * @returns {Promise<void>} - A promise that resolves when the base conversion is selected.
 */
const baseConversionPrompt = async (): Promise<void> => {
  try {
    const { selectedBase } = await inquirer.prompt<Answers>([
      {
        type: 'list',
        name: 'selectedBase',
        message: 'Choose the target base for conversion:',
        choices: baseChoices,
      },
    ])

    console.log(chalk.yellow(`Selected Base: ${selectedBase}`))

    if (selectedBase === 'Base 2') {
      // Placeholder function for binary conversion logic
      return binaryConverter()
    }

    console.log(chalk.red(`Conversions for ${selectedBase} are currently not supported.`))
  } catch (error: unknown) {
    handleError(error, 'An error occurred during base selection')
  }
}

/**
 * Handles the logic for string conversion (this is a placeholder for your conversion logic).
 * 
 * @returns {Promise<void>} - A promise that resolves when the string conversion is done.
 */
const stringConverter = async (): Promise<void> => {
  console.log(chalk.brightBlue('String Conversion Selected'))
  // Placeholder: Your string conversion logic goes here
  console.log(chalk.brightCyan('Implement string conversion logic here'))
}

/**
 * Handles the logic for binary conversion (this is a placeholder for your conversion logic).
 * 
 * @returns {Promise<void>} - A promise that resolves when the binary conversion is done.
 */
const binaryConverter = async (): Promise<void> => {
  console.log(chalk.brightBlue('Binary Conversion Selected'))
  // Placeholder: Your binary conversion logic goes here
  console.log(chalk.brightCyan('Implement binary conversion logic here'))
}

/**
 * Starts the application by prompting the user for the type of conversion.
 */
mainPrompt()

Note

This is not the actual code, but an illustration designed to demonstrate how the CLI tool operates. It serves as an example to show the general behavior and flow of the tool, rather than the complete or exact implementation.

Contribution

Contributions are welcome! Here's how you can help:

  1. Fork the repository.
    Go to the repository page on GitHub and click the "Fork" button to create your own copy.

  2. Clone your Fork
    After forking the repository, clone it to your local machine:

    git clone https://github.com/anonymByte-404/base-string-converter.git
  3. Create a new branch for your feature or bug fix:
    Create a new branch so you can work on your changes without affecting the main branch:

    git checkout -b feature/your-feature-name
  4. Make your changes and commit:
    After making your changes, commit them with a meaningful message:

    git commit -m "Add your commit message here"
  5. Push to your fork:
    Push to your fork:

    git push origin feature/your-feature-name
  6. Open a pull request on the main repository.
    Go to the original repository on GitHub (https://github.com/anonymByte-404/base-string-converter) and open a pull request with your changes.

LICENSE

This project is licensed under the AGPL-3.0 License. See the LICENSE file for more details.

About

A versatile utility designed to handle conversions between various base encodings, including Base64, Base32, Base58, and more. Available as both a command-line tool and a web application, it allows users to seamlessly encode, decode, or transform data between different base formats with ease and efficiency.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published