New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

megaorm-text

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

megaorm-text

This package provides various functions to manipulate and transform strings.

unpublished
latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
0
Created
Source

MegaORM Text

megaorm-text is a utility library that provides various functions to manipulate and transform strings. The package includes functions to convert strings to different cases (camelCase, snake_case, kebab-case, etc.), handle singular/plural transformations, and more.

Installation

To install the package, run:

npm install megaorm-text

Functions

dictionary(singular: string, plural: string): void: Adds or updates the plural form for a singular word in the dictionary.

  • singular: The singular word to be registered.
  • plural: The plural form to be registered.
dictionary('cat', 'cats');
dictionary('bus', 'buses');

toPlural(singular: string): string: Converts a singular word to its plural form based on registered mappings or rules.

  • singular: The singular word to be pluralized.
console.log(toPlural('cat')); // "cats"
console.log(toPlural('bus')); // "buses"

toSingular(plural: string): string: Converts a plural word to its singular form based on registered mappings or rules.

  • plural: The plural word to be converted to singular.
console.log(toSingular('cats')); // "cat"
console.log(toSingular('buses')); // "bus"

toRegex(text: string, flags?: string): RegExp: Converts a string pattern into a regular expression.

  • text: The string pattern to convert.
  • flags: Optional flags for the regular expression.
const regex = toRegex('hello*');
console.log(regex.test('hello world')); // true

toUpper(text: string): string: Converts a string to uppercase.

  • text: The string to convert to uppercase.
console.log(toUpper('hello world')); // "HELLO WORLD"

toLower(text: string): string: Converts a string to lowercase.

  • text: The string to convert to lowercase.
console.log(toLower('HELLO WORLD')); // "hello world"

toUpperAt(text: string, index: number): string: Converts the character at a specified index of a string to uppercase.

  • text: The string to modify.
  • index: The index of the character to convert.
console.log(toUpperAt('hello world', 6)); // "hello World"

toLowerAt(text: string, index: number): string: Converts the character at a specified index of a string to lowercase.

  • text: The string to modify.
  • index: The index of the character to convert.
console.log(toLowerAt('HELLO World', 6)); // "HELLO world"

toUpperFrom(text: string, index: number, to?: number): string: Converts all characters from a specified index to uppercase.

  • text: The string to modify.
  • index: The starting index from which characters will be converted.
  • to: The optional ending index. If not provided, the function will convert from the index to the end of the string.
console.log(toUpperFrom('hello world', 6)); // "hello WORLD"

toLowerFrom(text: string, index: number, to?: number): string: Converts all characters from a specified index to lowercase.

  • text: The string to modify.
  • index: The starting index from which characters will be converted.
  • to: The optional ending index. If not provided, the function will convert from the index to the end of the string.
console.log(toLowerFrom('HELLO World', 6)); // "HELLO world"

toUpperFirst(text: string): string: Converts the first character of a string to uppercase.

  • text: The string whose first character will be converted.
console.log(toUpperFirst('hello world')); // "Hello world"

toKamelCase(text: string): string: Converts a string to camelCase.

  • text: The string to convert to camelCase.
console.log(toKamelCase('hello world')); // "helloWorld"

toPascalCase(text: string): string: Converts a string to PascalCase.

  • text: The string to convert to PascalCase.
console.log(toPascalCase('hello world')); // "HelloWorld"

toSnakeCase(text: string): string: Converts a string to snake_case.

  • text: The string to convert to snake_case.
console.log(toSnakeCase('hello world')); // "hello_world"

toKababCase(text: string): string: Converts a string to kebab-case.

  • text: The string to convert to kebab-case.
console.log(toKababCase('hello world')); // "hello-world"

toTitle(text: string): string: Converts the first character of every word to uppercase.

  • text: The string to be transformed.
console.log(toTitle('hello world')); // "Hello World"

toSlug(text: string): string: Converts a string to a slug.

  • text: The string to be converted to a slug.
console.log(toSlug('Hello world!')); // "hello-world"

toSnap(text: string, length: number): string: Trims the string to a specified length and appends an ellipsis ("...") if the string is longer than the specified length.

  • text: The string to be truncated.
  • length: The maximum length of the string.
console.log(toSnap('This is a long sentence', 10)); // "This is a..."

toChars(text: string, ...exclude: string[]): string[]: Splits a string into an array of characters, optionally excluding certain characters.

  • text: The string to be split into characters.
  • exclude: An optional array of characters to exclude.
console.log(toChars('hello world', 'o')); // ["h", "e", "l", "l", " ", "w", "r", "l", "d"]

toWords(text: string): string[]: Splits a string into an array of words, based on spaces.

  • text: The string to be split into words.
console.log(toWords('hello world')); // ["hello", "world"]

prefix(text: string, portion: string): string: Prefixes a string with a given portion.

  • text: The string to be prefixed.
  • portion: The portion to prefix the string with.
console.log(prefix('world', 'hello ')); // "hello world"

suffix(text: string, portion: string): string: Suffixes a string with a given portion.

  • text: The string to be suffixed.
  • portion: The portion to suffix the string with.
console.log(suffix('hello', ' world')); // "hello world"

infix(text: string, portion: string, index: number): string: Inserts a portion of text into a string at a specific index.

  • text: The original string.
  • portion: The portion to insert.
  • index: The index at which to insert the portion.
console.log(infix('helloworld', ' beautiful', 5)); // "hello beautiful world"

countOf(text: string, search: string | RegExp): number: Counts the occurrences of a substring or pattern in a string.

  • text: The string in which to search.
  • search: The substring or regular expression to search for.
console.log(countOf('hello hello world', 'hello')); // 2

indexOf(text: string, search: string | RegExp, pos: number = 0): number | void: Finds the first index of a substring or pattern in a string, starting from a specified position.

  • text: The string in which to search.
  • search: The substring or regular expression to search for.
  • pos: The position in the string to start the search from (default: 0).
console.log(indexOf('hello world', 'world')); // 6

indexesOf(text: string, search: string | RegExp): Indexes | void: Finds all the indexes of a substring or pattern in a string and returns an array of index ranges.

  • text: The string in which to search.
  • search: The substring or regular expression to search for.
console.log(indexesOf('hello world hello', 'hello')); // [{ start: 0, end: 5 }, { start: 12, end: 17 }]

lastIndexOf(text: string, search: string | RegExp): number | void: Finds the last index of a substring or pattern in a string.

  • text: The string in which to search.
  • search: The substring or regular expression to search for.
console.log(lastIndexOf('hello world hello', 'hello')); // 12

Keywords

megaorm

FAQs

Package last updated on 16 Dec 2024

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