-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
38 lines (34 loc) · 997 Bytes
/
code.js
File metadata and controls
38 lines (34 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import _ from 'lodash';
import { format, addDays } from 'date-fns';
import ms from 'ms';
import { v4 as uuidv4 } from 'uuid';
import equal from 'fast-deep-equal';
/**
* Main run function for the Glide JS code sandbox
* @param {Object} input - JSON object input
* @returns {Object} JSON object output
*/
export async function run(input) {
// Example: Process the input and return transformed data
const id = uuidv4();
const timestamp = new Date();
const futureDate = addDays(timestamp, 7);
// Use lodash to process input
const processedData = _.mapValues(input, (value) => {
if (typeof value === 'string') {
return _.upperCase(value);
}
return value;
});
// Check if input has changed
const hasChanged = !equal(input, processedData);
return {
id,
timestamp: format(timestamp, 'yyyy-MM-dd HH:mm:ss'),
futureDate: format(futureDate, 'yyyy-MM-dd'),
oneWeek: ms('7 days'),
originalInput: input,
processedData,
hasChanged
};
}