PluginProbe
Extendify / 0.10.0
Extendify v0.10.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Onboarding / lib / util.js

util.js in Extendify 0.10.0, at src/Onboarding/lib/util.js

38 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /** Takes each possible code section and filters out undefined */
2 export const findTheCode = (item) =>
3 [item?.template?.code, item?.template?.code2].filter(Boolean).join('')
4
5 /** Removes any hash or qs values from URL - Airtable adds timestamps */
6 export const stripUrlParams = (url) => url?.[0]?.url?.split(/[?#]/)?.[0]
7
8 /** Lowers the quality of images */
9 export const lowerImageQuality = (html) => {
10 return html.replace(/\w+:\/\/\S*(w=(\d*))&\w+\S*"/g, (url, w, width) =>
11 // Could lower the width here if needed
12 url.replace(w, 'w=' + Math.floor(Number(width)) + '&q=10'),
13 )
14 }
15
16 /** Capitalize first letter of a string */
17 export const capitalize = (str) =>
18 str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()
19
20 export const runAtLeastFor = async (functionPromise, time, options) => {
21 if (options.dryRun) {
22 return new Promise((resolve) => setTimeout(resolve, time))
23 }
24 const start = Date.now()
25 try {
26 return await Promise.all([
27 await functionPromise(),
28 new Promise((resolve) => setTimeout(resolve, time)),
29 ])
30 } catch (error) {
31 console.error(error)
32 return await new Promise((resolve) =>
33 // Check at least min milliseconds have passed
34 setTimeout(resolve, Math.max(0, time - (Date.now() - start))),
35 )
36 }
37 }
38