npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

emoji-line-break

v1.1.2

Published

Split emoji text into multiple lines.

Downloads

41

Readme

English | 简体中文

emoji-line-break.js

Build Status npm

Split emoji string into an array. The purpose is to solve the problem of line wrapping drawn on Canvas with emoji string. (demo)

Installation

Nodejs

npm install emoji-line-break
var emojiLineBreak = require('emoji-line-break');

You should disable @babel/plugin-transform-unicode-regex if you use babel to convert es6 to es5. (e.g)

Browser

You can use this smaller version if you can provide the canvas2d. (size~15.3kb)

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/emoji-line-break.canvas2d.min.js"></script>

Full ver. (size~63.4kb)

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/emoji-line-break.min.js"></script>

Usage

Syntax

emojiLineBreak(text[, options]);
  • text
    • Type: String
    • The string to be split.
  • options (optional)
    • Type: Object
    • Split string configuration. Check out the available options.

Examples

var text = `Lorem ipsum dolor sit amet,☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕☕

quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.`;

console.log('result:', emojiLineBreak(text, {
    lang: 'en',
    wordBreak: 'break-word',
    fontWeight: 'normal',
    fontFamily: 'sans-serif',
    fontSize: '16px',
    width: '500px'
}));

output:

result: [
  'Lorem ipsum dolor sit amet,☕☕☕☕☕☕☕☕☕☕☕☕',
  '☕☕☕☕☕☕☕☕☕☕☕☕☕',
  '',
  'quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea ',
  'commodo consequat.'
]

Options

canvas2d (optional)

  • Type: CanvasRenderingContext2D
  • Default: null

In an environment that supports Canvas, you can provide the CanvasRenderingContext2D to support all languages, improve line break precision and customize the values of fontWeight and fontFamily.

You must pass in the CanvasRenderingContext2D if you use the smaller version.

lang (optional)

  • Type: String
  • Default: en
  • Options:
    • en: Matches and calculates 26 English uppercase, lowercase letters and basic English punctuation in the split string(text).
    • zh: Matches and calculates Chinese, Chinese basic punctuation characters, 26 English uppercase, lowercase letters and English basic punctuation characters in the split string(text).

Set the language used.

This option will be invalid when the canvas2d option is provided.

wordBreak (optional)

  • Type: String
  • Default: break-word
  • Options:
    • break-all: To prevent overflow, word breaks should be inserted between any two characters.
    • break-word: To prevent overflow, word breaks should be inserted between any two words.(All characters before any space are counted as a single word)

Specify how to break lines within words.

fontWeight (optional)

  • Type: String
  • Default: normal
  • Options:
    • lighter: Lighter font weight.
    • normal: Normal font weight.
    • bold: Bold font weight.

Set the font weight.

This option supports custom values when the canvas2d option is provided.

fontFamily (optional)

  • Type: String
  • Default: sans-serif
  • Options:
    • serif: serif font family.
    • sans-serif: sans-serif font family.
    • Arial: Arial font family.
    • cursive: cursive font family.

Set the font family.

This option supports custom values when the canvas2d option is provided.

fontSize (optional)

  • Type: String|Number
  • Default: 16px

Set the font size, only supports px.

width (optional)

  • Type: String|Number
  • Default: 500px

Set the width of the text container, only supports px.

Dependencies

License

MIT © Yayure