Changelog
All notable changes to the XPR language specification and runtimes.
v0.5.0
Math
- New functions:
sqrt(n),log(n),pow(x, y),random(),sign(n),trunc(n) - New constants:
PI,E
Type Predicates
isNumber(v),isString(v),isArray(v),isNull(v),isObject(v),isRegex(v)
Array Methods
sortBy(fn),take(n),drop(n),count(fn),sum(),avg(),compact()partition(fn),keyBy(fn),min(),max(),first(),last()
Other
fromEntries(pairs)— inverse of.entries()str.split(/regex/)— regex overload for string split- Rest parameters in arrow functions:
(...args) => expr,(a, ...rest) => expr
v0.4.0
Destructuring
- Object destructuring in
letbindings:let {name, age} = user; name - Array destructuring in
letbindings:let [first, ...rest] = items; rest - Destructuring in arrow function parameters:
users.map(({name}) => name) - Defaults, renaming, nested, and rest patterns supported
Regex
- Regex literals:
/pattern/flags— first-classregextype (7th type) - Regex methods:
/re/.test(str),str.match(/re/),str.replace(/re/, str) - Supported flags:
i,m,s
v0.3.0
Date/Time (epoch milliseconds, UTC only)
now(),parseDate(str, format?),formatDate(date, format)year(d),month(d),day(d),hour(d),minute(d),second(d),millisecond(d)dateAdd(date, amount, unit),dateDiff(date1, date2, unit)
Regex Functions
matches(str, pattern),match(str, pattern),matchAll(str, pattern),replacePattern(str, pattern, repl)- RE2 flavor. Inline flags via
(?i)etc.
Other
- Negative array indexing:
items[-1]returns last element - Spread in function call arguments:
fn(...args),fn(a, ...rest)
v0.2.0
Let Bindings
- Immutable scoped bindings:
let x = 1; x + 1 - Chained:
let x = 1; let y = x + 1; y - Arrow functions as values:
let f = (x) => x * 2; f(5)
Spread Operator
- Array spread:
[...arr1, ...arr2] - Object spread:
{...obj1, ...obj2}
New Array Methods
includes,indexOf,slice,join,concat,flat,unique,zip,chunk,groupBy
New String Methods
indexOf,repeat,trimStart,trimEnd,charAt,padStart,padEnd
New Object Methods
entries(),has(key)
New Global
range(end),range(start, end),range(start, end, step)
v0.1.0
Core
- Literals: numbers, strings, booleans, null, arrays, objects, template literals
- Arithmetic:
+,-,*,/,%,** - Comparison:
==,!=,<,>,<=,>= - Logic:
&&,||,!, ternarya ? b : c, nullish coalescing??
Access
- Dot and bracket notation:
user.name,user["name"],items[0] - Optional chaining:
user?.address?.city
Collections
- Arrow functions:
x => x * 2,(x, y) => x + y - Methods:
map,filter,reduce,find,some,every,flatMap,sort,reverse - Property:
.length
Strings
- Methods:
len,upper,lower,trim,startsWith,endsWith,contains,split,replace,slice
Math
round,floor,ceil,abs,min,max
Type
type(v),int(v),float(v),string(v),bool(v)
Object
keys(),values()
Pipe
|>operator:data |> filter(x => x.active) |> map(x => x.name)
Runtimes
- JavaScript/TypeScript:
@xpr-lang/xpr - Python:
xpr-lang - Go:
github.com/xpr-lang/xpr-go