@jdeighan/coffee-utils 4.1.31 → 4.1.35
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +3 -2
- package/src/DataStores.coffee +9 -1
- package/src/DataStores.js +12 -5
- package/src/taml.coffee +40 -0
- package/src/taml.js +61 -0
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "4.1.
|
4
|
+
"version": "4.1.35",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -17,6 +17,7 @@
|
|
17
17
|
"./svelte": "./src/svelte_utils.js",
|
18
18
|
"./test": "./src/UnitTester.js",
|
19
19
|
"./store": "./src/DataStores.js",
|
20
|
+
"./taml": "./src/taml.js",
|
20
21
|
"./package.json": "./package.json"
|
21
22
|
},
|
22
23
|
"engines": {
|
@@ -50,6 +51,6 @@
|
|
50
51
|
"cross-env": "^7.0.3",
|
51
52
|
"js-yaml": "^4.1.0",
|
52
53
|
"readline-sync": "^1.4.10",
|
53
|
-
"svelte": "^3.46.
|
54
|
+
"svelte": "^3.46.4"
|
54
55
|
}
|
55
56
|
}
|
package/src/DataStores.coffee
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# DataStores.coffee
|
2
2
|
|
3
3
|
import pathlib from 'path'
|
4
|
+
import yaml from 'js-yaml'
|
4
5
|
import {writable, readable, get} from 'svelte/store'
|
5
6
|
|
6
7
|
import {
|
@@ -10,7 +11,6 @@ import {log} from '@jdeighan/coffee-utils/log'
|
|
10
11
|
import {
|
11
12
|
withExt, slurp, barf, newerDestFileExists,
|
12
13
|
} from '@jdeighan/coffee-utils/fs'
|
13
|
-
import {isTAML, taml} from '@jdeighan/string-input/taml'
|
14
14
|
|
15
15
|
# ---------------------------------------------------------------------------
|
16
16
|
|
@@ -128,6 +128,14 @@ export class TAMLDataStore extends WritableDataStore
|
|
128
128
|
# UTILITIES
|
129
129
|
# ---------------------------------------------------------------------------
|
130
130
|
|
131
|
+
export taml = (text) ->
|
132
|
+
|
133
|
+
if ! text?
|
134
|
+
return undef
|
135
|
+
return yaml.load(untabify(text, 1), {skipInvalid: true})
|
136
|
+
|
137
|
+
# ---------------------------------------------------------------------------
|
138
|
+
|
131
139
|
export brewTamlStr = (code, stub) ->
|
132
140
|
|
133
141
|
return """
|
package/src/DataStores.js
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
// DataStores.coffee
|
3
3
|
import pathlib from 'path';
|
4
4
|
|
5
|
+
import yaml from 'js-yaml';
|
6
|
+
|
5
7
|
import {
|
6
8
|
writable,
|
7
9
|
readable,
|
@@ -28,11 +30,6 @@ import {
|
|
28
30
|
newerDestFileExists
|
29
31
|
} from '@jdeighan/coffee-utils/fs';
|
30
32
|
|
31
|
-
import {
|
32
|
-
isTAML,
|
33
|
-
taml
|
34
|
-
} from '@jdeighan/string-input/taml';
|
35
|
-
|
36
33
|
// ---------------------------------------------------------------------------
|
37
34
|
export var WritableDataStore = class WritableDataStore {
|
38
35
|
constructor(value = undef) {
|
@@ -170,6 +167,16 @@ export var TAMLDataStore = class TAMLDataStore extends WritableDataStore {
|
|
170
167
|
|
171
168
|
// ---------------------------------------------------------------------------
|
172
169
|
// UTILITIES
|
170
|
+
// ---------------------------------------------------------------------------
|
171
|
+
export var taml = function(text) {
|
172
|
+
if (text == null) {
|
173
|
+
return undef;
|
174
|
+
}
|
175
|
+
return yaml.load(untabify(text, 1), {
|
176
|
+
skipInvalid: true
|
177
|
+
});
|
178
|
+
};
|
179
|
+
|
173
180
|
// ---------------------------------------------------------------------------
|
174
181
|
export var brewTamlStr = function(code, stub) {
|
175
182
|
return `import {TAMLDataStore} from '@jdeighan/starbucks/stores';
|
package/src/taml.coffee
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# taml.coffee
|
2
|
+
|
3
|
+
import yaml from 'js-yaml'
|
4
|
+
|
5
|
+
import {
|
6
|
+
assert, undef, oneline, isString,
|
7
|
+
} from '@jdeighan/coffee-utils'
|
8
|
+
import {untabify, tabify} from '@jdeighan/coffee-utils/indent'
|
9
|
+
import {log, tamlStringify} from '@jdeighan/coffee-utils/log'
|
10
|
+
import {slurp} from '@jdeighan/coffee-utils/fs'
|
11
|
+
import {debug} from '@jdeighan/coffee-utils/debug'
|
12
|
+
import {firstLine} from '@jdeighan/coffee-utils/block'
|
13
|
+
|
14
|
+
# ---------------------------------------------------------------------------
|
15
|
+
# isTAML - is the string valid TAML?
|
16
|
+
|
17
|
+
export isTAML = (text) ->
|
18
|
+
|
19
|
+
return isString(text) && (firstLine(text).indexOf('---') == 0)
|
20
|
+
|
21
|
+
# ---------------------------------------------------------------------------
|
22
|
+
# taml - convert valid TAML string to a JavaScript value
|
23
|
+
|
24
|
+
export taml = (text) ->
|
25
|
+
|
26
|
+
debug "enter taml(#{oneline(text)})"
|
27
|
+
if ! text?
|
28
|
+
debug "return undef from taml() - text is not defined"
|
29
|
+
return undef
|
30
|
+
assert isTAML(text), "taml(): string #{oneline(text)} isn't TAML"
|
31
|
+
debug "return from taml()"
|
32
|
+
return yaml.load(untabify(text, 1), {skipInvalid: true})
|
33
|
+
|
34
|
+
# ---------------------------------------------------------------------------
|
35
|
+
# slurpTAML - read TAML from a file
|
36
|
+
|
37
|
+
export slurpTAML = (filepath) ->
|
38
|
+
|
39
|
+
contents = slurp(filepath)
|
40
|
+
return taml(contents)
|
package/src/taml.js
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
// Generated by CoffeeScript 2.6.1
|
2
|
+
// taml.coffee
|
3
|
+
import yaml from 'js-yaml';
|
4
|
+
|
5
|
+
import {
|
6
|
+
assert,
|
7
|
+
undef,
|
8
|
+
oneline,
|
9
|
+
isString
|
10
|
+
} from '@jdeighan/coffee-utils';
|
11
|
+
|
12
|
+
import {
|
13
|
+
untabify,
|
14
|
+
tabify
|
15
|
+
} from '@jdeighan/coffee-utils/indent';
|
16
|
+
|
17
|
+
import {
|
18
|
+
log,
|
19
|
+
tamlStringify
|
20
|
+
} from '@jdeighan/coffee-utils/log';
|
21
|
+
|
22
|
+
import {
|
23
|
+
slurp
|
24
|
+
} from '@jdeighan/coffee-utils/fs';
|
25
|
+
|
26
|
+
import {
|
27
|
+
debug
|
28
|
+
} from '@jdeighan/coffee-utils/debug';
|
29
|
+
|
30
|
+
import {
|
31
|
+
firstLine
|
32
|
+
} from '@jdeighan/coffee-utils/block';
|
33
|
+
|
34
|
+
// ---------------------------------------------------------------------------
|
35
|
+
// isTAML - is the string valid TAML?
|
36
|
+
export var isTAML = function(text) {
|
37
|
+
return isString(text) && (firstLine(text).indexOf('---') === 0);
|
38
|
+
};
|
39
|
+
|
40
|
+
// ---------------------------------------------------------------------------
|
41
|
+
// taml - convert valid TAML string to a JavaScript value
|
42
|
+
export var taml = function(text) {
|
43
|
+
debug(`enter taml(${oneline(text)})`);
|
44
|
+
if (text == null) {
|
45
|
+
debug("return undef from taml() - text is not defined");
|
46
|
+
return undef;
|
47
|
+
}
|
48
|
+
assert(isTAML(text), `taml(): string ${oneline(text)} isn't TAML`);
|
49
|
+
debug("return from taml()");
|
50
|
+
return yaml.load(untabify(text, 1), {
|
51
|
+
skipInvalid: true
|
52
|
+
});
|
53
|
+
};
|
54
|
+
|
55
|
+
// ---------------------------------------------------------------------------
|
56
|
+
// slurpTAML - read TAML from a file
|
57
|
+
export var slurpTAML = function(filepath) {
|
58
|
+
var contents;
|
59
|
+
contents = slurp(filepath);
|
60
|
+
return taml(contents);
|
61
|
+
};
|