JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Skip to content
AI Turbo-George
Page d'accueil
Masterclass
George V1
Wiki
Source Externe
Contact
Politiques d'utilisation
George Beta
Configuration Système
Doc Explorer
More
Share
Explore
Formulas
Name:
Formulas
Formulas
Category
i
Coda Formula
i
Doc
JavaScript
Warning
Notes
Category
i
Coda Formula
i
Doc
JavaScript
Warning
Notes
Collections
8
Count(list...)
list.length
CountUnique(value...)
(new Set(value)).size
Find(needle, haystack)
haystack.indexOf(needle, startAt)
MaxBy(list, compareBy)
list.sort((a, b) =>
compareBy(a) > compareBy(b) ? 1 : -1)
[list.length + 1]
MinBy(list, compareBy)
list.sort((a, b) =>
compareBy(a) > compareBy(b) ? 1 : -1)
[0]
Slice(value, start)
value.slice(start, end)
End index non-inclusive.
Sort(dataset)
dataset.sort((a, b) =>
sortBy(a) > sortBy(b) ? 1 : -1)
JS sorts lexographically
Splice(value, start, deleteCount, insertValue...)
value.splice(start, deleteCount, insertValue)
To insert a list, use
...insertValue
Dates
32
Created(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
CurrentTimezone()
Not possible
Packs run on the server, and don’t have any information about the user looking at the doc.
Date(year, month, day)
new Date(year + "-" + month + "-" + day)
DateTime(year, month, day)
new Date(year + "-" + month + "-" + day)
DateTimeTruncate(dateTime, unit)
Needs library
DateToEpoch(date)
date.getTime()
Day(dateTime)
dateTime.getDate()
Time zone shifting
DocumentTimezone()
context.timezone
EndOfMonth(dateTime, monthOffset)
Needs library
EpochToDate(epochTime)
new Date(epochTime)
Hour(dateTime)
dateTime.getHours()
Time zone shifting
IsoWeekday(dateTime)
dateTime.getDay()
IsoWeekNumber(dateTime)
Needs library
Minute(dateTime)
dateTime.getMinutes()
Modified(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
Month(dateTime)
dateTime.getMonth()
Months start at 0.
MonthName(dateTime)
dateTime.toLocaleDateString("en", {
month: "long"
})
Time zone shifting
NetWorkingDays(startDate, endDate)
Needs library
Now()
new Date()
RelativeDate(dateTime, months)
dateTime = dateTime.setMonth(
dateTime.getMonth() + months)
Second(dateTime)
dateTime.getSeconds()
Time(hour, minute, second)
Needs library
JavaScript doesn’t have a native way to represent a pure time value.
TimeValue(time)
Needs library
JavaScript doesn’t have a native way to represent a pure time value.
ToDate(text)
Date.parse(text)
ToDateTime(datetime)
Date.parse(text)
Today()
let today = new Date();
today.setHours(0, 0, 0, 0);
ToTime(value)
Needs library
JavaScript doesn’t have a native way to represent a pure time value.
Weekday(dateTime)
dateTime.getDay()
WeekdayName(dateTime)
dateTime.toLocaleDateString("en", {
weekday: "long"
})
WeekNumber(dateTime)
Needs library
Workday(startDate, numWorkingDays)
Needs library
Year(dateTime)
dateTime.getFullYear()
Duration
9
Days(days)
Needs library
Duration()
Needs library
Hours(hours)
Needs library
Minutes(minutes)
Needs library
Seconds(seconds)
Needs library
ToDays(duration)
Needs library
ToHours(duration)
Needs library
ToMinutes(duration)
Needs library
ToSeconds(duration)
Needs library
Filters
7
AverageIf(list, expression)
let filtered = list.filter(num => expression);
let result = filtered.reduce((sum, num) => sum + num, 0) / filtered.length;
CountIf(list, expression)
list.filter(num => expression).length
Filter(list, expression)
list.filter(currentValue => expression)
IsFromTable(row, table)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
Lookup(table, column, match value)
Not possible
You can’t pass entire rows or tables into a Pack, so there is no equivalent.
Matches(value, control)
Too complex
The logic in the
Matches()
formula is complex, and there isn’t a simple equivalent in JavaScript.
SumIf(list, expression)
list.filter(num => expression)
.reduce((result, num) => result + num)
Logical
9
And(value...)
value1 && value2
False()
false
If(condition, ifTrue, ifFalse)
let result;
if (condition) {
result = ifTrue;
} else {
result = ifFalse;
}
IfBlank(value, ifBlank)
let result = value;
if (result == undefined) {
result = ifBlank;
}
Not(value)
!value
Or(value...)
value1 || value2 || value3
Switch(expression, value, result, arg...)
let result;
switch (expression) {
case value1:
result = result1;
break;
case value2:
result = result2;
break;
default:
result = defaultValue;
}
SwitchIf(condition, ifTrue, arg...)
let result;
if (condition1) {
result = ifTrue1;
} else if (condition2) {
result = ifTrue2;
} else {
result = defaultValue;
}
True()
true
Info
9
IsBlank(value)
value == undefined
IsDate(value)
value instanceof Date
IsLogical(value)
typeof value == "boolean"
IsNotBlank(value)
value != undefined
IsNotText(value)
typeof value != "string"
IsNumber(value)
typeof value == "number"
IsText(value)
typeof value == "string"
ToNumber(value)
parseFloat(value, base)
ToText(value)
value.toString()
Math
39
AbsoluteValue(number)
Math.abs(number)
Average(value...)
list.reduce((sum, num) => sum + num, 0) / list.length
BinomialCoefficient(n, k)
Needs library
Ceiling(value)
Math.ceil(value)
Even(value)
value % 2 == 0 ? value : value + 1
Exponent(value)
Math.exp(value)
Factorial(value)
Needs library
Floor(value)
Math.floor(value)
IsEven(value)
value % 2 == 0
IsOdd(value)
value % 2 == 1
Ln(number)
Math.log(number)
Log(number, base)
Math.log(number) / Math.log(base)
Log10(number)
Math.log10(number)
Max(value...)
Math.max(value1, value2)
Math.max(...list)
Median(value...)
Needs library
Min(value...)
Math.min(value1, value2)
Math.min(...list)
Mode(value...)
Needs library
Odd(value)
value % 2 == 1 ? value : value + 1
Percentile(dataset, percentile)
Needs library
PercentileRank(dataset, value)
Needs library
Pi()
Math.PI
Power(number, exponent)
Math.pow(number, exponent)
Product(value...)
value1 * value2
Quotient(dividend, divisor)
dividend / divisor
Random()
Math.random()
RandomInteger(low, high)
Math.floor(Math.random() * (high - low + 1) + low)
Rank(value, dataset)
Needs library
Remainder(dividend, divisor)
dividend % divisor
Round(number)
Math.round(number)
RoundDown(number)
Math.floor(number)
RoundTo(value, factor)
Needs library
RoundUp(number)
Math.ceil(number)
Sign(number)
number / Math.abs(number)
SquareRoot(number)
Math.sqrt(number)
StandardDeviation(value...)
Needs library
StandardDeviationPopulation(value...)
Needs library
Sum(value...)
value1 + value2
SumProduct(list1, list2)
let result = 0;
for (let i = 0; i < list1.length; i++) {
result += list1[i] * list2[i];
}
Truncate(number)
Needs library
Misc
2
ObjectLink(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
ParseCSV(csvString)
Needs library
Object
1
ParseJSON(jsonString)
JSON.parse(jsonString).path.path
Instead of using a path string, “dot” into the parsed object.
People
4
CreatedBy(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
IsSignedIn()
Not possible
Packs run on the server, and don’t have any information about the user looking at the doc.
ModifiedBy(object)
Not possible
You can’t pass entire rows into a Pack, so there is no equivalent.
User()
Not possible
Packs run on the server, and don’t have any information about the user looking at the doc.
Relational
2
RowId(row)
Not possible
Packs run on the server, and don’t have any information about the user looking at the doc.
WithName(value, name, expression)
let name = value;
// Do expression
RichText
3
BulletedList(value...)
Not possible
JavaScript doesn’t have a concept of rich text. You can however return
Markdown
or
HTML
.
IndentBy(text, levels)
Not possible
JavaScript doesn’t have a concept of rich text. You can however return
Markdown
or
HTML
.
NumberedList(value...)
Not possible
JavaScript doesn’t have a concept of rich text. You can however return
Markdown
or
HTML
.
Shape
6
ClipCircle(image)
Not possible
Embed(url)
Not possible
Not possible using pure JavaScript, but can be done in the
Pack SDK
.
Hyperlink(url)
Not possible
Not possible using pure JavaScript, but can be done in the Pack SDK.
HyperlinkCard(url)
Not possible
Not possible using pure JavaScript, but can be done in the Pack SDK.
Image(url)
Not possible
Not possible using pure JavaScript, but can be done in the
Pack SDK
.
Rectangle(width)
Not possible
Spatial
2
Distance(location1, location2)
Needs library
Location(latitude, longitude)
Needs library
String
28
Character(charNumber)
String.fromCharCode(charNumber)
Concatenate(text...)
[text1, text2, text3].join("")
ContainsText(text, searchText)
text.includes(searchText)
To ignore case, apply
.toLowerCase()
to both strings first.
DecodeFromBase64(base64Text)
Buffer.from(base64Text, "base64").toString()
EncodeAsBase64(text)
Buffer.from(text).toString("base64")
EncodeForUrl(text)
encodeURIComponent(text)
EndsWith(text, suffix)
text.endsWith(suffix)
Format(template, text...)
`Hi ${text1}, my ${text2} is ${text3}`
This is an example of a
template literal string
in JavaScript.
Join(delimiter, text...)
text.join(delimeter)
Left(text, numberOfCharacters)
text.substring(0, numberOfCharacters)
LeftPad(text, targetLength)
text.padStart(targetLength, padString)
Length(text)
text.length
LineBreak()
"\n"
Lower(text)
text.toLoewerCase()
Middle(text, start, numberOfCharacters)
text.substring(start, start + numberOfCharacters)
RegexMatch(text, regularExpression)
text.match(regularExpression)
Regular expressions aren’t strings.
RegexReplace(text, regularExpression, replacementText)
text.replace(regularExpression, replacementText)
Need to use
/g
modifier to replace them all.
Repeat(text, repetitions)
text.repeat(repetitions)
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).
Right(text, numberOfCharacters)
text.substring(text.length - numberOfCharacters)
RightPad(text, targetLength)
text.padEnd(targetLength, padText)
Split(text, delimiter)
text.split(delimiter)
StartsWith(text, prefix)
text.startsWith(prefix)
Substitute(text, searchFor, replacementText)
text.replace(searchFor, replacementText)
ToByteSize(byteCount)
Needs library
ToHexadecimal(decimalNumber)
decimalNumber.toString(16)
Trim(text)
text.trim()
Upper(text)
text.toUpperCase()
Lists
20
All(list)
list.every(expression)
Any(list)
list.some(expression)
Contains(value, search...)
search.some(item => value.includes(item))
The code assumes that
search
is an array of values.
ContainsAll(value, search...)
search.every(item => value.includes(item))
ContainsOnly(value, search...)
value.length == search.length && search.every(item => value.includes(item))
CountAll(list)
Duplicates(value...)
[...new Set(value.filter((item, index, arr) => arr.indexOf(item) !== index))]
First(list)
list[0]
Arrays in JavaScript start at index zero (0).
ForEach(list, formula)
list.map(item => {
// Apply the mapping to item.
return item;
})
Same as
Object not found!
FormulaMap(list, formula)
list.map(item => {
// Apply the mapping to item.
return item;
})
In(search, value...)
value.includes(search)
Last(list)
list[list.length - 1]
Arrays in JavaScript start at index zero (0).
List(value...)
[value1, value2, value3]
ListCombine(value...)
value1.concat(value2, value3)
Nth(list, position)
list[position]
Arrays in JavaScript start at index zero (0).
RandomItem(list)
list[Math.floor(Math.random() * list.length)]
RandomSample(list, count)
Needs library
ReverseList(list)
list.reverse()
Sequence(start, end)
let result = [];
for (let i = start; i <= end; i += by) {
result.push(i);
}
Unique(value...)
Array.from(new Set(value))
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
Ctrl
P
) instead.