Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@basd/formatter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@basd/formatter

A comprehensive text formatting and manipulation library written in JS.

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Formatter

npm pipeline license downloads

Gitlab Twitter Discord

A comprehensive text formatting and manipulation library written in JS. It aims to offer a simple and efficient way to format, normalize, tokenize, and filter text in various scenarios.

Installation

Install the package with:

npm install @basd/formatter

Usage

First, import the Formatter library.

import Formatter from '@basd/formatter'

or

const Formatter = require('@basd/formatter')

Or import TextFormatter and StopWordFilter classes like this:

const { TextFormatter, StopWordFilter } = require('@basd/formatter')

TextFormatter

const formatter = new TextFormatter()

console.log(formatter.normalizeSearchQuery('hello & world | earth'))
// Output: 'HELLO AND WORLD OR EARTH'

console.log(formatter.toUpperCase('hello world'))
// Output: 'HELLO WORLD'

console.log(formatter.toLowerCase('HELLO WORLD'))
// Output: 'hello world'

console.log(formatter.stripPunctuation('hello, world!'))
// Output: 'hello world'

const tokens = formatter.tokenize('This is an example.')
console.log(tokens)
// Output: ['this', 'is', 'an', 'example']

StopWordFilter

const stopWordFilter = new StopWordFilter(['a', 'an', 'the'])
console.log(stopWordFilter.filter(['this', 'is', 'a', 'test']))
// Output: ['this', 'is', 'test']

Documentation

TextFormatter

Methods
  • normalizeSearchQuery(text: string): string
  • stripPunctuation(text: string): string
  • toUpperCase(text: string): string
  • toLowerCase(text: string): string
  • splitWords(text: string): Array<string>
  • filterStopWords(words: Array<string>): Array<string>
  • normalize(text: string, upper: boolean = false): string
  • tokenize(text: string, filterStopWords: boolean = true): Array<string>
  • setStopWords(stopWords: Array<string>): Set a new list of stop words.

StopWordFilter

Methods
  • filter(words: Array<string>): Array<string>
  • setStopWords(stopWords: Array<string>): Set a new list of stop words.
Static Methods
  • get defaultStopWords(): Array<string>: Get the default list of stop words.
  • get extendedStopWords(): Array<string>: Get an extended list of stop words. (extendedStopWords must be imported or defined.)

Tests

In order to run the test suite, simply clone the repository and install its dependencies:

git clone https://gitlab.com/frenware/utils/formatter.git
cd formatter
npm install

To run the tests:

npm test

Contributing

Thank you! Please see our contributing guidelines for details.

Donations

If you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!

Bitcoin (BTC):

1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF

Monero (XMR):

46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ

License

@basd/formatter is MIT licensed.

Keywords

FAQs

Package last updated on 08 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc