PriyoScriptPriyoScript
Standard Library

decorators Package

Complete reference for string and date-time formatting APIs in PriyoScript.

Theory

The decorators package centralizes text and date-time formatting in one place. It solves inconsistency in output formatting, slug generation, display strings, and date rendering across programs. Instead of duplicating utility logic in each project file, you can use stable built-in methods that validate inputs and return predictable results.

Current status

decorators is stable and production-ready in current PriyoScript docs.

Import

monalisa {
  lisaaBring decorators
  priyoTell(decorators.upper("mona"))
}

API Table

String APIs

MethodSignatureDescription
upperdecorators.upper(value)Converts text to uppercase
lowerdecorators.lower(value)Converts text to lowercase
trimdecorators.trim(value)Removes leading/trailing spaces
trimStartdecorators.trimStart(value)Removes leading spaces
trimEnddecorators.trimEnd(value)Removes trailing spaces
titledecorators.title(value)Converts words to title case
capitalizedecorators.capitalize(value)Capitalizes first letter
slugdecorators.slug(value)Converts text to URL-friendly slug
snakedecorators.snake(value)Converts text to snake_case
truncatedecorators.truncate(value, maxLength, suffix?)Shortens text with suffix
surrounddecorators.surround(value, prefix, suffix)Wraps text with prefix/suffix
repeatdecorators.repeat(value, count)Repeats string count times
padStartdecorators.padStart(value, targetLength, fill?)Left pads string
padEnddecorators.padEnd(value, targetLength, fill?)Right pads string
replaceAlldecorators.replaceAll(value, searchValue, replaceValue)Replaces all occurrences
formatNumberdecorators.formatNumber(value, decimals?)Formats number with decimals

Date-Time APIs

MethodSignatureDescription
nowTimestampdecorators.nowTimestamp()Current epoch timestamp
nowISOdecorators.nowISO()Current ISO date-time string
todaydecorators.today()Current date as YYYY-MM-DD
timeNowdecorators.timeNow()Current time as HH:mm:ss
formatdecorators.format(dateValue, pattern?)Formats date by tokens
addDaysdecorators.addDays(dateValue, days)Adds days to date
addHoursdecorators.addHours(dateValue, hours)Adds hours to date
addMinutesdecorators.addMinutes(dateValue, minutes)Adds minutes to date
addMonthsdecorators.addMonths(dateValue, months)Adds months to date
addYearsdecorators.addYears(dateValue, years)Adds years to date
diffDaysdecorators.diffDays(startDate, endDate)Day difference
diffHoursdecorators.diffHours(startDate, endDate)Hour difference
diffMinutesdecorators.diffMinutes(startDate, endDate)Minute difference
isWeekenddecorators.isWeekend(dateValue)Checks if weekend
startOfDaydecorators.startOfDay(dateValue)Start of day ISO
endOfDaydecorators.endOfDay(dateValue)End of day ISO
toTimestampdecorators.toTimestamp(dateValue)Date to timestamp

Format Tokens

TokenMeaning
YYYYYear
MMMonth
DDDay
HHHour
mmMinute
ssSecond
SSSMilliseconds

API Examples (All String Methods)

monalisa {
  lisaaBring decorators

  priyoTell(decorators.upper("mona and piue"))
  priyoTell(decorators.lower("HELLO PRIYOSCRIPT"))
  priyoTell(decorators.trim("  hello  "))
  priyoTell(decorators.trimStart("  hello"))
  priyoTell(decorators.trimEnd("hello  "))
  priyoTell(decorators.title("welcome to priyoscript"))
  priyoTell(decorators.capitalize("mona"))
  priyoTell(decorators.slug("Priyo Script Language"))
  priyoTell(decorators.snake("Priyo Script Language"))
  priyoTell(decorators.truncate("mona and piue are coding", 12))
  priyoTell(decorators.surround("mona", "[", "]"))
  priyoTell(decorators.repeat("ha", 3))
  priyoTell(decorators.padStart("7", 3, "0"))
  priyoTell(decorators.padEnd("7", 3, "0"))
  priyoTell(decorators.replaceAll("mona likes tea", "tea", "coffee"))
  priyoTell(decorators.formatNumber(1234.5678, 2))
}

Output:

MONA AND PIUE
hello priyoscript
hello
hello
hello
Welcome To Priyoscript
Mona
priyo-script-language
priyo_script_language
mona and ...
[mona]
hahaha
007
700
mona likes coffee
1234.57

API Examples (All Date-Time Methods)

monalisa {
  lisaaBring decorators

  priyoTell(decorators.nowTimestamp())
  priyoTell(decorators.nowISO())
  priyoTell(decorators.today())
  priyoTell(decorators.timeNow())

  priyoKeep base = "2026-03-01T10:30:00.000Z"
  priyoTell(decorators.format(base, "DD/MM/YYYY HH:mm:ss"))
  priyoTell(decorators.addDays(base, 7))
  priyoTell(decorators.addHours(base, 3))
  priyoTell(decorators.addMinutes(base, 45))
  priyoTell(decorators.addMonths(base, 1))
  priyoTell(decorators.addYears(base, 1))
  priyoTell(decorators.diffDays("2026-03-01", "2026-03-21"))
  priyoTell(decorators.diffHours("2026-03-01T00:00:00Z", "2026-03-02T12:00:00Z"))
  priyoTell(decorators.diffMinutes("2026-03-01T00:00:00Z", "2026-03-01T01:30:00Z"))
  priyoTell(decorators.isWeekend("2026-03-09"))
  priyoTell(decorators.startOfDay(base))
  priyoTell(decorators.endOfDay(base))
  priyoTell(decorators.toTimestamp(base))
}

Output:

(current timestamp number)
(current ISO date-time string)
(current date)
(current time)
01/03/2026 16:00:00
2026-03-08T10:30:00.000Z
2026-03-01T13:30:00.000Z
2026-03-01T11:15:00.000Z
2026-04-01T10:30:00.000Z
2027-03-01T10:30:00.000Z
20
36
90
false
2026-03-01T00:00:00.000Z
2026-03-01T23:59:59.999Z
1456828200000

Error Cases

monalisa {
  lisaaBring decorators
  priyoTell(decorators.repeat("x", -1))
}

Expected error:

decorators.repeat expects count to be a non-negative integer
monalisa {
  lisaaBring decorators
  priyoTell(decorators.format("not-a-date", "YYYY-MM-DD"))
}

Expected error:

decorators.format expects dateValue to be a valid date input

Validation Notes

  • String helpers expect string input unless method signature says otherwise. - Date helpers require valid date input values. - replaceAll requires non-empty searchValue. - repeat requires non-negative integer count.

Practice Questions

Concept Check

  1. When should you use title vs upper? 2. Why is format(date, pattern) better than manual string concatenation for dates? 3. What is the practical difference between today() and nowISO()?

Last updated on

On this page