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

atext-wordz

v1.0.4

Published

Provides a list of words within an entire text alongside few statistics

Downloads

1

Readme

npm version License: MIT

Provides a list of words within an entire text alongside few statistics


Getting started

  1. Install the package
    $ npm i atext-wordz
  2. Require it's functions
    const { getWStatsList , getWStatsObj , getWordList } = require( "atext-wordz" );
  3. Call it's functions Regarding your needs you have to pick in what format you wish to get the result. NOTE : You have 3 choices
    const result = getWStatsList( text , options );
    // ==> [ {}:wordstats(1), {}, {}, ... , {}:wordstats(N)    ]
    
    // OR
    
    const result = getWStatsObj( text , options );
    // ==> { wordstats1, wordstats2, ..., wordstatsN  }
    
    // OR
    
    const result = getWordList( text , options );
    // ==> ["word 1", "word 2", ... "word N"]

Light demo

Assuming you have a demo.txt file in a demo folder at the same level as this .js file and you want to get word stats.

const { fs } = require('fs') ;

const { getWStatsList , getWStatsObj , getWordList } = require( "../atext-wordz" );

fs.readFile( "./demo/demo.txt" , "utf8" , ( err , text ) => {

  const sortString = ` by number of a > than b's `;
  const cbOnNewWord = ( word ) => {
    // TODO: make first sector actions on new word found
  };

  const options = {  sortString , cbOnNewWord };

  const result = getWStatsList( text , options );

  console.log( result );
  // outputs :
  // < an array of word statistics sorted by most used words >

});

Options

There is few options to meet your requirements at this time. Here is the definition table.

| option | type | default | |-|-|-| |sortString|string|""| |minimumLength|number|2| |cbOnNewWord|function| (word:string) => {}|

  1. sortString You can sort your words and stats before the service wraps everything up. Thanks to the integrated byStr~Sort npm module. You may find usefull to ceck it's sortString section.

    const sortString = `
        by order of a greater than b's then
        by number of a < than b's
    `;

    NOTE : Every sort sentence starts by byand can be ended by then to chain other sort sentences

  2. minimumLength You can define the minimum length of words during the analysis, phase.

  3. cbOnNewWord Provides you with a callback function that will be called whenever a new word is encountered. Which means, only once per word.


Stats

The services will gives you a stats matching an instance of IStatsOfWords or IStatsOfWordsObject or a simple array of strings.

Here are the definitions for each of them:

IStatsOfWords |field|type|notes| |-|-|-| |word|string|the word| |order|number|the order of appearence| |number|number|the number appearence| |length|number|the word's length|

IStatsOfWordsObject Each word will be a key and stats will be the value of that pair ||order|number|length| |-|-|-|-| |type|number|number|number|


Word detection

It is not that easy to detect words in a text that is quite big and containing many noises. It's not as easy as spliting on every space. And a normal text relies also on punctuation.

By chance French and English punctuation may not very this much or not at all.

Therefore, detecting anything matching anything something else than a "special" character chould be considered as part of a world. Things come very complicated when dealing with languages that are not that strict about isolating words... like japanese or chinese to list very a few.

Here is the regex that helped to detect non special characters :

const special = 
    /[�\d\s\\[\]\x20-\x40\-`{-~\xA0-\xBF×Ø÷øʹ͵ͺ;!?♪╚-╬┘-▀\uFF3B\uFF40\uFF5B-\uFF65¥・()]/i;