npm.io
1.0.6 • Published 6 years ago

parsetext2json

Licence
ISC
Version
1.0.6
Deps
0
Size
3 kB
Vulns
0
Weekly
0

npm NPM npm

parseText2Json

This repository lets you easily parse any .txt file containing strings or numbers into a dictionary format (JSON Object) that counts the frequency of each word/ number.

How to use it?

  1. Run npm i parsetext2json in your project directory. See an example in the next step.

  2. Using Node.Js to run the code in index.js

    const parse = require('parsetext2json');
    
    const filePath = 'input.txt';
    const output = parse.parseString(filePath);
    console.log(output);
  3. The output should be like below:

    [ { value: 'What', count: 1 },
      { value: 'is', count: 2 },
      { value: 'Lorem', count: 5 },
      { value: 'Ipsum', count: 5 },
      { value: 'simply', count: 1 },
      { value: 'dummy', count: 2 },
      { value: 'text', count: 2 },
                     ...
                     ...
                     ...
      { value: 'PageMaker', count: 1 },
      { value: 'including', count: 1 },
      { value: 'versions', count: 1 } ]