@jdeighan/coffee-utils 4.1.4 → 4.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.save/fs.test.js DELETED
@@ -1,191 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // fs.test.coffee
3
- var dir, hOpt, myfname, mypath, rootdir, simple, wd;
4
-
5
- import assert from 'assert';
6
-
7
- import {
8
- dirname,
9
- resolve
10
- } from 'path';
11
-
12
- import {
13
- fileURLToPath
14
- } from 'url';
15
-
16
- import {
17
- existsSync,
18
- copyFileSync,
19
- readFileSync,
20
- writeFileSync
21
- } from 'fs';
22
-
23
- import {
24
- UnitTester
25
- } from '@jdeighan/coffee-utils/test';
26
-
27
- import {
28
- say,
29
- undef
30
- } from '@jdeighan/coffee-utils';
31
-
32
- import {
33
- debug
34
- } from '@jdeighan/coffee-utils/debug';
35
-
36
- import {
37
- mydir,
38
- mkpath,
39
- isFile,
40
- isDir,
41
- isSimpleFileName,
42
- getSubDirs,
43
- pathTo,
44
- getFullPath,
45
- parseSource,
46
- fileExt,
47
- withExt,
48
- withUnderScore
49
- } from '@jdeighan/coffee-utils/fs';
50
-
51
- simple = new UnitTester();
52
-
53
- dir = mydir(import.meta.url);
54
-
55
- assert(existsSync(dir));
56
-
57
- // ---------------------------------------------------------------------------
58
- hOpt = {
59
- removeLeadingUnderScore: true
60
- };
61
-
62
- simple.equal(21, withExt('file.py', 'svelte'), 'file.svelte');
63
-
64
- simple.equal(21, withExt('file.py', 'svelte', hOpt), 'file.svelte');
65
-
66
- simple.equal(21, withExt('_file.py', 'svelte', hOpt), 'file.svelte');
67
-
68
- simple.equal(21, withExt('/bin/file.py', 'svelte'), '/bin/file.svelte');
69
-
70
- simple.equal(21, withExt('/bin/file.py', 'svelte', hOpt), '/bin/file.svelte');
71
-
72
- simple.equal(21, withExt('/bin/_file.py', 'svelte', hOpt), '/bin/file.svelte');
73
-
74
- simple.equal(21, withUnderScore('file.py', 'svelte'), '_file.py');
75
-
76
- simple.equal(21, withUnderScore('_file.py', 'svelte'), '__file.py');
77
-
78
- simple.equal(21, withUnderScore('/bin/file.py', 'svelte'), '/bin/_file.py');
79
-
80
- simple.equal(21, withUnderScore('/bin/_file.py', 'svelte'), '/bin/__file.py');
81
-
82
- // ---------------------------------------------------------------------------
83
- (function() {
84
- var fname;
85
- fname = 'debug.test.coffee';
86
- simple.truthy(29, existsSync(`${dir}/${fname}`));
87
- simple.falsy(30, existsSync(`${dir}/nosuchfile.test.coffee`));
88
- return simple.equal(31, pathTo(`${fname}`, dir), `${dir}/${fname}`);
89
- })();
90
-
91
- // ---------------------------------------------------------------------------
92
-
93
- // --- dirs are returned in alphabetical order
94
- simple.equal(37, getSubDirs(dir), ['data', 'markdown', 'subdirectory']);
95
-
96
- simple.equal(39, pathTo('test.txt', dir), `${dir}/subdirectory/test.txt`);
97
-
98
- // ---------------------------------------------------------------------------
99
- simple.equal(44, mkpath('/usr/lib', 'johnd'), '/usr/lib/johnd');
100
-
101
- simple.equal(48, mkpath('', '/usr/lib', undef, 'johnd'), '/usr/lib/johnd');
102
-
103
- simple.equal(45, mkpath("c:", 'local/user'), 'c:/local/user');
104
-
105
- simple.equal(46, mkpath('/usr', 'lib', 'local', 'johnd'), '/usr/lib/local/johnd');
106
-
107
- simple.equal(48, mkpath('\\usr\\lib', 'johnd'), '/usr/lib/johnd');
108
-
109
- simple.equal(49, mkpath("c:", 'local\\user'), 'c:/local/user');
110
-
111
- simple.equal(50, mkpath('\\usr', 'lib', 'local', 'johnd'), '/usr/lib/local/johnd');
112
-
113
- simple.equal(55, mkpath('C:\\Users\\johnd', 'cielo'), 'c:/Users/johnd/cielo');
114
-
115
- // ---------------------------------------------------------------------------
116
- // test getFullPath()
117
-
118
- // --- current working directory is the root dir, i.e. parent of this directory
119
- wd = mkpath(process.cwd());
120
-
121
- myfname = 'fs.test.coffee';
122
-
123
- mypath = mkpath(dir, myfname);
124
-
125
- rootdir = mkpath(resolve(dir, '..'));
126
-
127
- assert(rootdir === wd, `${rootdir} should equal ${wd}`);
128
-
129
- debug(`Current Working Directory = '${wd}'`);
130
-
131
- debug(`dir = '${dir}'`);
132
-
133
- debug(`myfname = '${myfname}'`);
134
-
135
- debug(`mypath = '${mypath}'`);
136
-
137
- debug(`rootdir = '${rootdir}'`);
138
-
139
- // --- given a full path, only change \ to /
140
- simple.equal(72, getFullPath(mypath), mypath);
141
-
142
- // --- given a simple file name, prepend the current working directory
143
- simple.equal(75, getFullPath(myfname), mkpath(rootdir, myfname));
144
-
145
- // --- leading . should be resolved
146
- simple.equal(78, getFullPath(`./${myfname}`), mkpath(rootdir, myfname));
147
-
148
- // --- leading .. should be resolved
149
- simple.equal(81, getFullPath(`./test/../${myfname}`), mkpath(rootdir, myfname));
150
-
151
- simple.equal(86, parseSource('unit test'), {
152
- filename: 'unit test',
153
- stub: 'unit test'
154
- });
155
-
156
- simple.equal(91, parseSource("c:/Users/johnd/oz/src/test.js"), {
157
- dir: 'c:/Users/johnd/oz/src',
158
- fullpath: 'c:/Users/johnd/oz/src/test.js',
159
- filename: 'test.js',
160
- stub: 'test',
161
- ext: '.js'
162
- });
163
-
164
- simple.equal(91, parseSource("c:\\Users\\johnd\\oz\\src\\test.js"), {
165
- dir: 'c:/Users/johnd/oz/src',
166
- fullpath: 'c:/Users/johnd/oz/src/test.js',
167
- filename: 'test.js',
168
- stub: 'test',
169
- ext: '.js'
170
- });
171
-
172
- if (process.platform === 'win32') {
173
- simple.truthy(108, isDir('c:/Users'));
174
- simple.truthy(109, isDir('c:/Program Files'));
175
- simple.falsy(110, isFile('c:/Users'));
176
- simple.falsy(111, isFile('c:/Program Files'));
177
- simple.falsy(113, isDir('c:/Windows/notepad.exe'));
178
- simple.falsy(114, isDir('c:/Program Files/Windows Media Player/wmplayer.exe'));
179
- simple.truthy(115, isFile('c:/Windows/notepad.exe'));
180
- simple.truthy(116, isFile('c:/Program Files/Windows Media Player/wmplayer.exe'));
181
- simple.truthy(118, isSimpleFileName('notepad.exe'));
182
- simple.falsy(119, isSimpleFileName('c:/Program Files/Windows Media Player/wmplayer.exe'));
183
- }
184
-
185
- simple.equal(121, fileExt('file.txt'), '.txt');
186
-
187
- simple.equal(122, fileExt('file.'), '');
188
-
189
- simple.equal(123, fileExt('file.99'), '.99');
190
-
191
- simple.equal(124, fileExt('file._txt'), '._txt');
@@ -1,130 +0,0 @@
1
- # indent.test.coffee
2
-
3
- import assert from 'assert'
4
-
5
- import {UnitTester} from '@jdeighan/coffee-utils/test'
6
- import {isInteger} from '@jdeighan/coffee-utils'
7
- import {
8
- indentLevel, indentation, undented, splitLine,
9
- indented, tabify, untabify,
10
- } from '@jdeighan/coffee-utils/indent'
11
-
12
- simple = new UnitTester()
13
-
14
- # ---------------------------------------------------------------------------
15
-
16
- simple.equal 16, indentLevel("abc"), 0
17
- simple.equal 17, indentLevel("\tabc"), 1
18
- simple.equal 18, indentLevel("\t\tabc"), 2
19
-
20
- # ---------------------------------------------------------------------------
21
-
22
- simple.equal 22, indentation(0), ''
23
- simple.equal 23, indentation(1), "\t"
24
- simple.equal 24, indentation(2), "\t\t"
25
-
26
- # ---------------------------------------------------------------------------
27
-
28
- simple.equal 28, undented("abc"), "abc"
29
- simple.equal 29, undented("\tabc"), "abc"
30
- simple.equal 30, undented("\t\tabc"), "abc"
31
- simple.equal 31, undented("\t\tabc", 0), "\t\tabc"
32
- simple.equal 32, undented("\t\tabc", 1), "\tabc"
33
- simple.equal 33, undented("\t\tabc", 2), "abc"
34
-
35
- # ---------------------------------------------------------------------------
36
-
37
- simple.equal 37, undented("\t\tfirst\n\t\tsecond\n\t\t\tthird\n"),
38
- "first\nsecond\n\tthird\n",
39
-
40
- # ---------------------------------------------------------------------------
41
-
42
- simple.equal 42, splitLine("abc"), [0, "abc"]
43
- simple.equal 43, splitLine("\tabc"), [1, "abc"]
44
- simple.equal 44, splitLine("\t\tabc"), [2, "abc"]
45
- simple.equal 45, splitLine("\t\t\t"), [0, ""]
46
-
47
- # ---------------------------------------------------------------------------
48
-
49
- simple.equal 49, indented("abc", 0), "abc"
50
- simple.equal 50, indented("abc", 1), "\tabc"
51
- simple.equal 51, indented("abc", 2), "\t\tabc"
52
-
53
- # --- empty lines, indented, should just be empty lines
54
- simple.equal 54, indented("abc\n\ndef", 2), "\t\tabc\n\n\t\tdef"
55
-
56
- (() ->
57
- str = "main\n\toverflow: auto\n\nnav\n\toverflow: auto"
58
- exp = "\tmain\n\t\toverflow: auto\n\n\tnav\n\t\toverflow: auto"
59
- simple.equal 59, indented(str, 1), exp
60
- )()
61
-
62
- # --- indented also handles arrays, so test them, too
63
-
64
- # --- empty lines, indented, should just be empty lines
65
- simple.equal 65, indented(['abc','','def'], 2), '\t\tabc\n\n\t\tdef'
66
-
67
- (() ->
68
- lLines = ['main','\toverflow: auto','','nav','\toverflow: auto']
69
- lExp = '\tmain\n\t\toverflow: auto\n\n\tnav\n\t\toverflow: auto'
70
- simple.equal 70, indented(lLines, 1), lExp
71
- )()
72
-
73
- # ---------------------------------------------------------------------------
74
-
75
- (() ->
76
- prefix = ' ' # 3 spaces
77
-
78
- simple.equal 78, tabify("""
79
- first line
80
- #{prefix}second line
81
- #{prefix}#{prefix}third line
82
- """, 3), """
83
- first line
84
- \tsecond line
85
- \t\tthird line
86
- """
87
- )()
88
-
89
- # ---------------------------------------------------------------------------
90
- # you don't need to tell it number of spaces
91
-
92
- (() ->
93
- prefix = ' ' # 3 spaces
94
-
95
- simple.equal 95, tabify("""
96
- first line
97
- #{prefix}second line
98
- #{prefix}#{prefix}third line
99
- """), """
100
- first line
101
- \tsecond line
102
- \t\tthird line
103
- """
104
- )()
105
-
106
- # ---------------------------------------------------------------------------
107
-
108
- (() ->
109
- prefix = ' ' # 3 spaces
110
-
111
- simple.equal 111, untabify("""
112
- first line
113
- \tsecond line
114
- \t\tthird line
115
- """, 3), """
116
- first line
117
- #{prefix}second line
118
- #{prefix}#{prefix}third line
119
- """
120
- )()
121
-
122
- # ---------------------------------------------------------------------------
123
-
124
- simple.equal 124, indented("export name = undef", 1), "\texport name = undef"
125
- simple.equal 125, indented("export name = undef", 2), "\t\texport name = undef"
126
-
127
- # ---------------------------------------------------------------------------
128
- # make sure indentLevel() works for blocks
129
-
130
- simple.equal 130, indentLevel("\t\tabc\n\t\tdef\n\t\t\tghi"), 2
@@ -1,136 +0,0 @@
1
- // Generated by CoffeeScript 2.6.1
2
- // indent.test.coffee
3
- var simple;
4
-
5
- import assert from 'assert';
6
-
7
- import {
8
- UnitTester
9
- } from '@jdeighan/coffee-utils/test';
10
-
11
- import {
12
- isInteger
13
- } from '@jdeighan/coffee-utils';
14
-
15
- import {
16
- indentLevel,
17
- indentation,
18
- undented,
19
- splitLine,
20
- indented,
21
- tabify,
22
- untabify
23
- } from '@jdeighan/coffee-utils/indent';
24
-
25
- simple = new UnitTester();
26
-
27
- // ---------------------------------------------------------------------------
28
- simple.equal(16, indentLevel("abc"), 0);
29
-
30
- simple.equal(17, indentLevel("\tabc"), 1);
31
-
32
- simple.equal(18, indentLevel("\t\tabc"), 2);
33
-
34
- // ---------------------------------------------------------------------------
35
- simple.equal(22, indentation(0), '');
36
-
37
- simple.equal(23, indentation(1), "\t");
38
-
39
- simple.equal(24, indentation(2), "\t\t");
40
-
41
- // ---------------------------------------------------------------------------
42
- simple.equal(28, undented("abc"), "abc");
43
-
44
- simple.equal(29, undented("\tabc"), "abc");
45
-
46
- simple.equal(30, undented("\t\tabc"), "abc");
47
-
48
- simple.equal(31, undented("\t\tabc", 0), "\t\tabc");
49
-
50
- simple.equal(32, undented("\t\tabc", 1), "\tabc");
51
-
52
- simple.equal(33, undented("\t\tabc", 2), "abc");
53
-
54
- // ---------------------------------------------------------------------------
55
- simple.equal(37, undented("\t\tfirst\n\t\tsecond\n\t\t\tthird\n"), "first\nsecond\n\tthird\n");
56
-
57
- // ---------------------------------------------------------------------------
58
- simple.equal(42, splitLine("abc"), [0, "abc"]);
59
-
60
- simple.equal(43, splitLine("\tabc"), [1, "abc"]);
61
-
62
- simple.equal(44, splitLine("\t\tabc"), [2, "abc"]);
63
-
64
- simple.equal(45, splitLine("\t\t\t"), [0, ""]);
65
-
66
- // ---------------------------------------------------------------------------
67
- simple.equal(49, indented("abc", 0), "abc");
68
-
69
- simple.equal(50, indented("abc", 1), "\tabc");
70
-
71
- simple.equal(51, indented("abc", 2), "\t\tabc");
72
-
73
- // --- empty lines, indented, should just be empty lines
74
- simple.equal(54, indented("abc\n\ndef", 2), "\t\tabc\n\n\t\tdef");
75
-
76
- (function() {
77
- var exp, str;
78
- str = "main\n\toverflow: auto\n\nnav\n\toverflow: auto";
79
- exp = "\tmain\n\t\toverflow: auto\n\n\tnav\n\t\toverflow: auto";
80
- return simple.equal(59, indented(str, 1), exp);
81
- })();
82
-
83
- // --- indented also handles arrays, so test them, too
84
-
85
- // --- empty lines, indented, should just be empty lines
86
- simple.equal(65, indented(['abc', '', 'def'], 2), '\t\tabc\n\n\t\tdef');
87
-
88
- (function() {
89
- var lExp, lLines;
90
- lLines = ['main', '\toverflow: auto', '', 'nav', '\toverflow: auto'];
91
- lExp = '\tmain\n\t\toverflow: auto\n\n\tnav\n\t\toverflow: auto';
92
- return simple.equal(70, indented(lLines, 1), lExp);
93
- })();
94
-
95
- // ---------------------------------------------------------------------------
96
- (function() {
97
- var prefix;
98
- prefix = ' '; // 3 spaces
99
- return simple.equal(78, tabify(`first line
100
- ${prefix}second line
101
- ${prefix}${prefix}third line`, 3), `first line
102
- \tsecond line
103
- \t\tthird line`);
104
- })();
105
-
106
- // ---------------------------------------------------------------------------
107
- // you don't need to tell it number of spaces
108
- (function() {
109
- var prefix;
110
- prefix = ' '; // 3 spaces
111
- return simple.equal(95, tabify(`first line
112
- ${prefix}second line
113
- ${prefix}${prefix}third line`), `first line
114
- \tsecond line
115
- \t\tthird line`);
116
- })();
117
-
118
- // ---------------------------------------------------------------------------
119
- (function() {
120
- var prefix;
121
- prefix = ' '; // 3 spaces
122
- return simple.equal(111, untabify(`first line
123
- \tsecond line
124
- \t\tthird line`, 3), `first line
125
- ${prefix}second line
126
- ${prefix}${prefix}third line`);
127
- })();
128
-
129
- // ---------------------------------------------------------------------------
130
- simple.equal(124, indented("export name = undef", 1), "\texport name = undef");
131
-
132
- simple.equal(125, indented("export name = undef", 2), "\t\texport name = undef");
133
-
134
- // ---------------------------------------------------------------------------
135
- // make sure indentLevel() works for blocks
136
- simple.equal(130, indentLevel("\t\tabc\n\t\tdef\n\t\t\tghi"), 2);