UNPKG

1.28 kBPlain TextView Raw
1import * as assert from 'assert'
2
3export const Strings = {
4 BadMessageKey: 'Bad Message Key: ?0',
5
6 ManagerFailedToStart: 'Coordinator failed to start',
7 ManagerErrorFn: 'Coordinator Function failed ?0',
8 ManagerInitialized: 'Coordinator is already initialized',
9 ManagerNotInitialized: 'Coordinator not initialized',
10 ManagerSettled: 'Coordinator is settled',
11 ManagerNotSettled: 'Coordinator not settled',
12 ManagerInitComplete: 'dont forget to start when models are prepared, start triggers model prep, including table create',
13 ManagerNoSyncModels: 'Create tables is disabled, nothing to prepare',
14 ManagerOnlyOneKeyType: 'An attribute can only have 1 key type ?0',
15 ManagerTypeStoreRequired: 'TypeStore required on options',
16 PromiseUnhandledRejection: 'Unhandled promise rejection ?0',
17 PromiseRejected: 'Handled rejection - just for debugging/tracing'
18}
19
20/**
21 * Retrieve a message with placeholders
22 * replaced
23 *
24 * @param key
25 * @param args
26 * @returns {any} an array of values, the index in the rest args
27 * starting at 0 maps to the string with ?0, ?1 ... ?n
28 */
29export function msg(str, ...args) {
30 if (!str) {
31 str = Strings.BadMessageKey
32 args.splice(0,0,str)
33 }
34
35 args.forEach((arg,index) => {
36 str = str.replace(new RegExp(`\\?${index}`),arg)
37 })
38
39 return str
40}