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 🙏

© 2026 – Pkg Stats / Ryan Hefner

extract-zhongwen

v1.1.2

Published

Utility for extracting chinese characters from a string

Readme

extract-zhongwen

extract-zhongwen is a small utility designed to extract Chinese characters from a given string based on Unicode Ranges.


Installation

npm install extract-zhongwen

Features

  • Extracts Chinese characters from an input string.
  • Supports Unicode normalization (NFKC) with optional preservation of specified characters.
  • Allows whitelisting or blacklisting of specific characters.
  • Option to remove duplicate characters.

Function Signature

const extract = (
  input: string,
  options?: Options
): string

Parameters

input (string)

The input string from which Chinese characters will be extracted.

options (Options)

An object containing configuration options.

| Option | Type | Default | Description | | ------------------- | ------- | ------- | -------------------------------------------------------------------------------------------------------------------------------- | | normalizeUnicode | boolean | true | If true, normalizes Unicode characters to NFKC form, while preserving whitelisted characters. | | removeDuplicates | boolean | true | If true, removes duplicate Chinese characters in the output. | | includeCharacters | string | "" | A string of characters to explicitly include in the extracted output, even if they don't match general Chinese character ranges. | | excludeCharacters | string | "" | A string of characters to exclude from the extracted output, even if they match Chinese character ranges. |

Notes

  • Whitelisted characters in includeCharacters will not be normalized if present.
  • includeCharacters and excludeCharacters will treat each character individually. This means that it is not possible to whitelist or blacklist specific words or phrases.
  • If includeCharacters and excludeCharacters contain overlapping characters, the overlapping characters will be filtered out.
  • Whitespaces, punctuation, and any non-Chinese characters are filtered out by default.
  • Duplicate characters are removed at the very end. This means that unnormalized characters and their normalized counterparts may be considered duplicates if the normalizeUnicode option is enabled, even if their Unicode values are technically different.
  • If normalizeUnicode is disabled, characters with different Unicode representations might not be merged correctly.
  • Performance may vary for very large input strings, especially when removeDuplicates is enabled, since it requires additional processing.
  • If no Chinese characters are found in the input, an empty string will be returned.
  • The function does not differentiate between Simplified and Traditional Chinese.

Example Usage

import { extract } from "extract-zhongwen";

console.log(extract("中文字符 English Characters"));
// Output: "中文字符"

// Example with normalization (NFKC)
console.log(extract("社 社 祖 租", { normalizeUnicode: true }));
// Output: "社社租租"

// Example with duplicate removal
console.log(extract("你好 你好 世界 世界", { removeDuplicates: true }));
// Output: "你好世界"

// Example with duplicate removal disabled
console.log(extract("你好 你好 世界 世界", { removeDuplicates: false }));
// Output: "你好你好世界世界"

// Example including a specific character
console.log(
  extract("Hello 你好,世界!", { includeCharacters: "l,! " })
);
// Output: "ll 你好,世界!"

// Example excluding a specific character
console.log(extract("Hello 你好,世界!", { excludeCharacters: "世" }));
// Output: "你好界"

// Example including and excluding characters
console.log(
  extract(
    "那座山,正当顶上,有一块仙石 On the summit of the mountain was a mythical stone",
    {
      includeCharacters: "On the summit of the mountain",
      excludeCharacters: "那座山",
    }
  )
);
// Output: "正当顶上有一块仙石 On the summit of the mountain"