All Projects โ†’ sallar โ†’ Stringz

sallar / Stringz

Licence: mit
๐Ÿ’ฏ Super fast unicode-aware string manipulation Javascript library

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Stringz

Portable Utf8
๐Ÿ‰‘ Portable UTF-8 library - performance optimized (unicode) string functions for php.
Stars: โœญ 405 (+123.76%)
Mutual labels:  unicode, string-manipulation, utf-8
Voca rs
Voca_rs is the ultimate Rust string library inspired by Voca.js, string.py and Inflector, implemented as independent functions and on Foreign Types (String and str).
Stars: โœญ 167 (-7.73%)
Mutual labels:  unicode, string-manipulation, utf-8
Tiny Utf8
Unicode (UTF-8) capable std::string
Stars: โœญ 322 (+77.9%)
Mutual labels:  unicode, string-manipulation, utf-8
string theory
Flexible modern C++ string library with type-safe formatting
Stars: โœญ 32 (-82.32%)
Mutual labels:  strings, utf-8, string-manipulation
Encoding.js
Convert or detect character encoding in JavaScript
Stars: โœญ 338 (+86.74%)
Mutual labels:  unicode, utf-8
Guide To Swift Strings Sample Code
Xcode Playground Sample Code for the Flight School Guide to Swift Strings
Stars: โœญ 136 (-24.86%)
Mutual labels:  unicode, strings
Bstr
A string type for Rust that is not required to be valid UTF-8.
Stars: โœญ 348 (+92.27%)
Mutual labels:  unicode, utf-8
Transliteration
UTF-8 to ASCII transliteration / slugify module for node.js, browser, Web Worker, React Native, Electron and CLI.
Stars: โœญ 444 (+145.3%)
Mutual labels:  unicode, utf-8
unicode-c
A C library for handling Unicode, UTF-8, surrogate pairs, etc.
Stars: โœญ 32 (-82.32%)
Mutual labels:  unicode, utf-8
Tomlplusplus
Header-only TOML config file parser and serializer for C++17 (and later!).
Stars: โœญ 403 (+122.65%)
Mutual labels:  unicode, utf-8
Twine
String manipulation, leveled up!
Stars: โœญ 496 (+174.03%)
Mutual labels:  strings, string-manipulation
Chr
๐Ÿ”ค Lightweight R package for manipulating [string] characters
Stars: โœญ 18 (-90.06%)
Mutual labels:  strings, string-manipulation
Cuerdas
String manipulation library for Clojure(Script)
Stars: โœญ 272 (+50.28%)
Mutual labels:  strings, string-manipulation
libWinTF8
The library handling things related to UTF-8 and Unicode when you want to port your program to Windows
Stars: โœญ 18 (-90.06%)
Mutual labels:  unicode, utf-8
Unicopy
Unicode command-line codepoint dumper
Stars: โœญ 16 (-91.16%)
Mutual labels:  unicode, utf-8
Mightystring
Making Ruby Strings Powerful
Stars: โœญ 28 (-84.53%)
Mutual labels:  strings, string-manipulation
Unibits
Visualize different Unicode encodings in the terminal
Stars: โœญ 125 (-30.94%)
Mutual labels:  unicode, utf-8
StringPool
A performant and memory efficient storage for immutable strings with C++17. Supports all standard char types: char, wchar_t, char16_t, char32_t and C++20's char8_t.
Stars: โœญ 19 (-89.5%)
Mutual labels:  strings, utf-8
UniObfuscator
Java obfuscator that hides code in comment tags and Unicode garbage by making use of Java's Unicode escapes.
Stars: โœญ 40 (-77.9%)
Mutual labels:  unicode, utf-8
Awesome Unicode
๐Ÿ˜‚ ๐Ÿ‘Œ A curated list of delightful Unicode tidbits, packages and resources.
Stars: โœญ 693 (+282.87%)
Mutual labels:  unicode, utf-8

Stringz Build Status codecov npm

A really small, performant, unicode-aware library for working with Strings in Node.js.

Javascript has a serious problem with unicode. Even ES6 canโ€™t solve the problem entirely since some characters like the new colored emojis are three bytes instead of two bytes. Sometimes even more! "๐Ÿ‘๐Ÿฝ".length returns 4 which is totally wrong (hint: it should be 1!). ES6's Array.from tried to solve this, but that even fails: Array.from("๐Ÿ‘๐Ÿฝ") returns ["๐Ÿ‘", "๐Ÿฝ"] which is incorrect. This library tries to tackle all these problems with a mega RegExp. Read More Here.

