logo

String

This is a collection of functions for working with strings.

Generate random

The generateRandomString function returns a random string.

  • The alphabet is the set of characters that are used to generate the random string.
  • The blacklist is a set of strings that are not allowed to be generated.
  • The random function is a function that returns a random array of bytes.
  • The prefix is the string that is prepended to the random string.
  • The separator is the string that separates the prefix, the random string and the suffix.
  • The size is the length of the random string.
  • The suffix is the string that is appended to the random string.
import { generateRandomString } from '@aracna/core';

// will log a 32 chars random alphanumeric string
console.log(generateRandomString());

// will log a 32 chars random numeric string
console.log(generateRandomString({ alphabet: '0123456789' }));

// will log a 8 chars random alphanumeric string
console.log(generateRandomString({ size: 8 }));

Capitalize

The getCapitalizedString function returns a string with the first letter capitalized. Optionally the rest of the letters can be set to lowercase.

import { getCapitalizedString } from '@aracna/core';

// will log "Hello World"
console.log(getCapitalizedString('hello World'));

// will log "Hello world"
console.log(getCapitalizedString('hello World', true));

Make camel case

The getCamelCaseString function returns a string in camel case.

import { getCamelCaseString } from '@aracna/core';

// will log "helloWorld"
console.log(getCamelCaseString('hello world'));

Make kebab case

The getKebabCaseString function returns a string in kebab case.

import { getKebabCaseString } from '@aracna/core';

// will log "hello-world"
console.log(getKebabCaseString('hello world'));

Make pascal case

The getPascalCaseString function returns a string in pascal case.

import { getPascalCaseString } from '@aracna/core';

// will log "Hello World"
console.log(getPascalCaseString('hello world'));

Make snake case

The getSnakeCaseString function returns a string in snake case.

import { getSnakeCaseStranger } from '@aracna/core';

// will log "hello_world"
console.log(getSnakeCaseStranger('hello world'));

Make custom case

The getSymbolCaseString function returns a string with a symbol between each word.

import { getKebabCaseString } from '@aracna/core';

// will log "hello.world"
console.log(getSymbolCaseString('hello world', '.'));

Check if a string is a float

The isStringFloat function checks if a string is a float.

import { isStringFloat } from '@aracna/core';

// will log true
console.log(isStringFloat('1.5'));

Check if a string is an integer

The isStringInt function checks if a string is an integer.

import { isStringInt } from '@aracna/core';

// will log true
console.log(isStringInt('1'));

Check if a string is a JSON

The isStringJSON function checks if a string is a JSON.

import { isStringJSON } from '@aracna/core';

// will log true
console.log(isStringJSON('{}'));

Check if a string is a URL

The isStringURL function checks if a string is a URL.

import { isStringURL } from '@aracna/core';

// will log true
console.log(isStringURL('https://aracna.dariosechi.it'));