Skip to main content

Helper Utilities

The helper module provides a comprehensive collection of utility functions for string manipulation, data transformation, validation, and formatting. Located at packages/loopar/core/global/helper.js.

String Manipulation

Capitalize

Capitalizes the first character of a string.
import { Capitalize } from 'loopar';

const result = Capitalize('hello world');
// Output: 'Hello world'
text
string
required
The text to capitalize
return
string
The capitalized string

UPPERCASE

Converts a string to uppercase.
import { UPPERCASE } from 'loopar';

const result = UPPERCASE('hello');
// Output: 'HELLO'
text
string
required
The text to convert to uppercase
return
string
The uppercase string

lowercase

Converts a string to lowercase.
import { lowercase } from 'loopar';

const result = lowercase('HELLO');
// Output: 'hello'
text
string
required
The text to convert to lowercase
return
string
The lowercase string

camelCase

Converts a string to camelCase format.
import { camelCase } from 'loopar';

const result = camelCase('hello-world');
// Output: 'helloWorld'

const result2 = camelCase('hello_world');
// Output: 'helloWorld'
str
string
required
The string to convert (supports hyphen and underscore separators)
return
string
The camelCase formatted string

decamelize

Converts a camelCase string to a delimited format.
import { decamelize } from 'loopar';

const result = decamelize('helloWorld');
// Output: 'hello-world'

const result2 = decamelize('dataForUSACounties', { 
  separator: '_', 
  preserveConsecutiveUppercase: true 
});
// Output: 'data_for_USA_counties'
text
string
required
The camelCase text to convert
options
object
Configuration options
separator
string
default:"-"
The separator character to use
preserveConsecutiveUppercase
boolean
default:false
Whether to preserve consecutive uppercase letters (e.g., “USA” stays as “USA”)
return
string
The delimited string

kebabToPascal

Converts a kebab-case string to PascalCase.
import { kebabToPascal } from 'loopar';

const result = kebabToPascal('hello-world-example');
// Output: 'HelloWorldExample'
kebabString
string
required
The kebab-case string to convert
return
string
The PascalCase string

humanize

Converts a string to a human-readable format.
import { humanize } from 'loopar';

const result = humanize('helloWorld');
// Output: 'Hello world'

const result2 = humanize('user_profile_settings');
// Output: 'User profile settings'
string
string
required
The string to humanize (supports camelCase, snake_case, and kebab-case)
return
string
The human-readable string with first letter capitalized

debug_name

Converts a string to a debug-friendly format by replacing spaces and hyphens with underscores.
import { debug_name } from 'loopar';

const result = debug_name('Hello World');
// Output: 'Hello_World'
name
string
required
The name to convert
return
string
The debug-friendly name

Hashing and Random Generation

hash

Generates a hash string from input text.
import { hash } from 'loopar';

const result = hash('mystring');
// Output: 'a1b2c3' (base-36 hash)
str
string
required
The string to hash
return
string
A base-36 encoded hash string

randomString

Generates a random alphanumeric string.
import { randomString } from 'loopar';

const result = randomString(10);
// Output: 'aB3xY9kL2m' (random 10-character string)

const result2 = randomString();
// Output: random 15-character string (default)
length
number
default:15
The length of the random string to generate
return
string
A random alphanumeric string starting with a letter

Value Validation and Conversion

trueValue

Checks if a value represents a boolean true.
import { trueValue } from 'loopar';

trueValue(true);    // true
trueValue('true');  // true
trueValue(1);       // true
trueValue('1');     // true
trueValue(false);   // false
trueValue('0');     // false
value
any
required
The value to check
return
boolean
Returns true if value is true, “true”, 1, or “1”

trueToBinary

Converts a truthy value to binary (1 or 0).
import { trueToBinary } from 'loopar';

const result = trueToBinary(true);
// Output: 1

const result2 = trueToBinary(false);
// Output: 0
value
any
required
The value to convert
return
number
Returns 1 if truthy, 0 otherwise

binaryValue

Checks if a value represents binary 1.
import { binaryValue } from 'loopar';

binaryValue(1);     // true
binaryValue('1');   // true
binaryValue(0);     // false
binaryValue('0');   // false
value
any
required
The value to check
return
boolean
Returns true if value is 1 or “1”

nullValue

Checks if a value is null or undefined.
import { nullValue } from 'loopar';

nullValue(null);        // true
nullValue('null');      // true
nullValue(undefined);   // true
nullValue('undefined'); // true
nullValue(0);           // false
nullValue('');          // false
value
any
required
The value to check
return
boolean
Returns true if value is null, “null”, undefined, or “undefined”

