-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
94 lines (83 loc) · 2.17 KB
/
index.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use strict';
const {clipboard} = require('electron');
const moment = require('moment');
const sanitize = require('sanitize-filename');
const {
uniqueNamesGenerator,
...dictionaries
} = require('unique-names-generator');
const template = require('string-template');
const dictionaryMap = new Map([
['color', 'colors'],
['adjective', 'adjectives'],
['animal', 'animals'],
['country', 'countries'],
['name', 'names'],
['starWars', 'starWars']
]);
const config = {
nameTemplate: {
title: 'Template',
description: 'Used to generate the file name. For available all options read here: https://github.com/karaggeorge/kap-recording-name#templating',
type: 'string',
default: '{date} at {time} - {color} {animal}',
required: true
},
dateFormat: {
title: 'Date Format',
description: 'Moment.js format for the {date} parameter.',
type: 'string',
default: 'YYYY-MM-DD',
required: true
},
timeFormat: {
title: 'Time Format',
description: 'Moment.js format for the {time} parameter.',
type: 'string',
default: 'H.mm.ss',
required: true
},
randomWordStyle: {
title: 'Random Word Style',
description: 'Style to use for the generated random words.',
type: 'string',
enum: [
'lowerCase',
'upperCase',
'capital'
],
required: true,
default: 'capital'
}
};
const willStartRecording = ({state}) => {
state.clipboardContent = clipboard.readText();
};
const didStopRecording = async ({state, config, setRecordingName}) => {
const {nameTemplate, dateFormat, timeFormat, randomWordStyle} = config.store;
const date = moment().format(dateFormat);
const time = moment().format(timeFormat);
const generateRandomWord = key => uniqueNamesGenerator({
dictionaries: [dictionaries[key]],
length: 1,
style: randomWordStyle
});
const randomValues = [...dictionaryMap.entries()].reduce((acc, [key, value]) => ({
...acc,
[key]: generateRandomWord(value)
}), {});
const name = template(nameTemplate, {
date,
time,
clipboard: state.clipboardContent,
...randomValues
});
setRecordingName(sanitize(name));
};
const renameRecording = {
title: 'Rename Recording',
config,
willStartRecording,
didStopRecording
};
exports.recordServices = [renameRecording];