@demouth/mb_strwidth
TypeScript icon, indicating that this package has built-in type declarations

2.0.3 • Public • Published

mb_strwidth

mb_strwidth ported to JavaScript.

Calculates the width of a string, where halfwidth characters count as 1, and fullwidth characters count as 2. See » http://www.unicode.org/reports/tr11/ for details regarding East Asian character widths.

CircleCI

Installation

Using npm:

npm install @demouth/mb_strwidth

Using unpkg CDN:

<script src="https://unpkg.com/@demouth/mb_strwidth@2.0.2/dist/mb_strwidth.min.js"></script>

Examples

This package has the same result as mb_strwidth() in PHP.

ES Module:

import { mb_strwidth } from "@demouth/mb_strwidth";
console.log(mb_strwidth("𠮷野家")); // 6

CommonJS:

const { mb_strwidth } = require("@demouth/mb_strwidth");
console.log(mb_strwidth("𩸽定食食べたい😭")); // 15

Browser:

<script src="https://unpkg.com/@demouth/mb_strwidth@2.0.3/dist/mb_strwidth.min.js"></script>
<script>
  console.log(mb_strwidth("𩸽定食食べたい😭")); // 15
</script>

Reference(PHP 7.3.28):

var_dump(mb_strwidth('𩸽定食食べたい😭')); // int(15)

https://www.php.net/manual/en/function.mb-strwidth.php

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.3
    4,295
    • latest

Version History

Package Sidebar

Install

npm i @demouth/mb_strwidth

Weekly Downloads

4,512

Version

2.0.3

License

MIT

Unpacked Size

80.2 kB

Total Files

18

Last publish

Collaborators

  • demouth