letter-count
TypeScript icon, indicating that this package has built-in type declarations

5.2.1 • Public • Published

letter-count

npm version Build Status Known Vulnerabilities GitHub issues GitHub license

NPM Badge

This is a calculator which counts the number of letters/ characters/ lines/ words/ numbers or wordsigns in a text, useful for your tweets on Twitter, as well as a multitude of other applications.

Whether it is Snapchat, Twitter, Facebook, Yelp or just a note to co-workers or business officials, the number of actual characters matters. What you say may not be as important as how you say it. And how many characters you use.

The idea of this project arose during the development of a game | OpenAPI, while my brother accompanied me for one day in the agency to register the incurrence of free improvised software. So, this is a project that also has been started because of my interests in modelling digital logic and data.

Installation

Via npx:

$ npx letter-count "Hamburg - \nGermany 325!"

$ npx letter-count -int "Hamburg - \nGermany 325!"

Via yarn:

$ yarn add letter-count

Via npm:

$ npm install letter-count

Usage

ECMAScript modules:

import { count, countFromFile, info } from 'letter-count';

CommonJS modules:

const lc = require('letter-count');

API

📍 count(value, [option]) ECMAScript modules:

import { count } from 'letter-count';

const Log = console.log;

Log(count('Hamburg - \nGermany 137!')); 
//=> { 
//      origin: 'Hamburg - \nGermany 137!', 
//      chars: 23, 
//      lines: 2, 
//      words: 2, 
//      numbers: 3, 
//      option: '-a',
//      letters: 14, 
//      wordsigns: 2, 
//      hash: 'd559d4e0ad0770ec6940e6892a9c921b' 
//  }

📍 lc.count(value, [option]) CommonJS modules:

const lc = require('letter-count');

const Log = console.log;

Log(lc.count('Hamburg - \nGermany 137!')); 
//=> { 
//      origin: 'Hamburg - \nGermany 137!', 
//      chars: 23, 
//      lines: 2, 
//      words: 2, 
//      numbers: 3, 
//      option: '-a',
//      letters: 14, 
//      wordsigns: 2, 
//      hash: 'd559d4e0ad0770ec6940e6892a9c921b' 
//  }

➔ The optional option argument accepts a string with the following options:

Counts only the characters:
-c or --chars
// ECMAScript
count('Hamburg - \nGermany 137!', '-c');

// CommonJS
lc.count('Hamburg - \nGermany 137!', '--chars');

//=> { origin: 'Hamburg - \nGermany 137!', chars: 23 }
Counts only the lines:
-ln or --lines
// ECMAScript
count('Hamburg - \nGermany 137!', '-ln');

// CommonJS
lc.count('Hamburg - \nGermany 137!', '--lines'); 

//=> { origin: 'Hamburg - \nGermany 137!', lines: 2 }
Counts only the words:
-w or --words
// ECMAScript
count('Hamburg - \nGermany 137!', '-w');

// CommonJS
lc.count('Hamburg - \nGermany 137!', '--words'); 

//=> { origin: 'Hamburg - \nGermany 137!', words: 2 }
Counts only the numbers:
-n or --numbers
// ECMAScript
count('Hamburg - \nGermany 137!', '-n');

// CommonJS
lc.count('Hamburg - \nGermany 137!', '--numbers'); 

//=> { origin: 'Hamburg - \nGermany 137!', numbers: 3 }
Counts only the integers:
-int or --integers
// ECMAScript
count('Hamburg - \nGermany 137!', '-int');

// CommonJS
lc.count('Hamburg - \nGermany 137!', '--integers'); 

//=> { origin: 'Hamburg - \nGermany 137!', integers: 1 }
Counts only the floats:
-fl or --floats
// ECMAScript
count('Hamburg - \nGermany 13.7!', '-fl');

// CommonJS
lc.count('Hamburg - \nGermany 13.7!', '--floats'); 

//=> { origin: 'Hamburg - \nGermany 137!', floats: 1 }
Counts only the spaces:
-s or --spaces
// ECMAScript
count('Hamburg - \nGermany 13 7!', '-s');

// CommonJS
lc.count('Hamburg - \nGermany 13 7!', '--spaces'); 

//=> { origin: 'Hamburg - \nGermany 13 7!', spaces: 4 }
Counts only the letters:
-l or --letters
// ECMAScript
count('Hamburg - \nGermany 137!', '-l');

// CommonJS
lc.count('Hamburg - \nGermany 137!', '--letters'); 

//=> { origin: 'Hamburg - \nGermany 137!', letters: 14 }
MD5 hash:
-hs or --hash
// ECMAScript
count('Hamburg - \nGermany 137!', '-hs');

