Skip to content
Coda Formulas to JavaScript
Share
Explore

icon picker
Coda Formulas to JavaScript

Search Formula Name:
Formulas
0
Not synced yet
Category
Coda Formula
Formula Documentation
JavaScript
Warning
Notes
Collections
8
Count(list...)
list.length

Open
CountUnique(value...)
(new Set(value)).size

Open
Find(needle, haystack)
haystack.indexOf(needle, startAt)

Open
MaxBy(list, compareBy)
list.sort((a, b) => compareBy(a) > compareBy(b) ? 1 : -1) [list.length + 1]

Open
MinBy(list, compareBy)
list.sort((a, b) => compareBy(a) > compareBy(b) ? 1 : -1) [0]

Open
Slice(value, start)
value.slice(start, end)
End index non-inclusive.
Open
Sort(dataset)
dataset.sort((a, b) => sortBy(a) > sortBy(b) ? 1 : -1)
JS sorts lexographically
Open
Splice(value, start, deleteCount, insertValue...)
value.splice(start, deleteCount, insertValue)
To insert a list, use ...insertValue
Open
Dates
32
Created(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
Open
CurrentTimezone()
Not possible
Packs run on the server, and don’t have any information about the user looking at the doc.
Open
Date(year, month, day)
new Date(year + "-" + month + "-" + day)

Open
DateTime(year, month, day)
new Date(year + "-" + month + "-" + day)

Open
DateTimeTruncate(dateTime, unit)
Needs library

Open
DateToEpoch(date)
date.getTime()

Open
Day(dateTime)
dateTime.getDate()
Time zone shifting
Open
DocumentTimezone()
context.timezone

Open
EndOfMonth(dateTime, monthOffset)
Needs library

Open
EpochToDate(epochTime)
new Date(epochTime)

Open
Hour(dateTime)
dateTime.getHours()
Time zone shifting
Open
IsoWeekday(dateTime)
dateTime.getDay()

Open
IsoWeekNumber(dateTime)
Needs library

Open
Minute(dateTime)
dateTime.getMinutes()

Open
Modified(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
Open
Month(dateTime)
dateTime.getMonth()
Months start at 0.
Open
MonthName(dateTime)
dateTime.toLocaleDateString("en", { month: "long"})
Time zone shifting
Open
NetWorkingDays(startDate, endDate)
Needs library

Open
Now()
new Date()

Open
RelativeDate(dateTime, months)
dateTime = dateTime.setMonth( dateTime.getMonth() + months)

Open
Second(dateTime)
dateTime.getSeconds()

Open
Time(hour, minute, second)
Needs library
JavaScript doesn’t have a native way to represent a pure time value.
Open
TimeValue(time)
Needs library
JavaScript doesn’t have a native way to represent a pure time value.
Open
ToDate(text)
Date.parse(text)

Open
ToDateTime(datetime)
Date.parse(text)

Open
Today()
let today = new Date();today.setHours(0, 0, 0, 0);

Open
ToTime(value)
Needs library
JavaScript doesn’t have a native way to represent a pure time value.
Open
Weekday(dateTime)
dateTime.getDay()

Open
WeekdayName(dateTime)
dateTime.toLocaleDateString("en", { weekday: "long"})

Open
WeekNumber(dateTime)
Needs library

Open
Workday(startDate, numWorkingDays)
Needs library

Open
Year(dateTime)
dateTime.getFullYear()

Open
Duration
9
Days(days)
Needs library

Open
Duration()
Needs library

Open
Hours(hours)
Needs library

Open
Minutes(minutes)
Needs library

Open
Seconds(seconds)
Needs library

Open
ToDays(duration)
Needs library

Open
ToHours(duration)
Needs library

Open
ToMinutes(duration)
Needs library

Open
ToSeconds(duration)
Needs library

Open
Filters
7
AverageIf(list, expression)
let filtered = list.filter(num => expression);let result = filtered.reduce((sum, num) => sum + num, 0) / filtered.length;

Open
CountIf(list, expression)
list.filter(num => expression).length

Open
Filter(list, expression)
list.filter(currentValue => expression)

Open
IsFromTable(row, table)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
Open
Lookup(table, column, match value)
Not possible
You can’t pass entire rows or tables into a Pack, so there is no equivalent.
Open
Matches(value, control)
Too complex
The logic in the Matches() formula is complex, and there isn’t a simple equivalent in JavaScript.
Open
SumIf(list, expression)
list.filter(num => expression) .reduce((result, num) => result + num)

Open
Logical
9
And(value...)
value1 && value2

Open
False()
false

Open
If(condition, ifTrue, ifFalse)
let result;if (condition) { result = ifTrue;} else { result = ifFalse;}

Open
IfBlank(value, ifBlank)
let result = value;if (result == undefined) { result = ifBlank;}

Open
Not(value)
!value

Open
Or(value...)
value1 || value2 || value3

Open
Switch(expression, value, result, arg...)
let result;switch (expression) { case value1: result = result1; break; case value2: result = result2; break; default: result = defaultValue;}

Open
SwitchIf(condition, ifTrue, arg...)
let result;if (condition1) { result = ifTrue1;} else if (condition2) { result = ifTrue2;} else { result = defaultValue;}

Open
True()
true

Open
Info
9
IsBlank(value)
value == undefined

Open
IsDate(value)
value instanceof Date

Open
IsLogical(value)
typeof value == "boolean"

Open
IsNotBlank(value)
value != undefined

Open
IsNotText(value)
typeof value != "string"

Open
IsNumber(value)
typeof value == "number"

Open
IsText(value)
typeof value == "string"

Open
ToNumber(value)
parseFloat(value, base)

Open
ToText(value)
value.toString()

Open
Math
39
AbsoluteValue(number)
Math.abs(number)

Open
Average(value...)
list.reduce((sum, num) => sum + num, 0) / list.length

Open
BinomialCoefficient(n, k)
Needs library

Open
Ceiling(value)
Math.ceil(value)

Open
Even(value)
value % 2 == 0 ? value : value + 1

Open
Exponent(value)
Math.exp(value)

Open
Factorial(value)
Needs library

Open
Floor(value)
Math.floor(value)

Open
IsEven(value)
value % 2 == 0

Open
IsOdd(value)
value % 2 == 1

Open
Ln(number)
Math.log(number)

Open
Log(number, base)
Math.log(number) / Math.log(base)

Open
Log10(number)
Math.log10(number)

Open
Max(value...)
Math.max(value1, value2)Math.max(...list)

Open
Median(value...)
Needs library

Open
Min(value...)
Math.min(value1, value2)Math.min(...list)

Open
Mode(value...)
Needs library

Open
Odd(value)
value % 2 == 1 ? value : value + 1

Open
Percentile(dataset, percentile)
Needs library

Open
PercentileRank(dataset, value)
Needs library

Open
Pi()
Math.PI

Open
Power(number, exponent)
Math.pow(number, exponent)

Open
Product(value...)
value1 * value2

Open
Quotient(dividend, divisor)
dividend / divisor

Open
Random()
Math.random()

Open
RandomInteger(low, high)
Math.floor(Math.random() * (high - low + 1) + low)

Open
Rank(value, dataset)
Needs library

Open
Remainder(dividend, divisor)
dividend % divisor

Open
Round(number)
Math.round(number)

Open
RoundDown(number)
Math.floor(number)

Open
RoundTo(value, factor)
Needs library

Open
RoundUp(number)
Math.ceil(number)

Open
Sign(number)
number / Math.abs(number)

Open
SquareRoot(number)
Math.sqrt(number)

Open
StandardDeviation(value...)
Needs library

Open
StandardDeviationPopulation(value...)
Needs library

Open
Sum(value...)
value1 + value2

Open
SumProduct(list1, list2)
let result = 0;for (let i = 0; i < list1.length; i++) { result += list1[i] * list2[i];}

Open
Truncate(number)
Needs library

Open
Misc
2
ObjectLink(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
Open
ParseCSV(csvString)
Needs library

Open
Object
1
ParseJSON(jsonString)
JSON.parse(jsonString).path.path
Instead of using a path string, “dot” into the parsed object.
Open
People
4
CreatedBy(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
Open
IsSignedIn()
Not possible
Packs run on the server, and don’t have any information about the user looking at the doc.
Open
ModifiedBy(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
Open
User()
Not possible
Packs run on the server, and don’t have any information about the user looking at the doc.
Open
Relational
2
RowId(row)
Not possible
Packs run on the server, and don’t have any information about the user looking at the doc.
Open
WithName(value, name, expression)
let name = value;// Do expression

Open
RichText
3
BulletedList(value...)
Not possible
JavaScript doesn’t have a concept of rich text. You can however return or
.
Open
IndentBy(text, levels)
Not possible
JavaScript doesn’t have a concept of rich text. You can however return or
.
Open
NumberedList(value...)
Not possible
JavaScript doesn’t have a concept of rich text. You can however return or
.
Open
Shape
6
ClipCircle(image)
Not possible

Open
Embed(url)
Not possible
Not possible using pure JavaScript, but can be done in the .
Open
Hyperlink(url)
Not possible
Not possible using pure JavaScript, but can be done in the Pack SDK.
Open
HyperlinkCard(url)
Not possible
Not possible using pure JavaScript, but can be done in the Pack SDK.
Open
Image(url)
Not possible
Not possible using pure JavaScript, but can be done in the .
Open
Rectangle(width)
Not possible

Open
Spatial
2
Distance(location1, location2)
Needs library

Open
Location(latitude, longitude)
Needs library

Open
String
28
Character(charNumber)
String.fromCharCode(charNumber)

Open
Concatenate(text...)
[text1, text2, text3].join("")

Open
ContainsText(text, searchText)
text.includes(searchText)
To ignore case, apply .toLowerCase() to both strings first.
Open
DecodeFromBase64(base64Text)
Buffer.from(base64Text, "base64").toString()

Open
EncodeAsBase64(text)
Buffer.from(text).toString("base64")

Open
EncodeForUrl(text)
encodeURIComponent(text)

Open
EndsWith(text, suffix)
text.endsWith(suffix)

Open
Format(template, text...)
`Hi ${text1}, my ${text2} is ${text3}`
This is an example of a in JavaScript.
Open
Join(delimiter, text...)
text.join(delimeter)

Open
Left(text, numberOfCharacters)
text.substring(0, numberOfCharacters)

Open
LeftPad(text, targetLength)
text.padStart(targetLength, padString)

Open
Length(text)
text.length

Open
LineBreak()
"\n"

Open
Lower(text)
text.toLoewerCase()

Open
Middle(text, start, numberOfCharacters)
text.substring(start, start + numberOfCharacters)

Open
RegexMatch(text, regularExpression)
text.match(regularExpression)
Regular expressions aren’t strings.
Open
RegexReplace(text, regularExpression, replacementText)
text.replace(regularExpression, replacementText)
Need to use /g modifier to replace them all.
Open
Repeat(text, repetitions)
text.repeat(repetitions)

Open
Replace(text, start, numberOfCharacters, replacementText)
let chars = text.split("");chars.splice(start, numberOfCharacters, replacementText);text = chars.join("");
Remember that JavaScript indices start at zero (0).
Open
Right(text, numberOfCharacters)
text.substring(text.length - numberOfCharacters)

Open
RightPad(text, targetLength)
text.padEnd(targetLength, padText)

Open
Split(text, delimiter)
text.split(delimiter)

Open
StartsWith(text, prefix)
text.startsWith(prefix)

Open
Substitute(text, searchFor, replacementText)
text.replace(searchFor, replacementText)

Open
ToByteSize(byteCount)
Needs library

Open
ToHexadecimal(decimalNumber)
decimalNumber.toString(16)

Open
Trim(text)
text.trim()

Open
Upper(text)
text.toUpperCase()

Open
Lists
20
All(list)
list.every(expression)

Open
Any(list)
list.some(expression)

Open
Contains(value, search...)
search.some(item => value.includes(item))
The code assumes that search is an array of values.

Open
ContainsAll(value, search...)
search.every(item => value.includes(item))

Open
ContainsOnly(value, search...)
value.length == search.length && search.every(item => value.includes(item))

Open
CountAll(list)
list.length

Open
Duplicates(value...)
[...new Set(value.filter((item, index, arr) => arr.indexOf(item) !== index))]

Open
First(list)
list[0]
Arrays in JavaScript start at index zero (0).
Open
ForEach(list, formula)
list.map(item => { // Apply the mapping to item. return item;})
Same as
@FormulaMap(list, formula)
Open
FormulaMap(list, formula)
list.map(item => { // Apply the mapping to item.