Restorm 裡的每一個運算式都是一份 Handlebars 樣板:URL、標頭、參數、請求內文、
Expression 類型的環境變數、情境欄位,以及 Transform template 動作的樣板。
本頁收錄 116 個具名 helper 與 22 個動態變數。
在支援的欄位中,Ctrl+Space 會觸發自動完成。
| helper | 簽章 | 效果 |
|---|
eq | {{eq a b}} | a === b |
ne | {{ne a b}} | a !== b |
neq | {{neq a b}} | ne 的別名 |
lt | {{lt a b}} | a < b(數值比較) |
lte | {{lte a b}} | a <= b |
gt | {{gt a b}} | a > b |
gte | {{gte a b}} | a >= b |
and | {{#and a b}}…{{else}}…{{/and}} | 區塊:所有引數皆為真 |
or | {{#or a b}}…{{/or}} | 區塊:至少一個引數為真 |
not | {{not value}} | 取相反的布林值 |
ifEquals | {{#ifEquals a b}}…{{else}}…{{/ifEquals}} | 區塊,嚴格相等 |
is | {{#is a b}}…{{/is}} | 區塊,以字串比較是否相同 |
isnt | {{#isnt a b}}…{{/isnt}} | 區塊,以字串比較是否不同 |
default | {{default value fallback}} | value 已定義時用它,否則用 fallback |
compare | {{#compare a "op" b}}…{{/compare}} | 區塊;op ∈ == === != !== < <= > >= |
{{default region "eu-west-1"}}
{{#compare quantite ">" 100}}gros{{else}}normal{{/compare}}
| helper | 簽章 | 範例 → 結果 |
|---|
lowercase | {{lowercase s}} | Bonjour → bonjour |
uppercase | {{uppercase s}} | Bonjour → BONJOUR |
capitalize | {{capitalize s}} | bonjour tout → Bonjour tout |
capitalizeAll | {{capitalizeAll s}} | bonjour tout → Bonjour Tout |
titleize | {{titleize s}} | 與 capitalizeAll 相同 |
camelcase | {{camelcase s}} | mon-champ → monChamp |
pascalcase | {{pascalcase s}} | mon-champ → MonChamp |
snakecase | {{snakecase s}} | monChamp → mon_champ |
snakeCase | {{snakeCase s}} | snakecase 的別名 |
dashcase | {{dashcase s}} | monChamp → mon-champ |
dotcase | {{dotcase s}} | monChamp → mon.champ |
pathcase | {{pathcase s}} | monChamp → mon/champ |
sentencecase | {{sentencecase s}} | BONJOUR TOUT → Bonjour tout |
slugify | {{slugify s}} | Mon Beau Titre ! → mon-beau-titre |
trim | {{trim s}} | 移除兩端的空白字元 |
trimLeft | {{trimLeft s}} | 只移除開頭 |
trimRight | {{trimRight s}} | 只移除結尾 |
replace | {{replace s search replacement}} | 取代所有出現的位置(字面比對,不用正規表示式) |
split | {{split s separator}} | 分割成陣列;分隔符號預設為 , |
truncate | {{truncate s length suffix}} | 長度預設 50,後綴預設 ... |
ellipsis | {{ellipsis s length}} | 與 truncate 相同,但用 … |
append | {{append s suffix}} | 接在結尾 |
prepend | {{prepend s prefix}} | 接在開頭 |
reverse | {{reverse value}} | 反轉字串或陣列 |
startsWith | {{#startsWith s prefix}}…{{/startsWith}} | 區塊 |
endsWith | {{#endsWith s suffix}}…{{/endsWith}} | 區塊 |
contains | {{#contains sOrArray value}}…{{/contains}} | 區塊 |
match | {{match s pattern}} | 所有相符的結果,或 null |
test | {{#test s pattern}}…{{/test}} | 區塊,正規表示式測試 |
padStart | {{padStart s length char}} | 在開頭填補 |
padEnd | {{padEnd s length char}} | 在結尾填補 |
repeat | {{repeat s n}} | 重複 |
substring | {{substring s start end}} | 擷取一段 |
indexOf | {{indexOf s search}} | 位置,找不到時為 -1 |
count | {{count s substring}} | 出現的次數 |
newLineToBr | {{newLineToBr s}} | \n → <br> |
stripTags | {{stripTags s}} | 移除 <…> 標籤 |
{{padStart numeroCommande 8 "0"}}
{{truncate description 120}}
| helper | 簽章 | 效果 |
|---|
add | {{add a b}} | 相加 |
subtract | {{subtract a b}} | 相減 |
multiply | {{multiply a b}} | 相乘 |
divide | {{divide a b}} | 相除 |
modulo | {{modulo a b}} | 餘數 |
abs | {{abs a}} | 絕對值 |
ceil | {{ceil a}} | 無條件進位 |
floor | {{floor a}} | 無條件捨去 |
round | {{round a}} | 四捨五入 |
pow | {{pow base exponent}} | 次方 |
sqrt | {{sqrt a}} | 平方根 |
random | {{random min max}} | 隨機整數,上下界都包含 |
sum | {{sum array}} | 陣列各值的總和 |
avg | {{avg array}} | 平均值 |
min | {{min a b c …}} | 最小值,可變引數 |
max | {{max a b c …}} | 最大值,可變引數 |
toFixed | {{toFixed number decimals}} | 固定 N 位小數的字串 |
toInt | {{toInt number}} | 整數(十進位),失敗時回退為 0 |
toFloat | {{toFloat number}} | 浮點數,失敗時回退為 0 |
{"montantTTC": {{toFixed (multiply montantHT 1.2) 2}}}
| helper | 簽章 | 效果 |
|---|
first | {{first array n}} | 第一個元素,或前 n 個 |
last | {{last array n}} | 最後一個元素,或最後 n 個 |
length | {{length value}} | 陣列或字串的長度,或物件的鍵數 |
join | {{join array separator}} | 分隔符號預設為 , |
sort | {{sort array}} | 排序後的副本 |
unique | {{unique array}} | 去除重複值 |
after | {{after array n}} | 索引 n 之後的全部元素 |
before | {{before array n}} | 索引 n 之前的全部元素 |
slice | {{slice array start end}} | 取一段切片 |
concat | {{concat a b …}} | 串接,並攤平一層 |
flatten | {{flatten array}} | 攤平一層 |
pluck | {{pluck array property}} | 從每個元素中擷取一個屬性 |
itemAt | {{itemAt array index}} | 該索引位置的元素;負索引從尾端起算 |
inArray | {{#inArray array value}}…{{/inArray}} | 區塊 |
isArray | {{isArray value}} | 布林值 |
isEmpty | {{#isEmpty value}}…{{/isEmpty}} | 區塊 |
some | {{#some array prop value}}…{{/some}} | 區塊:至少有一個元素符合 |
every | {{#every array prop value}}…{{/every}} | 區塊:所有元素都符合 |
{{join (pluck articles "reference") ","}}
| helper | 簽章 | 效果 |
|---|
JSONstringify | {{JSONstringify obj}} | 序列化,縮排 2 |
JSONparse | {{JSONparse string}} | 解析;失敗時傳回 {} |
get | {{get obj "a.b.c"}} | 以點號路徑讀取 |
isObject | {{isObject value}} | 布林值(非 null、非陣列) |
typeOf | {{typeOf value}} | null、array,或 JavaScript 的型別 |
keys | {{keys obj}} | 所有鍵 |
values | {{values obj}} | 所有值 |
entries | {{entries obj}} | 所有 [key, value] 配對 |
hasOwn | {{#hasOwn obj "key"}}…{{/hasOwn}} | 區塊 |
pick | {{pick obj "k1" "k2"}} | 只保留這些鍵 |
omit | {{omit obj "k1"}} | 移除這些鍵 |
merge | {{merge o1 o2}} | 淺層合併 |
{{get reponse "data.client.identifiant"}}
| helper | 簽章 | 效果 |
|---|
encodeURI | {{encodeURI s}} | 對 URL 的一個組成部分編碼 |
decodeURI | {{decodeURI s}} | 解碼 |
urlParse | {{urlParse url}} | { href, origin, protocol, host, hostname, port, pathname, search, hash },或 null |
stripQuerystring | {{stripQuerystring url}} | 移除查詢字串 |
stripProtocol | {{stripProtocol url}} | 移除通訊協定 |
{{baseUrl}}/recherche?q={{encodeURI termeRecherche}}
| helper | 簽章 | 效果 |
|---|
year | {{year}} | 目前的年份 |
now | {{now}} | 目前時刻,ISO 格式 |
timestamp | {{timestamp}} | 目前時刻,單位為毫秒 |
formatDate | {{formatDate date "YYYY-MM-DD"}} | 格式化 |
另外也請注意,{{timestamp}} 的單位是毫秒,而 {{$timestamp}}
(下方的 Postman 相容變數)的單位是秒。
| helper | 簽章 | 效果 |
|---|
coalesce | {{coalesce a b c}} | 第一個非 null 的值 |
uuid | {{uuid}} | 一個 UUID v4 |
noop | {{#noop}}…{{/noop}} | 不產生任何效果的區塊 |
raw | {{{{raw}}}}…{{{{/raw}}}} | 不解讀其中的內容 |
times | {{#times n}}…{{/times}} | 重複該區塊;可以使用 @index、@first、@last |
range | {{range start end step}} | 數字陣列,不含結束值 |
當您刻意要送出雙大括號時 — 例如要測試一個自己會解讀它們的服務 —
raw 這個 helper 正是您需要的東西。
不帶引數,每次求值都會得到不同的值。
| 變數 | 傳回 |
|---|
{{$guid}} | 一個 UUID v4 |
{{$randomUUID}} | 一個 UUID v4 |
{{$timestamp}} | 目前時刻,單位為秒 |
{{$isoTimestamp}} | 目前時刻,ISO 格式 |
{{$randomInt}} | 0 到 1000 之間的整數 |
{{$randomAlphaNumeric}} | 8 個英數字元 |
{{$randomBoolean}} | true 或 false |
{{$randomFirstName}} | 一個名字 |
{{$randomLastName}} | 一個姓氏 |
{{$randomFullName}} | 一個完整姓名 |
{{$randomUserName}} | firstname.lastname<0-99> |
{{$randomEmail}} | 一個電子郵件地址 |
{{$randomColor}} | 一個顏色名稱 |
{{$randomWord}} | 一個單字 |
{{$randomWords}} | 三個單字 |
{{$randomCompanyName}} | 一個公司名稱 |
{{$randomCity}} | 一座城市 |
{{$randomCountry}} | 一個國家 |
{{$randomPhoneNumber}} | 一個電話號碼 |
{{$randomIP}} | 一個 IP 位址 |
{{$randomIPV4}} | 一個 IPv4 位址 |
{{$randomPrice}} | 一個帶兩位小數的價格 |
"correlationId": "{{$guid}}",
"client": { "nom": "{{$randomFullName}}", "email": "{{$randomEmail}}" },
"emisLe": "{{$isoTimestamp}}"
沒有用來讀取變數的 helper:變數本身就直接位於上下文中。要寫
{{baseUrl}},而不是 {{env "baseUrl"}}。
請參閱變數與環境。