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

@vipran/aksharas

v0.4.0

Published

Aksharas is an utility for analysing akṣaras and varṇas in a Devanagari text.

Downloads

15

Readme

Aksharas

npm (scoped) npm type definitions NPM

Aksharas is an utility for analysing akṣaras and varṇas in a Devanagari text.

Installation

npm i @vipran/aksharas

Usage

import Aksharas from "@vipran/aksharas";

// OR for CommonJS:
// const Aksharas = require("@vipran/aksharas").default;

const input = "सर्वे भवन्तु सुखिनः।"

const results = Aksharas.analyse(input);

const aksharas = results.aksharas.map(akshara => akshara.value);

console.log(aksharas); // "स", "र्वे", "भ", "व", "न्तु", "सु", "खि", "नः"

API

Aksharas.analyse()

Accepts a string input and returns a Results object.

const input: string = 'नमः';
const results: Results = Aksharas.analyse(input);

Aksharas.TokenType

It is an enum with the following values:

  • TokenType.Akshara
  • TokenType.Symbol
  • TokenType.Whitespace
  • TokenType.Invalid
  • TokenType.Unrecognised

These can be used to filter the tokens in the Results object. Example:

import Aksharas from "@vipran/aksharas";
// OR import Aksharas, { TokenType } ...

const input = "हे! हरेऽत्र नागच्छ।";
const results = Aksharas.analyse(input);
const symbols = results.all
  .filter((token) => token.type === Aksharas.TokenType.Symbol)
  .map((token) => token.value);

console.log(symbols); // "ऽ", "।"

Aksharas.VarnaType

It is an enum with the following values:

  • VarnaType.Svara
  • VarnaType.Vyanjana

These can be used to filter the varnas in Results.varnas. Example:

import Aksharas from "@vipran/aksharas";
// OR import Aksharas, { VarnaType } ...

const input = "गुरुः";
const results = Aksharas.analyse(input);

const svaras = results.varnas
  .filter((varna) => varna.type === Aksharas.VarnaType.Svara)
  .map((varna) => varna.value);

console.log(svaras); // "उ", "उः"

Results

The Results object contains the following properties:

  • all
    • type: Token[]
    • An array of Token objects containing all the tokens analysed from input string. It includes Devanagari akṣaras, Devanagari symbols (१, २, ।, ॥, etc.) and non-devangari characters (i.e. characters in other scripts, special characters, whitespace characters, etc.)
  • aksharas
    • type: Token[]
    • Devanagari syllables like रा, सी, etc. Here, halanta consonants such as क्, च्, य्, etc. are also considered as aksharas when they are at the end of a word.
  • varnas
    • type: Varna[]
    • Devanagari consonants and vowels in the input. (Only in v0.4.0 or above.)
  • symbols
    • type: Token[]
    • Devanagari symbols such as १, २, ।, ॥, etc.
  • whitespaces
    • type: Token[]
    • All whitespace characters: \s, \t, \n, etc.
  • invalid
    • type: Token[]
    • All Devanagari characters whose occurance in the input string do not conform to the definition of an akṣara. For example, a virāma or a vowel mark which is not preceded by a consonant is invalid. ("अ्", "गोु", etc.)
  • unrecognised
    • type: Token[]
    • Non-devangari characters (i.e. characters in other scripts and special characters such as @, #, etc.)
  • chars
    • type: string[]
    • All Unicode characters in the input string. Same as String.prototype.split().

Token

Many of the properties in the Results object consists of an array of Token-s. A Token object has the following properties:

  • type
  • value
    • type: string
    • Conatins an analysed part of the input string.
  • from
    • type: number
    • From index - representing the start position of the token in the input string.
  • to
    • type: number
    • To index - representing the end position of the token in the input string.
  • attributes
    • type: Record<string, any>
    • An optional key-value object which may contain other attributes of the token. It is currently used only in the Akshara tokens for storing the varnas in that akshara.

Varna

Results.varnas consists of an array of Varna objects. A Varna object has the following properties:

  • type
  • value
    • type: string
    • Conatins an analysed part of the input string.

License

MIT © Prasanna Venkatesh T S