JSON Utilities

isJSON

Checks if a string is valid JSON.
import { isJSON } from 'loopar';

isJSON('{"name": "test"}');  // true
isJSON('invalid');            // false
str
string
required
The string to validate
return
boolean
Returns true if the string is valid JSON

JSONparse

Safely parses a JSON string.
import { JSONparse } from 'loopar';

const result = JSONparse('{"name": "test"}');
// Output: { name: 'test' }

const result2 = JSONparse('invalid', { default: 'fallback' });
// Output: { default: 'fallback' }
obj
string
required
The JSON string to parse
ifNotValid
any
The fallback value if parsing fails (defaults to null)
return
any
The parsed JSON object or the fallback value

fixJSON

Fixes common JSON formatting issues with escaped quotes.
import { fixJSON } from 'loopar';

const fixed = fixJSON('{"name": """"value""}');
// Recursively fixes escaped quote issues
json
string
required
The JSON string to fix
return
string
The fixed JSON string

Avatar and Display Utilities

avatar

Generates avatar initials from a name.
import { avatar } from 'loopar';

const result = avatar('John Doe');
// Output: 'JD'

const result2 = avatar('Loopar Framework');
// Output: 'LF'
name
string
default:"loopar"
The name to generate initials from
size
number
default:32
The size parameter (currently unused, reserved for future use)
return
string
Up to 2 uppercase initials from the name

avatarLetter

Extracts first letters from each word in a string.
import { avatarLetter } from 'loopar';

const result = avatarLetter('John Doe Smith');
// Output: 'JDS'
word
string
required
The text to extract letters from
return
string
Uppercase first letters of each word

Color Utilities

rgba

Converts a hex color to RGBA format.
import { rgba } from 'loopar';

const result = rgba('#ff5733', 0.5);
// Output: 'rgba(255, 87, 51, 0.5)'

