@jdeighan/coffee-utils 4.1.32 → 4.1.33

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "4.1.32",
4
+ "version": "4.1.33",
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": {
@@ -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
+ };