Divider is a powerful utility for dividing strings or string arrays using predetermined indexes or delimiters. It provides an easy-to-use interface for seamless integration with NPM, Deno, and Bun, making it versatile and accessible across various JavaScript environments. Perfect for developers seeking a straightforward solution to string manipulation.
Divider
The Divider is a versatile utility designed to split strings or arrays of strings using specified index positions or custom delimiters. This straightforward tool simplifies the process of dividing text data, making it ideal for various applications such as data parsing, formatting, and manipulation.
Key Features
- Flexible Division: Supports both index-based and string-based separation methods.
- Nested Input Handling: Effortlessly divides strings and arrays, accommodating complex data structures.
- Customizable Options: Provides features like flattening nested arrays, trimming whitespace, preserving empty strings, and excluding specific segments based on user-defined criteria.
- Targeted Extractors: Includes helper functions like
dividerFirst()anddividerLast()to easily access first or last elements from the divided results. - Loop Support: Utilizes
dividerLoop()for chunked division of strings into specified sizes. - Digit-Letter Splitter: The
dividerNumberString()function allows for separating numbers and letters within strings.
Basic Usage Example
import { divider } from '@nyaomaru/divider';
// Divide a string by index positions
const helloArray = divider('hello', 1, 3);
// Result: ['h', 'el', 'lo']
// Divide a string using a character separator
const divideWithString = divider('hello', 'e');
// Result: ['h', 'llo']
Advanced Usage Example
// Mixed usage of indexes and characters
const complexDivide = divider('hello world', 3, 'o');
// Result: ['hel', 'l', ' w', 'rld']
// Flattening nested results
const flatArray = divider(['hello', 'new world'], ' ', 2, { flatten: true });
// Result: ['he', 'llo', 'ne', 'w', 'wor', 'ld']
Presets
Divider also includes several presets for common tasks:
emailDivider: Splits emails into local-part and domain.csvDivider: Handles comma-separated values with consideration for quoted fields.pathDivider: Splits file paths by/or\.
Installation
To integrate the Divider into a project, it is available for installation via popular package managers:
- npm:
npm install @nyaomaru/divider - pnpm:
pnpm install @nyaomaru/divider - yarn:
yarn add @nyaomaru/divider
Documentation
For detailed documentation and API references, visit the official Divider Docs or the API Reference.
Additional Resources
- Contributing Guide: Guidelines for contributing to the project.
- Code of Conduct: Community standards and conduct expectations.
- Changelog: Information on version history and notable changes.
No comments yet.
Sign in to be the first to comment.