Options
All
  • Public
  • Public/Protected
  • All
Menu

Module source/words

Index

Variables

Variables

Const words

words: { allWordCount: (str: string, strict?: boolean) => any; capitalize: (str: string) => string | null; readingTime: (wCount: number, imageCount: number, valueOnly?: boolean, wordsPerMinute?: number) => string | number; replaceWord: (str: string, word: string, replaceWith: string, cases?: boolean) => string | null; specificWordCount: (str: string, word: string, strict?: boolean) => number; wordCount: (str: string) => number } = ...

Type declaration

  • allWordCount: (str: string, strict?: boolean) => any
      • (str: string, strict?: boolean): any
      • Takes a string, counts all instances of words in the string, and returns an object with each word and the number of occurences

        Basic usage example:

        import {words} from 'stringman'; // or const words = require('stringman').words;
        const test = `This is my stupid test.
         Its a small test, but it is my test.
         `;
        const lax = words.allWordCount(test);
        const strict = words.allWordCount(test, true);
        console.log(lax); // {"this": 1, "is": 2, "my": 2, "stupid": 1, "test": 3, "its": 1, "a": 1, "small": 1, "but": 1, "it": 1}
        console.log(strict); // {"This": 1, "is": 2, "my": 2, "stupid": 1, "test": 3, "Its": 1, "a": 1, "small": 1, "but": 1, "it": 1}
        

        Parameters

        • str: string
        • Optional strict: boolean

        Returns any

  • capitalize: (str: string) => string | null
      • (str: string): string | null
      • Takes a string and returns with the first character capitalized

        Basic usage example:

        import {words} from 'stringman'; // or const words = require('stringman').words;
        const cap = words.capitalize('test');
        const failure = words.capitalize(true);
        console.log(test); // 'Test'
        console.log(failure); // null
        

        Parameters

        • str: string

        Returns string | null

  • readingTime: (wCount: number, imageCount: number, valueOnly?: boolean, wordsPerMinute?: number) => string | number
      • (wCount: number, imageCount: number, valueOnly?: boolean, wordsPerMinute?: number): string | number
      • Takes word count, image count, boolean for valueOnly which will return only the minutes if set to 'true', and optionally a words per minute value (defaults to 270) and returns estimated reading time

        • Basic usage example:
          import {words} from 'stringman'; // or const words = require('stringman').words;
          const wordCount = 1200;
          const imageCount = 5;
          const readTime =  words.readingTime(wordCount, imageCount);
          const readTimeValueOnly =  words.readingTime(wordCount, imageCount, true);
          const readTimeSpeedReader =  words.readingTime(wordCount, imageCount, false, 400);
          console.log(readTime); // '5 min read'
          console.log(readTimeValueOnly); // 5
          console.log(readTimeSpeedReader); // 4
          

        Parameters

        • wCount: number
        • imageCount: number
        • valueOnly: boolean = false
        • wordsPerMinute: number = 270

        Returns string | number

  • replaceWord: (str: string, word: string, replaceWith: string, cases?: boolean) => string | null
      • (str: string, word: string, replaceWith: string, cases?: boolean): string | null
      • Takes a string, the string to replace, the string to replace the other string with, and the optional boolean argument for case sensitivity and returns the original string with the 2nd argument replaced with the 3rd. Can return null if a failure happens along the way.

        Basic usage example:

        import {words} from 'stringman'; // or const words = require('stringman').words;
        const test = 'We hope this works because we put some serious work into this and we are invested.';
        const sens = words.replaceWord(test, 'we', 'they', true);
        const ins =  words.replaceWord(test, 'we', 'they');
        const failure =  words.replaceWord(test, 5, 'they');
        console.log(sens); // 'They hope this works because they put some serious work into this and they are invested.'
        console.log(ins); // 'they hope this works because they put some serious work into this and they are invested.'
        console.log(failure); // null
        

        Parameters

        • str: string
        • word: string
        • replaceWith: string
        • Optional cases: boolean

        Returns string | null

  • specificWordCount: (str: string, word: string, strict?: boolean) => number
      • (str: string, word: string, strict?: boolean): number
      • Takes 2 strings and returns a number for the number of times the second string exists in the first string; optionally takes third boolean argument to make case sensitive

        Basic usage example:

        import {words} from 'stringman'; // or const words = require('stringman').words;
        const insensitive = words.specificWordCount('Maybe-this will, trip it up! Will it? We WILL see.', 'will');
        const sensitive = words.specificWordCount('Maybe-this will, trip it up! Will it? We WILL see.', 'will', true);
        console.log(insensitive); // 3
        console.log(sensitive); // 1
        

        Parameters

        • str: string
        • word: string
        • Optional strict: boolean

        Returns number

  • wordCount: (str: string) => number
      • (str: string): number
      • Takes a string and returns the number of words in the string as a number

        Basic usage example:

        import {words} from 'stringman'; // or const words = require('stringman').words;
        const count = words.wordCount('This sentence has 4 words.');
        const countAgain = words.wordCount('This sentence has five words.');
        console.log(count); // 4
        console.log(countAgain); // 5
        

        Parameters

        • str: string

        Returns number

Generated using TypeDoc