// CommonJS
lc.count('Hamburg - \nGermany 137!', '--hash'); 

//=> { origin: 'Hamburg - \nGermany 137!', hash: '6bee63bbc6c56f61fbfd19f1429ad4a3' }
Counts only the words sings:
-ws or --wordsigns
// ECMAScript
count('Hamburg - \nGermany 137!', '-ws');

// CommonJS
lc.count('Hamburg - \nGermany 137!', '--wordsigns'); 

//=> { origin: 'Hamburg - \nGermany 137!', wordsigns: 2 }

📍 countFromFile(file, [option]) ECMAScript modules:

no Browser support

import { countFromFile } from 'letter-count';

const Log = console.log;

Log(countFromFile('/path/to/file.txt')); 
//=> { 
//      origin: 'Hamburg - \nGermany 137!', 
//      chars: 23, 
//      lines: 2, 
//      words: 2, 
//      numbers: 3, 
//      option: '-a',
//      letters: 14,
//      wordsigns: 2, 
//      hash: 'd559d4e0ad0770ec6940e6892a9c921b' 
// }

📍 lc.countFromFile(file, [option]) CommonJS module:

no Browser support

const lc = require('letter-count');

const Log = console.log;

Log(lc.countFromFile('/path/to/file.txt')); 
//=> { 
//      origin: 'Hamburg - \nGermany 137!', 
//      chars: 23, 
//      lines: 2, 
//      words: 2, 
//      numbers: 3, 
//      option: '-a',
//      letters: 14,
//      wordsigns: 2, 
//      hash: 'd559d4e0ad0770ec6940e6892a9c921b' 
// }

➔ The optional option argument accepts a string with the following options:

Counts only the characters:
-c or --chars
// ECMAScript
countFromFile('/path/to/file.txt', '-c');

// CommonJS
lc.countFromFile('/path/to/file.txt', '--chars'); 

//=> { origin: 'Hamburg - \nGermany 137!', chars: 23 }

Counts only the lines:

-ln or --lines
// ECMAScript
countFromFile('/path/to/file.txt', '-ln');

// CommonJS
lc.countFromFile('/path/to/file.txt', '--lines'); 

//=> { origin: 'Hamburg - \nGermany 137!', lines: 2 }

Counts only the words:

-w or --words
// ECMAScript
countFromFile('/path/to/file.txt', '-w');

// CommonJS
lc.countFromFile('/path/to/file.txt', '--words'); 

//=> { origin: 'Hamburg - \nGermany 137!', words: 2 }

Counts only the numbers:

-n or --numbers
// ECMAScript
countFromFile('/path/to/file.txt', '-n');

// CommonJS
lc.countFromFile('/path/to/file.txt', '--numbers');

//=> { origin: 'Hamburg - \nGermany 137!', numbers: 3 }

Counts only the integers:

-int or --integers
// ECMAScript
countFromFile('/path/to/file.txt', '-int');

// CommonJS
lc.countFromFile('/path/to/file.txt', '--integers');

//=> { origin: 'Hamburg - \nGermany 137!', integers: 1 }

Counts only the floats:

-fl or --floats
// ECMAScript
countFromFile('/path/to/file.txt', '-fl');

// CommonJS
lc.countFromFile('/path/to/file.txt', '--floats');

//=> { origin: 'Hamburg - \nGermany 13.7!', floats: 1 }

Counts only the spaces:

-s or --spaces
// ECMAScript
countFromFile('/path/to/file.txt', '-s');

// CommonJS
lc.countFromFile('/path/to/file.txt', '--spaces');

//=> { origin: 'Hamburg - \nGermany 13 7!', spaces: 4 }

Counts only the letters:

-l or --letters
// ECMAScript
countFromFile('/path/to/file.txt', '-l');

// CommonJS
lc.countFromFile('/path/to/file.txt', '--letters'); 

//=> { origin: 'Hamburg - \nGermany 137!', letters: 14 }

Counts only the word signs:

-ws or --wordsigns
// ECMAScript
countFromFile('/path/to/file.txt', '-ws');

// CommonJS
lc.countFromFile('/path/to/file.txt', '--wordsigns'); 

//=> { origin: 'Hamburg - \nGermany 137!', wordsigns: 2 }

MD5 hash:

-hs or --hash
// ECMAScript
countFromFile('/path/to/file.txt', '-hs');

// CommonJS
lc.countFromFile('/path/to/file.txt', '--hash'); 