const result2 = rgba({ color: '#ff5733', alpha: 0.8 });
// Output: 'rgba(255, 87, 51, 0.8)'
hex
string | object
required
The hex color string (e.g., ‘#ff5733’) or an object with color and alpha properties
alpha
number
default:1
The alpha transparency value (0-1)
return
string | null
The RGBA color string or null if invalid

objToRGBA

Converts an RGB object to RGBA string.
import { objToRGBA } from 'loopar';

const result = objToRGBA({ r: 255, g: 87, b: 51, a: 0.5 });
// Output: 'rgba(255, 87, 51, 0.5)'

const result2 = objToRGBA({ r: 255, g: 87, b: 51 });
// Output: 'rgba(255, 87, 51, 1)'
color
object | string
required
RGB object with r, g, b properties (0-255) and optional a property (0-1)
return
string | null
The RGBA color string or null if invalid

Layout and Style Utilities

aspectRatio

Calculates percentage-based aspect ratio for CSS.
import { aspectRatio } from 'loopar';

const result = aspectRatio('16:9');
// Output: 56.25

const result2 = aspectRatio('4:3');
// Output: 75
ratio
string
required
The aspect ratio in “width:height” format
return
number
The percentage value for padding-bottom CSS trick

renderizableProps

Filters props to only those that can be rendered as HTML attributes.
import { renderizableProps } from 'loopar';

const props = {
  className: 'test',
  onClick: () => {},
  element: 'div',
  style: { color: 'red' },
  'data-id': '123'
};

const result = renderizableProps(props);
// Output: { className: 'test', style: { color: 'red' }, 'data-id': '123' }
props
object
required
The props object to filter
return
object
Filtered props excluding internal properties, event handlers (except children and style), and metadata

Date Formatting

formatDate

Formats a date to a string.
import { formatDate } from 'loopar';

const result = formatDate(new Date());
// Output: '2024-03-15'

const result2 = formatDate(new Date(), 'MM/DD/YYYY');
// Output: '03/15/2024'
date
Date | string
required
The date to format
format
string
default:"YYYY-MM-DD"
The date format string (dayjs format)
return
string | null
The formatted date string or null if invalid

formatTime

Formats a date to a time string.
import { formatTime } from 'loopar';

const result = formatTime(new Date());
// Output: '14:30:00'

const result2 = formatTime(new Date(), 'HH:mm');
// Output: '14:30'
date
Date | string
required
The date to format
format
string
default:"HH:mm:ss"
The time format string (dayjs format)
return
string | null
The formatted time string or null if invalid

formatDateTime

Formats a date to a datetime string.
import { formatDateTime } from 'loopar';

const result = formatDateTime(new Date());
// Output: '2024-03-15 14:30:00'

const result2 = formatDateTime(new Date(), 'MM/DD/YYYY HH:mm');
// Output: '03/15/2024 14:30'
date
Date | string
required
The date to format
format
string
default:"YYYY-MM-DD HH:mm:ss"
The datetime format string (dayjs format)
return
string | null
The formatted datetime string or null if invalid

Comparison and Array Utilities

compare

Compares two strings ignoring case and separators.
import { compare } from 'loopar';

compare('hello-world', 'Hello World');   // true
compare('user_name', 'User Name');       // true
compare('test', 'different');            // false
a
string
required
First string to compare
b
string
required
Second string to compare
return
boolean
Returns true if strings are equal (case-insensitive, ignoring - and _)

getArrayMax

Finds the maximum value of a specific column in an array of objects.
import { getArrayMax } from 'loopar';

const data = [
  { id: 1, score: 85 },
  { id: 2, score: 92 },
  { id: 3, score: 78 }
];

const maxScore = getArrayMax(data, 'score');
// Output: 92
array
Array<object>
required
The array of objects
col
string
required
The column name to find the maximum value
return
number
The maximum value found, or 0 if array is empty

Data Structure Utilities

fieldList

Flattens a nested field structure into a single array.
import { fieldList } from 'loopar';

const fields = [
  { name: 'field1', elements: [
    { name: 'nested1' },
    { name: 'nested2', elements: [
      { name: 'deep1' }
    ]}
  ]},
  { name: 'field2' }
];

const flattened = fieldList(fields);
// Output: [field1, nested1, nested2, deep1, field2]
fields
Array | string
required
The fields array or JSON string to flatten
return
Array
A flattened array of all fields including nested elements

ObjectDeepExtend

Deep merges two objects, with circular reference protection.
import { ObjectDeepExtend } from 'loopar';

const target = { a: 1, b: { c: 2 } };
const source = { b: { d: 3 }, e: 4 };

const result = ObjectDeepExtend(target, source);
// Output: { a: 1, b: { c: 2, d: 3 }, e: 4 }
destination
object
required
The target object to extend
source
object
required
The source object to merge from
visited
WeakMap
Internal parameter for tracking visited objects (prevents circular references)
return
object
The merged object

URL and Routing Utilities

toEntityKey

Converts a string to a normalized entity key.
import { toEntityKey } from 'loopar';

const result = toEntityKey('User Profile Settings');
// Output: 'userprofilesettings'

const result2 = toEntityKey('my-entity_name');
// Output: 'myentityname'
str
string
required
The string to convert
return
string
Normalized lowercase string with no separators

urlHash

Generates a hash from a route object including query parameters.
import { urlHash } from 'loopar';

const route = {
  pathname: '/users/edit',
  search: '?name=john&id=123'
};

const hash = urlHash(route);
// Output: unique hash string based on pathname and name parameter
route
object
required
Route object with pathname and search properties
return
string
Hash string based on pathname and name query parameter

urlInstance

Generates a hash from a route pathname.
import { urlInstance } from 'loopar';

const route = { pathname: '/users/edit' };
const hash = urlInstance(route);
// Output: unique hash string based on pathname
route
object
required
Route object with pathname property
return
string
Hash string based on pathname only

AI Integration Utilities

evaluateAIResponse

Extracts content between delimiters from AI responses.
import { evaluateAIResponse } from 'loopar';

const message = 'Here is the result: [{"data": "value"}] and more text';
const result = evaluateAIResponse(message, '[', ']');
// Output: '[{"data": "value"}]'

const result2 = evaluateAIResponse('No brackets here');
// Output: 'No brackets here'
message
string
required
The AI response message
start
string
default:"["
The starting delimiter
end
string
The ending delimiter (defaults to same as start)
return
string
The extracted content between delimiters, or the original message if no delimiters found

Complete Export List

All functions are exported as named exports:
import {
  Capitalize,
  UPPERCASE,
  lowercase,
  debug_name,
  hash,
  trueValue,
  trueToBinary,
  humanize,
  JSONstringify,
  JSONparse,
  decamelize,
  avatar,
  randomString,
  avatarLetter,
  camelCase,
  nullValue,
  isJSON,
  fieldList,
  rgba,
  aspectRatio,
  kebabToPascal,
  cookie,
  renderizableProps,
  binaryValue,
  formatDate,
  formatTime,
  formatDateTime,
  compare,
  getArrayMax,
  objToRGBA,
  ObjectDeepExtend,
  evaluateAIResponse,
  toEntityKey,
  fixJSON,
  urlHash,
  urlInstance
} from 'loopar';

Build docs developers (and LLMs) love