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

vietnamese-search

v1.0.0

Published

Slugify and search Vietnamese text with diacritics support

Downloads

68

Readme

Vietnamese Search

A lightweight utility library for processing Vietnamese text, including slug generation and keyword-based search.

Features

  • Slugify: Convert Vietnamese text into URL-friendly slugs.
  • Search: Perform simple keyword searches on Vietnamese text.

Installation

Install the package using Yarn or NPM:

# Using Yarn
yarn add vietnamese-search

# Using NPM
npm install vietnamese-search

Usage

Importing the Library

// CommonJS
const { slugify, search } = require('vietnamese-search');

// ES Module
import { slugify, search } from 'vietnamese-search';

Slugify

The slugify function converts a given string into a slug suitable for URLs. It handles Vietnamese diacritics and removes special characters.

const text = "Xin chào, Việt Nam!";

const slug1 = slugify(text);
console.log(slug1);
// Output: "xin-chao-viet-nam"

const slug2 = slugify(text, { separator: " " });
console.log(slug2);
// Output: "xin chao viet nam"

Parameters

  1. text (string): The input string to be converted.
  2. options (SlugifyOptions, optional):
  • separator (string, optional): The character used to separate words in the slug. Defaults to "-".

Returns

  • (string): The slugified version of the input string.

Search

The search function performs a keyword search in a given text and provides details about all matches, including the matched strings and their positions.

const text = "Xin chào, Việt Nam! Chào mừng bạn đến với Việt Nam.";
const keyword = "chào";

const result = search(text, keyword);
console.log(result);
// Output:
// {
//   matches: ["chào", "Chào"],
//   positions: [
//     { start: 4, length: 4 },
//     { start: 18, length: 4 }
//   ]
// }

Parameters

  1. text1 (string, required): The input text to search in.
  2. keyword (string, required): The keyword to search for.

Returns

  • (SearchResult): An object with the following structure:
    • matches (string[]): An array of strings that match the keyword (case-insensitive).
    • positions (object[]): An array of objects containing the start index and length of each match.

License

This package is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

Support

If you encounter any issues or have feature requests, feel free to open an issue on GitHub.