Features

  • Unicode-aware string manipulation tools
  • High performance

Install

$ npm install stringz --save

And import it in your awesome node app:

// ES2015+
import * as stringz from 'stringz'; // OR:
import { limit, substring, length, substr } from 'stringz';
// CommonJS
const stringz = require('stringz'); // OR:
const { limit, substr } = require('stringz');

Usage

Limit String to Width

function limit(str[, limit[, padStr[, padPosition]]])
Param Type Default Description
str String none The string to be limited
limit Number 16 Desired string length
padStr String "#" Character to pad the output with
padPosition String "right" Pad position: "right" or "left"

Examples

// Truncate:
limit('Lifeโ€™s like a box of chocolates.', 20); // "Life's like a box of"

// Pad:
limit('Everybody loves emojis!', 26, '๐Ÿ’ฉ'); // "Everybody loves emojis!๐Ÿ’ฉ๐Ÿ’ฉ๐Ÿ’ฉ"
limit('What are you looking at?', 30, '+', 'left'); // "++++++What are you looking at?"

// Unicode Aware:
limit('๐Ÿค”๐Ÿค”๐Ÿค”', 2); // "๐Ÿค”๐Ÿค”"
limit('๐Ÿ‘๐Ÿฝ๐Ÿ‘๐Ÿฝ', 4, '๐Ÿ‘๐Ÿฝ'); // "๐Ÿ‘๐Ÿฝ๐Ÿ‘๐Ÿฝ๐Ÿ‘๐Ÿฝ๐Ÿ‘๐Ÿฝ"

String Length

function length(str)
Param Type Default Description
str String none String to return the length for

Examples

length('Iรฑtรซrnรขtiรดnร lizรฆtiรธnโ˜ƒ๐Ÿ’ฉ'); // 22

Substring

function substring(str, start[, end])
Param Type Default Description
str String none String to be devided
start Number none Start position
end Number End of string End position

Examples

substring('Emojis ๐Ÿ‘๐Ÿฝ are ๐Ÿ† poison. ๐ŸŒฎs are bad.', 7, 14); // "๐Ÿ‘๐Ÿฝ are ๐Ÿ†"

Substr

function substr(str[, start[, length]])
Param Type Default Description
str String none String to be devided
start Number Start of string Start position
length Number String length minus start parameter Length of result

Examples

substr('A.C. Milan ๐Ÿ‡ฎ๐Ÿ‡นโšฝ๏ธ', 5, 7); // "Milan ๐Ÿ‡ฎ๐Ÿ‡น"

IndexOf

function indexOf(str[, searchStr[, position]])
Param Type Default Description
str String none String to get index
searchStr String none String to be searched
position Number 0 Start of searching

Examples

indexOf('Emojis ๐Ÿ‘๐Ÿฝ are ๐Ÿ† poison. ๐ŸŒฎs are bad.', 'are'); // 9
indexOf('Emojis ๐Ÿ‘๐Ÿฝ are ๐Ÿ† poison. ๐ŸŒฎs are bad.', 'are', 10); // 26

ToArray

function toArray(str)
Param Type Default Description
str String none String to convert to array

Examples

toArray('๐Ÿ‘๐Ÿฝ๐Ÿ†๐ŸŒฎ'); // ['๐Ÿ‘๐Ÿฝ', '๐Ÿ†', '๐ŸŒฎ']

Test

$ npm test

Benchmark

This library scores high in a length benchmark (it's intended usage) and should be fast for most use case.

Stringz .length (accurate) x 861,039 ops/sec ยฑ1.57% (84 runs sampled)
Lodash .toArray (accurate) x 795,108 ops/sec ยฑ2.13% (82 runs sampled)
Emoji Aware .split (inaccurate) x 2,269 ops/sec ยฑ1.38% (85 runs sampled)
Spliddit .length (inaccurate) x 487,718 ops/sec ยฑ2.21% (83 runs sampled)
UTF8 Length (inaccurate) x 232,918 ops/sec ยฑ1.02% (87 runs sampled)
Fastest is Stringz .length

To run benchmarks yourself:

$ cd ./benchmark
$ npm install
$ node run.js

Changelog

Moved to CHANGELOG.md

License

This software is released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].