
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
liamloads-segment
Advanced tools
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.
git clone https://github.com/liamloads/javascript-segment.git
<script src="liamloads-segment.js" type="text/javascript"></script>
npm install liamloads-segment
const liamloadsSegment = require('liamloads-segment');
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
.
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));
// []
FAQs
Segment strings into chunks with JavaScript.
The npm package liamloads-segment receives a total of 0 weekly downloads. As such, liamloads-segment popularity was classified as not popular.
We found that liamloads-segment demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.