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

halfwidth-kit

v1.0.1

Published

halfwidth kit

Downloads

4

Readme

halfwidth-kit

halfwidth kit

Install

npm install halfwidth-kit

Usage & Api

var halfwidth_kit = require("halfwidth-kit");

/*
Calculate the halfwidth-length of a string

halfwidthLength( str [, regHalfwidth ] )
	regHalfwidth
		An RegExp object of Halfwidth charset for calculation.

		The default value is /[\u0000-\u00ff\uFF61-\uFF9F\uFFE8-\uFFEE]+/ug.

		When set `false`, use the default charset by not-Fullwidth, that is,
			the default value is /[^\u1100-\u115F\u11A3-\u11A7 ... \u{30000}-\u{3FFFD}]+/ug.

		A user-defined RegExp object should contain some key elements like '/[...]+/ug' or '^' if needed.

NOTE: To all types, such as Fullwidth, Narrow, Wide, Ambiguous, and even the Halfwidth,
	the actual display width depend on the font system of the environment, not only on the unicode standard.
*/
halfwidth_kit.length("aaa") === 3 &&
halfwidth_kit.length("是是是") === 6 &&
halfwidth_kit.length("aaa是是是") === 9 &&
halfwidth_kit.length("A\uD87E\uDC04Z") === 4 &&
halfwidth_kit.length("😄") === 2 &&
/*
In author's VsCode, without Adlam font support, the 4 chars are shown as 4 'unknown's,
	i.e. 4 same halfwidth 'unknown' chars, so this test add them to the halfwidth charset,
	to make the result equals 4.
	*/
halfwidth_kit.length("𞤲𞥋𞤣𞤫", /[𞤲𞥋𞤣𞤫\u0000-\u00ff\uFF61-\uFF9F\uFFE8-\uFFEE]+/gu) === 4 &&

//In author's VsCode, only the "∈" is a Fullwidth char, so the test want result be 10.
halfwidth_kit.length("∀𝑥∈ℝ,𝑥²≥0", /[∀𝑥ℝ,𝑥²≥0]+/ug) === 10 &&	//defined the Halfwidth
halfwidth_kit.length("∀𝑥∈ℝ,𝑥²≥0", /[^∈\u1100-\u115F\u11A3-\u11A7]+/ug) === 10 &&	//or defined the Fullwidth

/*
Calculate the index of a string by halfwidth

halfwidthIndex( str, startIndex, halfwidthCount [, regHalfwidth ] )
	startIndex
		The start index of the string.

		Note: If startIndex is not from head, i.e value 0, be careful to select a startIndex
			to avoid spliting a unicode char. An example: "A😄Z".slice(0,2) === 'A\uD83D',
			in this case, the startIndex should be 1 or 3, not a 2 that cause error.

	halfwidthCount
		The halfwidth count to step forward.
	regHalfwidth
		refer .length().
*/
halfwidth_kit.getIndex("12一二34三四", 3, 6) === 7 &&
halfwidth_kit.getIndex("12一二34三四", 3, 99) === 8 &&

halfwidth_kit.getIndex("12一二34三四", 0, 8) === 6 &&
halfwidth_kit.getIndex("12一二34三四", 0, 9) === 6 &&
halfwidth_kit.getIndex("12一二34三四", 0, 10) === 7 &&

//"A\uD87E\uDC04Z"==='A你Z'
halfwidth_kit.getIndex("A\uD87E\uDC04Z", 0, 1) === 1 &&
halfwidth_kit.getIndex("A\uD87E\uDC04Z", 0, 2) === 1 &&
halfwidth_kit.getIndex("A\uD87E\uDC04Z", 0, 3) === 3 &&

/*
Slice a string by halfwidth

halfwidthSlice( str, startHalfwidth, endHalfwidth [, regHalfwidth ] )
	startHalfwidth
		The start halfwidth index.
		If startHalfwidth < 0, it will be counted from the end of the string.

	endHalfwidth
		The end halfwidth index.
		Set null/undefined to indicate the end of the string.
		Set 0 to indicate the start of the string.
		If endHalfwidth < 0, it will be counted from the end of the string.

	regHalfwidth
		refer .length().
*/

halfwidth_kit.slice("12一二34三四", 0, 2) === "12" &&
halfwidth_kit.slice("12一二34三四", 0, 3) === "12" &&
halfwidth_kit.slice("12一二34三四", 0, 4) === "12一" &&
halfwidth_kit.slice("12一二34三四", 2, -2) === "一二34三" &&
halfwidth_kit.slice("12一二34三四", 3, -3) === "一二34三" &&
halfwidth_kit.slice("12一二34三四", 4, -4) === "二34" &&

halfwidth_kit.slice("12一二34三四", -1) === "" &&
halfwidth_kit.slice("12一二34三四", -2) === "四" &&
halfwidth_kit.slice("12一二34三四", -3) === "四" &&
halfwidth_kit.slice("12一二34三四", -4) === "三四" &&
halfwidth_kit.slice("12一二3", -1) === "3" &&
halfwidth_kit.slice("12一二3", -2) === "3" &&
halfwidth_kit.slice("12一二3", -3) === "二3" &&