@demouth/mb_strimwidth
v1.0.3
Published
mb_strimwidth ported to JavaScript. Truncates string to specified width, where halfwidth characters count as 1, and fullwidth characters count as 2.
Downloads
51
Maintainers
Readme
mb_strimwidth
mb_strimwidth ported to JavaScript.
Truncates string to specified width, 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.
Installation
Using npm:
npm install @demouth/mb_strimwidth
Using unpkg CDN:
<script src="https://unpkg.com/@demouth/[email protected]/dist/mb_strimwidth.min.js"></script>
Examples
This package has the same result as mb_strimwidth()
in PHP.
ES Module:
import { mb_strimwidth } from "@demouth/mb_strimwidth";
console.log(mb_strimwidth('𩸽定食が食べたい😆', 0, 14, '...')); // 𩸽定食が食...
CommonJS:
const { mb_strimwidth } = require("@demouth/mb_strimwidth");
console.log(mb_strimwidth('𩸽定食が食べたい😆', 0, 14, '...')); // 𩸽定食が食...
Browser:
<script src="https://unpkg.com/@demouth/[email protected]/dist/mb_strimwidth.min.js"></script>
<script>
console.log(mb_strimwidth('𩸽定食が食べたい😆', 0, 14, '...')); // 𩸽定食が食...
</script>
Reference(PHP 7.3.28):
var_dump(mb_strimwidth('𩸽定食が食べたい😆', 0, 14, '...')); // string(19) "𩸽定食が食..."
https://www.php.net/manual/en/function.mb-strimwidth.php