Skip to content

Internal Libraries

NeoObjectPascal ships with five ready-to-use libraries, bundled inside the interpreter itself. They cover common tasks involving text, math, dates, files, and collections. Load any of them with the internal. prefix:

npas
uses internal.string, internal.math, internal.datetime;

begin
    WriteLn(toUpperCase("neo"));
    WriteLn(factorial(5));
    WriteLn(getMonthName(7));
end.
Saída
 NEO 120 Julho 

Because they are loaded from inside the JAR, they are always available, regardless of the project directory. See Modules and uses for the mechanics of uses.

internal.string

Functions to inspect, format, and transform strings.

FunctionDescription
isEmpty(s) / isNotEmpty(s)Checks whether the string is (or is not) empty
strLength(s)Length of the string
toUpperCase(s) / toLowerCase(s)Converts to upper / lower case
trim(s)Removes surrounding whitespace
repeat(s, count)Repeats the string count times
join(sep, s1, s2)Joins 2 strings with a separator
join3(sep, s1, s2, s3) / join4(...)Joins 3 or 4 strings
quote(s) / singleQuote(s)Wraps in double / single quotes
bracket(s) / parenthesize(s)Wraps in brackets / parentheses
inStr(haystack, needle)Position of the substring (1-based; 0 if absent)
contains(haystack, needle)Whether it contains the substring
startsWith(s, prefix) / endsWith(s, suffix)Whether it starts / ends with the given piece
subString(s, from, len)Extracts len characters starting at from (1-based)
replaceStr(s, from, to)Replaces all occurrences of from with to
intToStr(n) / strToInt(s)Converts between integer and string
npas
uses internal.string;

begin
    WriteLn(quote("NeoObjectPascal"));
    WriteLn(repeat("*", 3));
    WriteLn(contains("NeoObjectPascal", "Pascal"));
    WriteLn(join(" ", "João", "Silva"));
end.
Saída
 "NeoObjectPascal" *** true João Silva 

internal.math

Mathematical functions for integers.

FunctionDescription
abs(x)Absolute value
max(a, b) / min(a, b)Larger / smaller of two values
square(x) / cube(x)Square / cube
factorial(n)Factorial of n
fibonacci(n)The n-th Fibonacci number
isEven(n) / isOdd(n)Whether it is even / odd
gcd(a, b) / lcm(a, b)Greatest common divisor / least common multiple
sign(x)Sign of the number (-1, 0, or 1)
clamp(value, minVal, maxVal)Constrains value to the range [minVal, maxVal]
npas
uses internal.math;

begin
    WriteLn(abs(-15));
    WriteLn(factorial(5));
    WriteLn(gcd(24, 36));
    WriteLn(clamp(120, 0, 100));
end.
Saída
 15 120 12 100 

internal.datetime

Functions to obtain, validate, format, and compute dates and times.

CategoryFunctions
Current date/timegetCurrentYear, getCurrentMonth, getCurrentDay, getCurrentHour, getCurrentMinute, getCurrentSecond
FormattingformatDate(y, m, d), formatTime(h, m, s), getCurrentDate, getCurrentTime, getCurrentDateTime
ValidationisLeapYear(year), isValidDate(y, m, d), isValidTime(h, m, s)
ComputationgetDaysInMonth(y, m), getAge(ano, mes, dia), addDays(...), addMonths(...), addYears(...)
NamesgetMonthName, getMonthNameEn, getDayOfWeekName, getDayOfWeekNameEn
npas
uses internal.datetime;

begin
    WriteLn("Ano atual: ", getCurrentYear());
    WriteLn("2024 é bissexto? ", isLeapYear(2024));
    WriteLn("Dias em fevereiro/2024: ", getDaysInMonth(2024, 2));
    WriteLn("Nome do mês 10: ", getMonthName(10));
end.
Saída
 Ano atual: 2026 2024 é bissexto? true Dias em fevereiro/2024: 29 Nome do mês 10: Outubro 

internal.file

Functions to work with paths and files.

CategoryFunctions
Path componentsgetFileExtension, getFileName, getFileNameWithoutExtension, getParentDirectory, joinPath
NormalizationnormalizePath, isAbsolutePath, isRelativePath
Name validationisValidFilename, sanitizeFilename, createTempFilename
File systemfileExists, directoryExists, isFile, isDirectory, getFileSize
ClassificationisTextFile, isBinaryFile, formatFileSize
npas
uses internal.file;

begin
    WriteLn(getFileExtension("relatorio.pdf"));
    WriteLn(getFileName("/docs/notas.txt"));
    WriteLn(joinPath("docs", "notas.txt"));
    WriteLn(isTextFile("dados.csv"));
end.
Saída
 pdf notas.txt docs/notas.txt true 

internal.collections

Functions to manipulate arrays and lists.

CategoryFunctions
BasiccreateArray, arraySize, arrayIsEmpty, arrayFirst, arrayLast
SearcharrayContains, arrayIndexOf
TransformationarrayReverse, arraySlice, arraySort, arraySortDesc, arrayUnique, arrayConcat
AggregationarraySum, arrayMax, arrayMin, arrayJoin, arrayReduce
Higher-orderarrayMap, arrayFilter, arrayRange
npas
uses internal.collections;

var lista: Object;

begin
    lista := createArray();
    WriteLn("Vazio? ", arrayIsEmpty(lista));
    WriteLn("Tamanho: ", arraySize(lista));
end.
Saída
 Vazio? true Tamanho: 0 

Native arrays

For most cases, the language's native arrays ([10, 20, 30], indexing a[0], for x in a do) already do the job. See Arrays. The internal.collections library complements them with named utilities.

Combining libraries

Nothing stops you from loading several libraries at once and combining them freely:

npas
uses internal.string, internal.math;

begin
    WriteLn(quote(intToStr(square(8))));
end.
Saída
 "64" 

Next, ensure the quality of your code with Unit Testing.