@jdeighan/coffee-utils 14.0.29 → 14.0.30
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -6
- package/src/DataStores.coffee +0 -257
- package/src/DataStores.js +0 -310
- package/src/svelte.coffee +0 -42
- package/src/svelte.js +0 -43
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "14.0.
|
4
|
+
"version": "14.0.30",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -13,10 +13,6 @@
|
|
13
13
|
"./indent": "./src/indent.js",
|
14
14
|
"./html": "./src/html.js",
|
15
15
|
"./stack": "./src/stack.js",
|
16
|
-
"./debug": "./src/debug.js",
|
17
|
-
"./arrow": "./src/arrow.js",
|
18
|
-
"./svelte": "./src/svelte.js",
|
19
|
-
"./store": "./src/DataStores.js",
|
20
16
|
"./taml": "./src/taml.js",
|
21
17
|
"./section": "./src/Section.js",
|
22
18
|
"./sectionmap": "./src/SectionMap.js",
|
@@ -49,7 +45,7 @@
|
|
49
45
|
},
|
50
46
|
"homepage": "https://github.com/johndeighan/coffee-utils#readme",
|
51
47
|
"dependencies": {
|
52
|
-
"@jdeighan/base-utils": "^4.0.
|
48
|
+
"@jdeighan/base-utils": "^4.0.15",
|
53
49
|
"cross-env": "^7.0.3",
|
54
50
|
"n-readlines": "^1.0.1",
|
55
51
|
"readline-sync": "^1.4.10",
|
package/src/DataStores.coffee
DELETED
@@ -1,257 +0,0 @@
|
|
1
|
-
# DataStores.coffee
|
2
|
-
|
3
|
-
import pathlib from 'path'
|
4
|
-
import {writable, readable, get} from 'svelte/store'
|
5
|
-
|
6
|
-
import {
|
7
|
-
undef, defined, notdefined, pass, range, getOptions,
|
8
|
-
} from '@jdeighan/base-utils'
|
9
|
-
import {assert, croak} from '@jdeighan/base-utils/exceptions'
|
10
|
-
import {fromTAML} from '@jdeighan/base-utils/taml'
|
11
|
-
import {localStore} from '@jdeighan/coffee-utils/browser'
|
12
|
-
import {
|
13
|
-
withExt, slurp, barf, newerDestFileExists,
|
14
|
-
} from '@jdeighan/coffee-utils/fs'
|
15
|
-
|
16
|
-
# ---------------------------------------------------------------------------
|
17
|
-
|
18
|
-
export class StaticDataStore
|
19
|
-
|
20
|
-
constructor: (value) ->
|
21
|
-
@value = value
|
22
|
-
|
23
|
-
subscribe: (cbFunc) ->
|
24
|
-
cbFunc @value
|
25
|
-
return () ->
|
26
|
-
pass()
|
27
|
-
|
28
|
-
set: (val) ->
|
29
|
-
croak "Can't set() a StaticDataStore"
|
30
|
-
|
31
|
-
update: (func) ->
|
32
|
-
croak "Can't update() a StaticDataStore"
|
33
|
-
|
34
|
-
# ---------------------------------------------------------------------------
|
35
|
-
|
36
|
-
export class WritableDataStore
|
37
|
-
|
38
|
-
constructor: (value=undef) ->
|
39
|
-
@store = writable value
|
40
|
-
|
41
|
-
subscribe: (func) ->
|
42
|
-
return @store.subscribe(func)
|
43
|
-
|
44
|
-
set: (value) ->
|
45
|
-
@store.set(value)
|
46
|
-
return
|
47
|
-
|
48
|
-
update: (func) ->
|
49
|
-
@store.update(func)
|
50
|
-
return
|
51
|
-
|
52
|
-
# ---------------------------------------------------------------------------
|
53
|
-
|
54
|
-
export class LocalStorageDataStore extends WritableDataStore
|
55
|
-
|
56
|
-
constructor: (@masterKey, defValue=undef) ->
|
57
|
-
|
58
|
-
# --- CoffeeScript forces us to call super first
|
59
|
-
# so we can't get the localStorage value first
|
60
|
-
super defValue
|
61
|
-
value = localStore(@masterKey)
|
62
|
-
if defined(value)
|
63
|
-
@set value
|
64
|
-
|
65
|
-
# --- I'm assuming that when update() is called,
|
66
|
-
# set() will also be called
|
67
|
-
|
68
|
-
set: (value) ->
|
69
|
-
assert defined(value), "set(): cannot set to undef"
|
70
|
-
super value
|
71
|
-
localStore @masterKey, value
|
72
|
-
return
|
73
|
-
|
74
|
-
update: (func) ->
|
75
|
-
super func
|
76
|
-
localStore @masterKey, get(@store)
|
77
|
-
return
|
78
|
-
|
79
|
-
# ---------------------------------------------------------------------------
|
80
|
-
|
81
|
-
export class PropsDataStore extends LocalStorageDataStore
|
82
|
-
|
83
|
-
constructor: (masterKey, defValue=undef) ->
|
84
|
-
super masterKey, {}
|
85
|
-
|
86
|
-
setProp: (name, value) ->
|
87
|
-
|
88
|
-
assert defined(name), "PropStore.setProp(): empty key"
|
89
|
-
@update (hPrefs) ->
|
90
|
-
hPrefs[name] = value
|
91
|
-
return hPrefs
|
92
|
-
return
|
93
|
-
|
94
|
-
# ---------------------------------------------------------------------------
|
95
|
-
|
96
|
-
export class ReadableDataStore
|
97
|
-
|
98
|
-
constructor: () ->
|
99
|
-
@store = readable null, (set) ->
|
100
|
-
@setter = set # store the setter function
|
101
|
-
@start() # call your start() method
|
102
|
-
return () => @stop() # return function capable of stopping
|
103
|
-
|
104
|
-
subscribe: (callback) ->
|
105
|
-
return @store.subscribe(callback)
|
106
|
-
|
107
|
-
start: () ->
|
108
|
-
return
|
109
|
-
|
110
|
-
stop: () ->
|
111
|
-
return
|
112
|
-
|
113
|
-
# ---------------------------------------------------------------------------
|
114
|
-
|
115
|
-
export class DateTimeDataStore extends ReadableDataStore
|
116
|
-
|
117
|
-
start: () ->
|
118
|
-
# --- We need to store this interval for use in stop() later
|
119
|
-
@interval = setInterval(() ->
|
120
|
-
@setter new Date()
|
121
|
-
, 1000)
|
122
|
-
return
|
123
|
-
|
124
|
-
stop: () ->
|
125
|
-
clearInterval @interval
|
126
|
-
return
|
127
|
-
|
128
|
-
# ---------------------------------------------------------------------------
|
129
|
-
|
130
|
-
export class MousePosDataStore extends ReadableDataStore
|
131
|
-
|
132
|
-
start: () ->
|
133
|
-
# --- We need to store this handler for use in stop() later
|
134
|
-
@mouseMoveHandler = (e) ->
|
135
|
-
@setter {
|
136
|
-
x: e.clientX,
|
137
|
-
y: e.clientY,
|
138
|
-
}
|
139
|
-
document.body.addEventListener('mousemove', @mouseMoveHandler)
|
140
|
-
return
|
141
|
-
|
142
|
-
stop: () ->
|
143
|
-
document.body.removeEventListener('mousemove', @mouseMoveHandler)
|
144
|
-
return
|
145
|
-
|
146
|
-
# ---------------------------------------------------------------------------
|
147
|
-
|
148
|
-
export class TAMLDataStore extends WritableDataStore
|
149
|
-
|
150
|
-
constructor: (str) ->
|
151
|
-
|
152
|
-
super fromTAML(str)
|
153
|
-
|
154
|
-
# ---------------------------------------------------------------------------
|
155
|
-
# --- Mainly for better understanding, I've implemented data stores
|
156
|
-
# without using svelte's readable or writable data stores
|
157
|
-
|
158
|
-
export class BaseDataStore
|
159
|
-
|
160
|
-
constructor: (@value=undef) ->
|
161
|
-
@lSubscribers = []
|
162
|
-
|
163
|
-
subscribe: (cbFunc) ->
|
164
|
-
cbFunc @value
|
165
|
-
@lSubscribers.push cbFunc
|
166
|
-
return () ->
|
167
|
-
index = @lSubscribers.indexOf cbFunc
|
168
|
-
@lSubscribers.splice index, 1
|
169
|
-
|
170
|
-
set: (val) ->
|
171
|
-
@value = val
|
172
|
-
return
|
173
|
-
|
174
|
-
update: (func) ->
|
175
|
-
@value = func(@value)
|
176
|
-
@alertSubscribers()
|
177
|
-
return
|
178
|
-
|
179
|
-
alertSubscribers: () ->
|
180
|
-
for cbFunc in @lSubscribers
|
181
|
-
cbFunc @value
|
182
|
-
return
|
183
|
-
|
184
|
-
# ---------------------------------------------------------------------------
|
185
|
-
|
186
|
-
export class ToDoDataStore extends BaseDataStore
|
187
|
-
|
188
|
-
constructor: () ->
|
189
|
-
lToDos = [] # save local reference to make code easier to grok
|
190
|
-
super lToDos
|
191
|
-
@lToDos = lToDos # can't do this before calling super
|
192
|
-
|
193
|
-
set: (val) ->
|
194
|
-
croak "Don't use set()"
|
195
|
-
|
196
|
-
update: (func) ->
|
197
|
-
croak "Don't use update()"
|
198
|
-
|
199
|
-
find: (name) ->
|
200
|
-
# --- returns index
|
201
|
-
for index in range(@lToDos.length)
|
202
|
-
if (@lToDos[index].text == name)
|
203
|
-
return index
|
204
|
-
return undef
|
205
|
-
|
206
|
-
clear: () ->
|
207
|
-
# --- Don't set a new array. That would break our reference
|
208
|
-
@lToDos.splice 0, @lToDos.length
|
209
|
-
return
|
210
|
-
|
211
|
-
add: (name) ->
|
212
|
-
assert notdefined(@find(name)), "Todo #{name} already exists"
|
213
|
-
@lToDos.push {
|
214
|
-
text: name
|
215
|
-
done: false
|
216
|
-
}
|
217
|
-
@alertSubscribers()
|
218
|
-
return
|
219
|
-
|
220
|
-
remove: (name) ->
|
221
|
-
index = @find(name)
|
222
|
-
@lToDos.splice index, 1
|
223
|
-
@alertSubscribers()
|
224
|
-
return
|
225
|
-
|
226
|
-
# ---------------------------------------------------------------------------
|
227
|
-
# UTILITIES
|
228
|
-
# ---------------------------------------------------------------------------
|
229
|
-
|
230
|
-
export brewTamlStr = (code, stub) =>
|
231
|
-
|
232
|
-
return """
|
233
|
-
import {TAMLDataStore} from '@jdeighan/starbucks/stores';
|
234
|
-
|
235
|
-
export let #{stub} = new TAMLDataStore(`#{code}`);
|
236
|
-
"""
|
237
|
-
|
238
|
-
# ---------------------------------------------------------------------------
|
239
|
-
|
240
|
-
export brewTamlFile = (srcPath, destPath=undef, hOptions={}) =>
|
241
|
-
# --- taml => js
|
242
|
-
# Valid Options:
|
243
|
-
# force
|
244
|
-
|
245
|
-
if notdefined(destPath)
|
246
|
-
destPath = withExt(srcPath, '.js')
|
247
|
-
{force} = getOptions(hOptions)
|
248
|
-
if force || ! newerDestFileExists(srcPath, destPath)
|
249
|
-
hInfo = pathlib.parse(destPath)
|
250
|
-
stub = hInfo.name
|
251
|
-
|
252
|
-
tamlCode = slurp(srcPath)
|
253
|
-
jsCode = brewTamlStr(tamlCode, stub)
|
254
|
-
barf destPath, jsCode
|
255
|
-
return
|
256
|
-
|
257
|
-
# ---------------------------------------------------------------------------
|
package/src/DataStores.js
DELETED
@@ -1,310 +0,0 @@
|
|
1
|
-
// Generated by CoffeeScript 2.7.0
|
2
|
-
// DataStores.coffee
|
3
|
-
import pathlib from 'path';
|
4
|
-
|
5
|
-
import {
|
6
|
-
writable,
|
7
|
-
readable,
|
8
|
-
get
|
9
|
-
} from 'svelte/store';
|
10
|
-
|
11
|
-
import {
|
12
|
-
undef,
|
13
|
-
defined,
|
14
|
-
notdefined,
|
15
|
-
pass,
|
16
|
-
range,
|
17
|
-
getOptions
|
18
|
-
} from '@jdeighan/base-utils';
|
19
|
-
|
20
|
-
import {
|
21
|
-
assert,
|
22
|
-
croak
|
23
|
-
} from '@jdeighan/base-utils/exceptions';
|
24
|
-
|
25
|
-
import {
|
26
|
-
fromTAML
|
27
|
-
} from '@jdeighan/base-utils/taml';
|
28
|
-
|
29
|
-
import {
|
30
|
-
localStore
|
31
|
-
} from '@jdeighan/coffee-utils/browser';
|
32
|
-
|
33
|
-
import {
|
34
|
-
withExt,
|
35
|
-
slurp,
|
36
|
-
barf,
|
37
|
-
newerDestFileExists
|
38
|
-
} from '@jdeighan/coffee-utils/fs';
|
39
|
-
|
40
|
-
// ---------------------------------------------------------------------------
|
41
|
-
export var StaticDataStore = class StaticDataStore {
|
42
|
-
constructor(value) {
|
43
|
-
this.value = value;
|
44
|
-
}
|
45
|
-
|
46
|
-
subscribe(cbFunc) {
|
47
|
-
cbFunc(this.value);
|
48
|
-
return function() {
|
49
|
-
return pass();
|
50
|
-
};
|
51
|
-
}
|
52
|
-
|
53
|
-
set(val) {
|
54
|
-
return croak("Can't set() a StaticDataStore");
|
55
|
-
}
|
56
|
-
|
57
|
-
update(func) {
|
58
|
-
return croak("Can't update() a StaticDataStore");
|
59
|
-
}
|
60
|
-
|
61
|
-
};
|
62
|
-
|
63
|
-
// ---------------------------------------------------------------------------
|
64
|
-
export var WritableDataStore = class WritableDataStore {
|
65
|
-
constructor(value = undef) {
|
66
|
-
this.store = writable(value);
|
67
|
-
}
|
68
|
-
|
69
|
-
subscribe(func) {
|
70
|
-
return this.store.subscribe(func);
|
71
|
-
}
|
72
|
-
|
73
|
-
set(value) {
|
74
|
-
this.store.set(value);
|
75
|
-
}
|
76
|
-
|
77
|
-
update(func) {
|
78
|
-
this.store.update(func);
|
79
|
-
}
|
80
|
-
|
81
|
-
};
|
82
|
-
|
83
|
-
// ---------------------------------------------------------------------------
|
84
|
-
export var LocalStorageDataStore = class LocalStorageDataStore extends WritableDataStore {
|
85
|
-
constructor(masterKey1, defValue = undef) {
|
86
|
-
var value;
|
87
|
-
super(defValue);
|
88
|
-
this.masterKey = masterKey1;
|
89
|
-
value = localStore(this.masterKey);
|
90
|
-
if (defined(value)) {
|
91
|
-
this.set(value);
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
// --- I'm assuming that when update() is called,
|
96
|
-
// set() will also be called
|
97
|
-
set(value) {
|
98
|
-
assert(defined(value), "set(): cannot set to undef");
|
99
|
-
super.set(value);
|
100
|
-
localStore(this.masterKey, value);
|
101
|
-
}
|
102
|
-
|
103
|
-
update(func) {
|
104
|
-
super.update(func);
|
105
|
-
localStore(this.masterKey, get(this.store));
|
106
|
-
}
|
107
|
-
|
108
|
-
};
|
109
|
-
|
110
|
-
// ---------------------------------------------------------------------------
|
111
|
-
export var PropsDataStore = class PropsDataStore extends LocalStorageDataStore {
|
112
|
-
constructor(masterKey, defValue = undef) {
|
113
|
-
super(masterKey, {});
|
114
|
-
}
|
115
|
-
|
116
|
-
setProp(name, value) {
|
117
|
-
assert(defined(name), "PropStore.setProp(): empty key");
|
118
|
-
this.update(function(hPrefs) {
|
119
|
-
hPrefs[name] = value;
|
120
|
-
return hPrefs;
|
121
|
-
});
|
122
|
-
}
|
123
|
-
|
124
|
-
};
|
125
|
-
|
126
|
-
// ---------------------------------------------------------------------------
|
127
|
-
export var ReadableDataStore = class ReadableDataStore {
|
128
|
-
constructor() {
|
129
|
-
this.store = readable(null, function(set) {
|
130
|
-
this.setter = set; // store the setter function
|
131
|
-
this.start(); // call your start() method
|
132
|
-
return () => {
|
133
|
-
return this.stop(); // return function capable of stopping
|
134
|
-
};
|
135
|
-
});
|
136
|
-
}
|
137
|
-
|
138
|
-
subscribe(callback) {
|
139
|
-
return this.store.subscribe(callback);
|
140
|
-
}
|
141
|
-
|
142
|
-
start() {}
|
143
|
-
|
144
|
-
stop() {}
|
145
|
-
|
146
|
-
};
|
147
|
-
|
148
|
-
// ---------------------------------------------------------------------------
|
149
|
-
export var DateTimeDataStore = class DateTimeDataStore extends ReadableDataStore {
|
150
|
-
start() {
|
151
|
-
// --- We need to store this interval for use in stop() later
|
152
|
-
this.interval = setInterval(function() {
|
153
|
-
return this.setter(new Date(), 1000);
|
154
|
-
});
|
155
|
-
}
|
156
|
-
|
157
|
-
stop() {
|
158
|
-
clearInterval(this.interval);
|
159
|
-
}
|
160
|
-
|
161
|
-
};
|
162
|
-
|
163
|
-
// ---------------------------------------------------------------------------
|
164
|
-
export var MousePosDataStore = class MousePosDataStore extends ReadableDataStore {
|
165
|
-
start() {
|
166
|
-
// --- We need to store this handler for use in stop() later
|
167
|
-
this.mouseMoveHandler = function(e) {
|
168
|
-
return this.setter({
|
169
|
-
x: e.clientX,
|
170
|
-
y: e.clientY
|
171
|
-
});
|
172
|
-
};
|
173
|
-
document.body.addEventListener('mousemove', this.mouseMoveHandler);
|
174
|
-
}
|
175
|
-
|
176
|
-
stop() {
|
177
|
-
document.body.removeEventListener('mousemove', this.mouseMoveHandler);
|
178
|
-
}
|
179
|
-
|
180
|
-
};
|
181
|
-
|
182
|
-
// ---------------------------------------------------------------------------
|
183
|
-
export var TAMLDataStore = class TAMLDataStore extends WritableDataStore {
|
184
|
-
constructor(str) {
|
185
|
-
super(fromTAML(str));
|
186
|
-
}
|
187
|
-
|
188
|
-
};
|
189
|
-
|
190
|
-
// ---------------------------------------------------------------------------
|
191
|
-
// --- Mainly for better understanding, I've implemented data stores
|
192
|
-
// without using svelte's readable or writable data stores
|
193
|
-
export var BaseDataStore = class BaseDataStore {
|
194
|
-
constructor(value1 = undef) {
|
195
|
-
this.value = value1;
|
196
|
-
this.lSubscribers = [];
|
197
|
-
}
|
198
|
-
|
199
|
-
subscribe(cbFunc) {
|
200
|
-
cbFunc(this.value);
|
201
|
-
this.lSubscribers.push(cbFunc);
|
202
|
-
return function() {
|
203
|
-
var index;
|
204
|
-
index = this.lSubscribers.indexOf(cbFunc);
|
205
|
-
return this.lSubscribers.splice(index, 1);
|
206
|
-
};
|
207
|
-
}
|
208
|
-
|
209
|
-
set(val) {
|
210
|
-
this.value = val;
|
211
|
-
}
|
212
|
-
|
213
|
-
update(func) {
|
214
|
-
this.value = func(this.value);
|
215
|
-
this.alertSubscribers();
|
216
|
-
}
|
217
|
-
|
218
|
-
alertSubscribers() {
|
219
|
-
var cbFunc, i, len, ref;
|
220
|
-
ref = this.lSubscribers;
|
221
|
-
for (i = 0, len = ref.length; i < len; i++) {
|
222
|
-
cbFunc = ref[i];
|
223
|
-
cbFunc(this.value);
|
224
|
-
}
|
225
|
-
}
|
226
|
-
|
227
|
-
};
|
228
|
-
|
229
|
-
// ---------------------------------------------------------------------------
|
230
|
-
export var ToDoDataStore = class ToDoDataStore extends BaseDataStore {
|
231
|
-
constructor() {
|
232
|
-
var lToDos;
|
233
|
-
lToDos = []; // save local reference to make code easier to grok
|
234
|
-
super(lToDos);
|
235
|
-
this.lToDos = lToDos; // can't do this before calling super
|
236
|
-
}
|
237
|
-
|
238
|
-
set(val) {
|
239
|
-
return croak("Don't use set()");
|
240
|
-
}
|
241
|
-
|
242
|
-
update(func) {
|
243
|
-
return croak("Don't use update()");
|
244
|
-
}
|
245
|
-
|
246
|
-
find(name) {
|
247
|
-
var i, index, len, ref;
|
248
|
-
ref = range(this.lToDos.length);
|
249
|
-
// --- returns index
|
250
|
-
for (i = 0, len = ref.length; i < len; i++) {
|
251
|
-
index = ref[i];
|
252
|
-
if (this.lToDos[index].text === name) {
|
253
|
-
return index;
|
254
|
-
}
|
255
|
-
}
|
256
|
-
return undef;
|
257
|
-
}
|
258
|
-
|
259
|
-
clear() {
|
260
|
-
// --- Don't set a new array. That would break our reference
|
261
|
-
this.lToDos.splice(0, this.lToDos.length);
|
262
|
-
}
|
263
|
-
|
264
|
-
add(name) {
|
265
|
-
assert(notdefined(this.find(name)), `Todo ${name} already exists`);
|
266
|
-
this.lToDos.push({
|
267
|
-
text: name,
|
268
|
-
done: false
|
269
|
-
});
|
270
|
-
this.alertSubscribers();
|
271
|
-
}
|
272
|
-
|
273
|
-
remove(name) {
|
274
|
-
var index;
|
275
|
-
index = this.find(name);
|
276
|
-
this.lToDos.splice(index, 1);
|
277
|
-
this.alertSubscribers();
|
278
|
-
}
|
279
|
-
|
280
|
-
};
|
281
|
-
|
282
|
-
// ---------------------------------------------------------------------------
|
283
|
-
// UTILITIES
|
284
|
-
// ---------------------------------------------------------------------------
|
285
|
-
export var brewTamlStr = (code, stub) => {
|
286
|
-
return `import {TAMLDataStore} from '@jdeighan/starbucks/stores';
|
287
|
-
|
288
|
-
export let ${stub} = new TAMLDataStore(\`${code}\`);`;
|
289
|
-
};
|
290
|
-
|
291
|
-
// ---------------------------------------------------------------------------
|
292
|
-
export var brewTamlFile = (srcPath, destPath = undef, hOptions = {}) => {
|
293
|
-
var force, hInfo, jsCode, stub, tamlCode;
|
294
|
-
// --- taml => js
|
295
|
-
// Valid Options:
|
296
|
-
// force
|
297
|
-
if (notdefined(destPath)) {
|
298
|
-
destPath = withExt(srcPath, '.js');
|
299
|
-
}
|
300
|
-
({force} = getOptions(hOptions));
|
301
|
-
if (force || !newerDestFileExists(srcPath, destPath)) {
|
302
|
-
hInfo = pathlib.parse(destPath);
|
303
|
-
stub = hInfo.name;
|
304
|
-
tamlCode = slurp(srcPath);
|
305
|
-
jsCode = brewTamlStr(tamlCode, stub);
|
306
|
-
barf(destPath, jsCode);
|
307
|
-
}
|
308
|
-
};
|
309
|
-
|
310
|
-
// ---------------------------------------------------------------------------
|
package/src/svelte.coffee
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# svelte.coffee
|
2
|
-
|
3
|
-
import {assert, croak} from '@jdeighan/base-utils/exceptions'
|
4
|
-
import {LOG} from '@jdeighan/base-utils/log'
|
5
|
-
import {isFunction} from '@jdeighan/base-utils'
|
6
|
-
|
7
|
-
# ---------------------------------------------------------------------------
|
8
|
-
# svelteSourceCodeEsc - to display source code for a *.starbucks page
|
9
|
-
|
10
|
-
export svelteSourceCodeEsc = (str) =>
|
11
|
-
|
12
|
-
return str \
|
13
|
-
.replace(/\</g, '<') \
|
14
|
-
.replace(/\>/g, '>') \
|
15
|
-
.replace(/\{/g, '{') \
|
16
|
-
.replace(/\}/g, '}') \
|
17
|
-
.replace(/\$/g, '$')
|
18
|
-
|
19
|
-
# ---------------------------------------------------------------------------
|
20
|
-
# svelteHtmlEsc - after converting markdown
|
21
|
-
|
22
|
-
export svelteHtmlEsc = (str) =>
|
23
|
-
|
24
|
-
return str \
|
25
|
-
.replace(/\{/g, '{') \
|
26
|
-
.replace(/\}/g, '}') \
|
27
|
-
.replace(/\$/g, '$')
|
28
|
-
|
29
|
-
# ---------------------------------------------------------------------------
|
30
|
-
|
31
|
-
export onInterval = (func, secs, doLog=false) =>
|
32
|
-
|
33
|
-
assert isFunction(func), "onInterval(): 1st arg not a function"
|
34
|
-
ms = Math.floor(1000 * secs)
|
35
|
-
if doLog
|
36
|
-
LOG "calling func every #{ms} ms."
|
37
|
-
interval = setInterval(func, ms)
|
38
|
-
|
39
|
-
return () ->
|
40
|
-
if doLog
|
41
|
-
LOG "destroying interval timer"
|
42
|
-
clearInterval interval
|
package/src/svelte.js
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
// Generated by CoffeeScript 2.7.0
|
2
|
-
// svelte.coffee
|
3
|
-
import {
|
4
|
-
assert,
|
5
|
-
croak
|
6
|
-
} from '@jdeighan/base-utils/exceptions';
|
7
|
-
|
8
|
-
import {
|
9
|
-
LOG
|
10
|
-
} from '@jdeighan/base-utils/log';
|
11
|
-
|
12
|
-
import {
|
13
|
-
isFunction
|
14
|
-
} from '@jdeighan/base-utils';
|
15
|
-
|
16
|
-
// ---------------------------------------------------------------------------
|
17
|
-
// svelteSourceCodeEsc - to display source code for a *.starbucks page
|
18
|
-
export var svelteSourceCodeEsc = (str) => {
|
19
|
-
return str.replace(/\</g, '<').replace(/\>/g, '>').replace(/\{/g, '{').replace(/\}/g, '}').replace(/\$/g, '$');
|
20
|
-
};
|
21
|
-
|
22
|
-
// ---------------------------------------------------------------------------
|
23
|
-
// svelteHtmlEsc - after converting markdown
|
24
|
-
export var svelteHtmlEsc = (str) => {
|
25
|
-
return str.replace(/\{/g, '{').replace(/\}/g, '}').replace(/\$/g, '$');
|
26
|
-
};
|
27
|
-
|
28
|
-
// ---------------------------------------------------------------------------
|
29
|
-
export var onInterval = (func, secs, doLog = false) => {
|
30
|
-
var interval, ms;
|
31
|
-
assert(isFunction(func), "onInterval(): 1st arg not a function");
|
32
|
-
ms = Math.floor(1000 * secs);
|
33
|
-
if (doLog) {
|
34
|
-
LOG(`calling func every ${ms} ms.`);
|
35
|
-
}
|
36
|
-
interval = setInterval(func, ms);
|
37
|
-
return function() {
|
38
|
-
if (doLog) {
|
39
|
-
LOG("destroying interval timer");
|
40
|
-
}
|
41
|
-
return clearInterval(interval);
|
42
|
-
};
|
43
|
-
};
|