@ph9214/emoji_string_split_js

1.0.3Β β€’Β PublicΒ β€’Β Published

Split emoji strings, including compound emoji such as πŸ‘©πŸ½β€πŸš€

Why You Need It

The .split function native to javascript does not understand compound emojis. So it will work with "Hello World ❓" but not "Hello World πŸ‘©πŸ½β€πŸš€"

How To Install

To install simply run npm install @ph9214/emoji_string_split_js

How To Use

Demo code

let split = require("@ph9214/emoji_string_split_js")

let h = "Hello World πŸ‘©πŸ½β€πŸš€"
let s = h.split("") // ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r','l', 'd', ' ', '\ud83d', '\udc69', '\ud83c', '\udffd', '‍', '\ud83d', '\ude80']
let sn = split.splitE6(h) // [ 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', ' ', 'πŸ‘©πŸ½β€πŸš€' ]
let sanity = (s === sn) // false (would be true if js split worked properly)
let un = split.assembleE6(s) // "Hello World πŸ‘©πŸ½β€πŸš€"
let check = (un === h) // True
console.log( s, sn, un, check, sanity )

What you get

Avalible methods are .splitE6 which splits a string containing emojis and .assembleE6 which combines them back into a normal string reverting the change.

Readme

Keywords

Package Sidebar

Install

npm i @ph9214/emoji_string_split_js

Weekly Downloads

1

Version

1.0.3

License

ISC

Unpacked Size

2.08 kB

Total Files

4

Last publish

Collaborators

  • ph9214