Socket
Book a DemoInstallSign in
Socket

liamloads-segment

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

liamloads-segment

Segment strings into chunks with JavaScript.

1.0.1
unpublished
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

About

Description

This is a fast algorithm for segmenting strings based on character count instead of UTF-16 code unit length.

It's written in JavaScript and outputs either an object array or string based on specified parameters.

A complete line-by-line algorithm code explanation is coming soon.

License

The Unlicense

Installation

Browser

git clone https://github.com/liamloads/javascript-segment.git
<script src="liamloads-segment.js" type="text/javascript"></script>

Node.js

npm install liamloads-segment
const liamloadsSegment = require('liamloads-segment');

Usage

Details

The first argument is the string to segment into chunks.

The second argument is the numeric size of each segment with a limit of 999999999.

The third optional argument is the string delimiter with a UTF-16 code unit length limit of 999999999.

The fourth optional argument is the numeric limit of segments with a limit of 999999999.

The fifth optional argument is a boolean that includes the remaining string without segmentation beyond the defined numeric limit.

The return value is a string if the third optional argument is a string delimiter, otherwise the return value is an object array.

If the UTF-16 code unit length of the first argument multiplied by the UTF-16 code unit length of the delimiter exceeds 999999999, the return value is false.

Examples

console.log(liamloadsSegment('◯0123456789', 2));
// ['◯0', '12', '34', '56', '78', '9']

console.log(liamloadsSegment('◯012345', 3, '_'));
// '◯01_234_5'

console.log(liamloadsSegment('◯0123456789', 2, '_', 3));
// '◯0_12_34'

console.log(liamloadsSegment('◯0123456789', 2, '_', 3, true));
// '◯0_12_34_56789'

console.log(liamloadsSegment('◯0123456789', '0001', false, 3));
// ['◯', '0', '1']

console.log(liamloadsSegment('◯0123456789', 1, false, 2, true));
// ['◯', '0', '123456789']

console.log(liamloadsSegment('◯0123456789', 11));
// ['◯0123456789']

console.log(liamloadsSegment('◯0123456789', 11, '_'));
// '◯0123456789'

console.log(liamloadsSegment('◯0123456789', 11, '_', 0));
// ''

console.log(liamloadsSegment('◯0123456789', 0));
// []

Keywords

algorithm

FAQs

Package last updated on 26 Aug 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.