//=> { origin: 'Hamburg - \nGermany 137!', hash: '6bee63bbc6c56f61fbfd19f1429ad4a3' }

📍 info([key]) ECMAScript module:

no Browser support

import { info } from 'letter-count';

const Log = console.log;

Log(info('author')); 
//=>  {
//      author: { 
//          name: 'Tom S.', 
//          email: 'thoschulte@gmail.com' 
//      }
//  }

📍 lc.info([key]) CommonJS module:

no Browser support

const lc = require('letter-count');

const Log = console.log;

Log(lc.info()); 
//=>  { 
//      name: 'letter-count',
//      version: '5.0.0',
//      description: 'This is a calculator which counts the number of letters/ characters/ lines/ words/ numbers or wordsigns in a text, useful for your tweets on Twitter, as well as a multitude of other applications.',
//      author: { 
//          name: 'Tom S.', 
//          email: 'thoschulte@gmail.com' 
//      },
//      license: 'MIT' 
//  }

Using the letter-count binary

To use the letter-count binary in your shell, simply install letter-count globally using npm:

$ npx letter-count [option] "Hamburg - \nGermany 325!"
$ npm install -g letter-count 

After that you’re able to count from the command line:

$ letter-count hamburg 
#=> July 13, 2023 at 12:00:00 - hamburg : {"chars": "7", "hash": "f23bb5e2f7d35c767b40eddd42ac0e08", "letters": "7", "lines": "1", "numbers": "0", "option": "-a", "origin": "hamburg", "words": "1", "wordsigns": "0"}
To count only the character, use the -c/--char option:
$ letter-count -c hamburg 
#=> July 13, 2023 at 12:00:00 - hamburg : {"chars": "7", "origin": "hamburg"}
To count only the lines, use the -ln/--lines option:
$ letter-count -ln tom s. 
#=> July 13, 2023 at 12:00:00 - tom s. : {"lines": "1", "origin": "tom s."}
To count only the words, use the -w/--words option:
$ letter-count -w tom hamburg 
#=> July 13, 2023 at 12:00:00 - tom hamburg : {"origin": "tom hamburg", "words": "2"}
To count only the numbers, use the -n/--numbers option:
$ letter-count -n hamburg 20097
#=> July 13, 2023 at 12:00:00 - hamburg 20097 : {"numbers": "5", "origin": "hamburg 20097"}
To count only the integers, use the -int/--integers option:
$ letter-count -int hamburg 20097
#=> July 13, 2023 at 12:00:00 - hamburg 20097 : {"integers": "1", "origin": "hamburg 20097"}
To count only the floats, use the -fl/--floats option:
$ letter-count -fl hamburg 13.7
#=> July 13, 2023 at 12:00:00 - hamburg 13.7 : {"floats": "1", "origin": "hamburg 13.7"}
To count only the spaces, use the -s/--spaces option:
$ letter-count -s hamburg tom npm
#=> July 13, 2023 at 12:00:00 - hamburg tom npm : {"spaces": "2", "origin": "hamburg tom npm"}
To count only the letters, use the -l/--letters option:
$ letter-count -l tom 13 hh
#=> July 13, 2023 at 12:00:00 - tom 13 hh : {"letters": "5", "origin": "tom 13 hh"}
To count only the wordsigns, use the -ws/--wordsigns option:
$ letter-count -ws germany!
#=> July 13, 2023 at 12:00:00 - germany! : {"origin": "germany!", "wordsigns": "1"}
To generate a hash (MD5), use the -hs/--hash option:
$ letter-count -hs hamburg
#=> July 13, 2023 at 12:00:00 - hamburg : {"hash": "f23bb5e2f7d35c767b40eddd42ac0e08", "origin": "hamburg"}
To count in a file, use the -f/--file option and the path to the file:
$ letter-count -f path/to/file/input.txt
#=> July 13, 2023 at 12:00:00 - path/to/file/input.txt : {"chars": "11", "hash": "374b094aaccf1fa849642a2de03d6dbe", "letters": "9", "lines": "2", "numbers": "0", "option": "-a", "origin": "foo\nbar baz", "words": "3", "wordsigns": "0"}

NPM

https://npmjs.com/package/letter-count


Doc

jsdoc logo


RinKit

https://npm.runkit.com/letter-count


Links

Author

RTL - Games

letter-count for Angular

ShieldsIO


License

This library is available under the MIT license.


Package Sidebar

Install

npm i letter-count

Weekly Downloads

39

Version

5.2.1

License

MIT

Unpacked Size

48.7 kB

Total Files

17

Last publish

Collaborators

  • thoschu
  • reinhard