Skip to content

Core package

This package provides common algorithms and data structures.

{
  "type": "library"
}

Install

{
  "dependencies": {
    "Core": "pen:///core"
  } 
}

Core'Bit module

This module provides bitwise operations.

Most functions defined in this module take arguments of 64-bit integers. They can be converted from and into integers represented in IEEE-754 of a number type.

Types

No types are defined.

Functions

And

Calculate bitwise "and" given two 64-bit integers.

\(x number, y number) number

Or

Calculate bitwise "or" given two 64-bit integers.

\(x number, y number) number

Xor

Calculate bitwise exclusive-"or" given two 64-bit integers.

\(x number, y number) number

Not

Calculate bitwise "not" given two 64-bit integers.

\(x number) number

LeftShift

Calculate unsigned left shift given a 64-bit integer.

\(x number, n number) number

RightShift

Calculate unsigned right shift given a 64-bit integer.

\(x number, n number) number

ToInteger64

Convert an integer in IEEE-754 to a 64-bit integer.

\(x number) number

FromInteger64

Convert a 64-bit integer to an integer in IEEE-754.

\(x number) number

Core'Boolean module

This module provides common boolean operations.

Types

No types are defined.

Functions

Any

Return true if any of given booleans are true or false otherwise.

\(bs [boolean]) boolean

All

Return true if all of given booleans are true or false otherwise.

\(bs [boolean]) boolean

Core'Character module

Types

No types are defined.

Functions

FromCodePoint

\(n number) string

ToCodePoint

\(s string) number

Core'List module

This module provides common list operations.

Types

No types are defined.

Functions

First

Get the first element in a list. If a list is empty, it returns a fallback value.

\(xs [any], fallback any) any

Last

Get the last element in a list. If a list is empty, it returns a fallback value.

\(xs [any], fallback any) any

ToNumbers

Convert a list of an any type to one of a number type skipping non-number types.

\(xs [any]) [number]

ToStrings

Convert a list of an any type to one of a string type skipping non-string types.

\(xs [any]) [string]

ToBooleans

Convert a list of an any type to one of a boolean type skipping non-boolean types.

\(xs [any]) [boolean]

Core'Number module

This module provides common number operations.

Types

No types are defined.

Functions

Absolute

Calculate an absolute value.

\(x number) number

Ceil

Calculate a ceil value.

\(x number) number

Epsilon

Machine epsilon

\() number

Exponential

Calculate an exponential of a number.

\(x number) number

Floor

Calculate a floor value.

\(x number) number

Fraction

Calculate a fraction value of a number.

\(x number) number

Infinity

Infinity

\() number

IsNan

Check if a number is NaN.

\(x number) boolean

Maximum

Calculate a maximum.

\(x number, y number) number

Minimum

Calculate a minimum.

\(x number, y number) number

Nan

NaN

\() number

Parse

Parse a number.

\(s string) number | error

Power

Calculate a power.

\(base number, exponent number) number

Range

Create a list of numbers from a minimum to a maximum.

\(minimum number, maximum number) [number]

Remainder

Calculate a remainder.

\(dividend number, divisor number) number

Round

Round a number.

\(x number) number

Sequence

Create a list of numbers from 1 to a maximum value.

\(maximum number) [number]

SquareRoot

Calculate a square root.

\(x number) number

String

Convert a number into its string representation.

\(x number) string

Sum

Sum up numbers.

\(xs [number]) number

Truncate

Return an integer value of a number.

\(x number) number

Core'String module

This module provides common string operations.

Types

No types are defined.

Functions

Concatenate

Concatenate strings.

\(strings [string]) string

Join

Join strings with a separator.

\(strings [string], separator string) string

StartsWith

Check if a string starts with a pattern.

\(s string, prefix string) boolean

Core'String'Byte module

This module provides operations for strings as byte arrays.

Types

No types are defined.

Functions

Length

Return a length of a string.

\(s string) number

Slice

Slice a string.

\(s string, start number, end number) string

Core'String'Byte'View module

This module provides views of strings as byte arrays. By using those views, you can apply operations to strings without copying them.

Types

View

A view of a string

type View {
  # ...
}

Functions

New

Create a view of a string.

\(s string) View

Viewee

Get an original string.

\(v View) string

Start

Get a start index of a view.

\(v View) number

End

Get an end index of a view.

\(v View) number

StartsWith

Check if a string starts with a pattern.

\(v View, s string) boolean

Length

Get a length of a view.

\(v View) number

Seek

Move a start index forward.

\(v View, n number) View

Slice

Slice a view.

\(v View, start number, end number) View

ToString

Convert a view into a string.

\(v View) string

Core'String'Utf8 module

This module provides operations for strings encoded in UTF-8.

Types

No types are defined.

Functions

Characters

Split a string into characters.

\(s string) [string]

Contains

Check if a string contains a pattern.

\(s string, pat string) boolean

Find

Find an index for a pattern in a string.

\(s string, pat string) number | none

StartsWith

Checks if a string starts with a pattern..

\(s string, pat string) boolean

EndsWith

Checks if a string ends with a pattern..

\(s string, pat string) boolean

Length

Return a length of a string.

\(s string) number

Replace

Replace a pattern in a string.

\(s string, pattern string, replacement string) string

Slice

Slice a string.

\(s string, start number, end number) string

Split

Split a string by a pattern.

\(s string, pat string) [string]

ToLowercase

Convert a string into lowercase.

\(s string) string

ToUppercase

Convert a string into uppercase.

\(s string) string

Trim

Trim leading and trailing spaces.

\(s string) string

TrimEnd

Trim trailing spaces.

\(s string) string

TrimEndMatches

Trim trailing patterns.

\(s string, pat string) string

TrimMatches

Trim leading and trailing patterns.

\(s string, pat string) string

TrimStart

Trim leading spaces.

\(s string) string

TrimStartMatches

Trim leading patterns.

\(s string, pat string) string