Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→string-bionic-splitnext

string-bionic-split

Calculate a word string split position index for later highlighting

Downloads per monthMIT Licenselibera manifesto
  • the top
  • IDEA
  • FEATURES
  • API — SPLIT()
  • API — DEFAULTS
  • API — VERSION
  • HOW DIFFEREN…

Idea

A tiny (1.1KB) utility to calculate a position where to split a given the word (string) into two parts.

For example, it can be used to highlight one part of the string, to make it easier to read.

Features

  • Super lightweight
  • Extremely performant
  • Multilingual, supports all Latin and Cyrillic alphabets
  • No dependencies
  • Source in TS
  • Automatically-generated type definitions
  • Supports native ES Modules
  • Browser-Compatible
  • 100% code coverage unit tests

API — split()

The main function split() is imported like this:

It’s a function which takes two input arguments:

Input argumentTypeObligatoryDescription
str
Type: String
Obligatory: yes
strStringyesA word string.
opts
Type: Plain object
Obligatory: no
optsPlain objectnoOptional Options Object.

The Optional Options Object has the following shape:

KeyTypeDefaultDescription
throwIfEdgeWhitespace
Type: Boolean
Default: true
throwIfEdgeWhitespaceBooleantrueOptionally, you can disable throwing when there is a trailing whitespace detected.

The function will return a number, a string index. It is a suggestion where exactly to slice the str in two parts.

API — defaults

You can import defaults:

It's a plain object:

The main function calculates the options to be used by merging the options you passed with these defaults.

API — version

You can import version:

How different is it from the Bionic Reading®?

This program is not affiliated with Bionic Reading®opens in a new tab in any way.

For starters, an aforementioned commercial product is a set of different APIs and services which use closed-source, commercial and very advanced algorithms to format text in various ways.

On the other hand, the humble string-bionic-split processes one word at a time; it only suggests an index position, where to cut it into two pieces.

↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab