generated from Green-Software-Foundation/if-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
37 lines (32 loc) · 1.04 KB
/
index.ts
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
import { PluginFactory } from '@grnsft/if-core/interfaces';
import { PluginParams, ConfigParams } from '@grnsft/if-core/types';
import { validateConfig, validateInput } from '../../validation';
/*
* Calculate bars of chocolate
*/
const barsOfChocolate = (carbon: number) => {
const gPerBar = 100;
return {
'bars-of-chocolate/dark': carbon / (1.67 * gPerBar),
'bars-of-chocolate/milk': carbon / (4.19 * gPerBar),
'bars-of-chocolate/white': carbon / (4.1 * gPerBar),
};
};
export const Chocolate = PluginFactory({
configValidation: (config: ConfigParams) => {
return validateConfig(config);
},
inputValidation: (input: PluginParams) => {
return validateInput(input);
},
implementation: async (inputs: PluginParams[], config: ConfigParams) => {
const inputAndConfig = Object.assign({}, inputs, config);
const units: number = inputAndConfig.units ?? 1;
const carbon = inputAndConfig.carbon * units;
return inputs.map(input => {
// logic
barsOfChocolate(carbon);
return input;
});
},
});