@stdlib/datasets-fivethirtyeight-ffq-cli 0.1.0

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/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2016-2023 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,228 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2019 The Stdlib Authors.
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+
19
+ -->
20
+
21
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
32
+ # FiveThirtyEight Food Frequency Questionnaire
33
+
34
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
+
36
+ > [_FiveThirtyEight_][fivethirtyeight-nutrition-studies] reader responses to a food frequency questionnaire ([FFQ][ffq]).
37
+
38
+
39
+
40
+
41
+
42
+ <section class="notes">
43
+
44
+ ## Notes
45
+
46
+ - The administered food frequency questionnaire ([FFQ][ffq]) was the proprietary [Block FFQ][block-ffq].
47
+
48
+ </section>
49
+
50
+ <!-- /.examples -->
51
+
52
+
53
+
54
+
55
+
56
+ <section class="cli">
57
+
58
+
59
+
60
+ <section class="installation">
61
+
62
+ ## Installation
63
+
64
+ To use as a general utility, install the CLI package globally
65
+
66
+ ```bash
67
+ npm install -g @stdlib/datasets-fivethirtyeight-ffq-cli
68
+ ```
69
+
70
+ </section>
71
+
72
+ <!-- CLI usage documentation. -->
73
+
74
+ <section class="usage">
75
+
76
+ ## Usage
77
+
78
+ ```text
79
+ Usage: fivethirtyeight-ffq [options]
80
+
81
+ Options:
82
+
83
+ -h, --help Print this message.
84
+ -V, --version Print the package version.
85
+ ```
86
+
87
+ </section>
88
+
89
+ <!-- /.usage -->
90
+
91
+ <section class="notes">
92
+
93
+ ## Notes
94
+
95
+ - Data is written to `stdout` as comma-separated values ([CSV][csv]), where the first line is a header line.
96
+
97
+ <section class="examples">
98
+
99
+ ## Examples
100
+
101
+ ```bash
102
+ $ fivethirtyeight-ffq
103
+ ```
104
+
105
+ </section>
106
+
107
+ <!-- /.examples -->
108
+
109
+ </section>
110
+
111
+ <!-- /.cli -->
112
+
113
+ * * *
114
+
115
+ <section class="references">
116
+
117
+ ## References
118
+
119
+ - Aschwanden, Christie. 2016. "You Can't Trust What You Read About Nutrition." <https://fivethirtyeight.com/features/you-cant-trust-what-you-read-about-nutrition/>.
120
+
121
+ </section>
122
+
123
+ <!-- /.references -->
124
+
125
+ <!-- <license> -->
126
+
127
+ ## License
128
+
129
+ The data files (databases) are licensed under an [Open Data Commons Attribution 1.0 License][odc-by-1.0] and their contents are licensed under a [Creative Commons Attribution 4.0 International Public License][cc-by-4.0]. The original dataset is attributed to _FiveThirtyEight_ and can be found [here][fivethirtyeight-nutrition-studies]. The software is licensed under [Apache License, Version 2.0][apache-license].
130
+
131
+ <!-- </license> -->
132
+
133
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
134
+
135
+ <section class="related">
136
+
137
+ ## See Also
138
+
139
+ - <span class="package-name">[`@stdlib/datasets-fivethirtyeight-ffq`][@stdlib/datasets-fivethirtyeight-ffq]</span><span class="delimiter">: </span><span class="description">fiveThirtyEight reader responses to a food frequency questionnaire (FFQ).</span>
140
+
141
+
142
+ </section>
143
+
144
+ <!-- /.related -->
145
+
146
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
147
+
148
+
149
+ <section class="main-repo" >
150
+
151
+ * * *
152
+
153
+ ## Notice
154
+
155
+ This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
156
+
157
+ For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib].
158
+
159
+ ### Community
160
+
161
+ [![Chat][chat-image]][chat-url]
162
+
163
+ ---
164
+
165
+ ## Copyright
166
+
167
+ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
168
+
169
+ </section>
170
+
171
+ <!-- /.stdlib -->
172
+
173
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
174
+
175
+ <section class="links">
176
+
177
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/datasets-fivethirtyeight-ffq-cli.svg
178
+ [npm-url]: https://npmjs.org/package/@stdlib/datasets-fivethirtyeight-ffq-cli
179
+
180
+ [test-image]: https://github.com/stdlib-js/datasets-fivethirtyeight-ffq/actions/workflows/test.yml/badge.svg?branch=v0.1.0
181
+ [test-url]: https://github.com/stdlib-js/datasets-fivethirtyeight-ffq/actions/workflows/test.yml?query=branch:v0.1.0
182
+
183
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/datasets-fivethirtyeight-ffq/main.svg
184
+ [coverage-url]: https://codecov.io/github/stdlib-js/datasets-fivethirtyeight-ffq?branch=main
185
+
186
+ <!--
187
+
188
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/datasets-fivethirtyeight-ffq.svg
189
+ [dependencies-url]: https://david-dm.org/stdlib-js/datasets-fivethirtyeight-ffq/main
190
+
191
+ -->
192
+
193
+ [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
194
+ [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
195
+
196
+ [stdlib]: https://github.com/stdlib-js/stdlib
197
+
198
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
199
+
200
+ [cli-section]: https://github.com/stdlib-js/datasets-fivethirtyeight-ffq#cli
201
+ [cli-url]: https://github.com/stdlib-js/datasets-fivethirtyeight-ffq/tree/cli
202
+ [@stdlib/datasets-fivethirtyeight-ffq]: https://www.npmjs.com/package/@stdlib/datasets-fivethirtyeight-ffq
203
+
204
+ [umd]: https://github.com/umdjs/umd
205
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
206
+
207
+ [deno-url]: https://github.com/stdlib-js/datasets-fivethirtyeight-ffq/tree/deno
208
+ [umd-url]: https://github.com/stdlib-js/datasets-fivethirtyeight-ffq/tree/umd
209
+ [esm-url]: https://github.com/stdlib-js/datasets-fivethirtyeight-ffq/tree/esm
210
+ [branches-url]: https://github.com/stdlib-js/datasets-fivethirtyeight-ffq/blob/main/branches.md
211
+
212
+ [odc-by-1.0]: http://opendatacommons.org/licenses/by/1.0/
213
+
214
+ [cc-by-4.0]: http://creativecommons.org/licenses/by/4.0/
215
+
216
+ [apache-license]: https://www.apache.org/licenses/LICENSE-2.0
217
+
218
+ [csv]: https://tools.ietf.org/html/rfc4180
219
+
220
+ [fivethirtyeight-nutrition-studies]: https://fivethirtyeight.com/features/you-cant-trust-what-you-read-about-nutrition/
221
+
222
+ [block-ffq]: https://nutritionquest.com/assessment/list-of-questionnaires-and-screeners/
223
+
224
+ [ffq]: https://en.wikipedia.org/wiki/Food_frequency_questionnaire
225
+
226
+ </section>
227
+
228
+ <!-- /.links -->
package/bin/cli ADDED
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * @license Apache-2.0
5
+ *
6
+ * Copyright (c) 2019 The Stdlib Authors.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+
21
+ 'use strict';
22
+
23
+ // MODULES //
24
+
25
+ var createReadStream = require( 'fs' ).createReadStream;
26
+ var resolve = require( 'path' ).resolve;
27
+ var readFileSync = require( '@stdlib/fs-read-file' ).sync;
28
+ var stdout = require( '@stdlib/streams-node-stdout' );
29
+ var CLI = require( '@stdlib/cli-ctor' );
30
+
31
+
32
+ // MAIN //
33
+
34
+ /**
35
+ * Main execution sequence.
36
+ *
37
+ * @private
38
+ */
39
+ function main() {
40
+ var flags;
41
+ var fpath;
42
+ var cli;
43
+
44
+ // Create a command-line interface:
45
+ cli = new CLI({
46
+ 'pkg': require( './../package.json' ),
47
+ 'options': require( './../etc/cli_opts.json' ),
48
+ 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
49
+ 'encoding': 'utf8'
50
+ })
51
+ });
52
+
53
+ // Get any provided command-line options:
54
+ flags = cli.flags();
55
+ if ( flags.help || flags.version ) {
56
+ return;
57
+ }
58
+
59
+ // Resolve the data file path:
60
+ fpath = resolve( __dirname, '..', 'data', 'data.csv' );
61
+
62
+ // Print the data to stdout:
63
+ createReadStream( fpath )
64
+ .pipe( stdout )
65
+ .on( 'close', onClose );
66
+
67
+ /**
68
+ * Exits the CLI.
69
+ *
70
+ * @private
71
+ */
72
+ function onClose() {
73
+ cli.close( 0 );
74
+ }
75
+ }
76
+
77
+ main();
package/docs/usage.txt ADDED
@@ -0,0 +1,8 @@
1
+
2
+ Usage: fivethirtyeight-ffq [options]
3
+
4
+ Options:
5
+
6
+ -h, --help Print this message.
7
+ -V, --version Print the package version.
8
+
@@ -0,0 +1,14 @@
1
+ {
2
+ "boolean": [
3
+ "help",
4
+ "version"
5
+ ],
6
+ "alias": {
7
+ "help": [
8
+ "h"
9
+ ],
10
+ "version": [
11
+ "V"
12
+ ]
13
+ }
14
+ }
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@stdlib/datasets-fivethirtyeight-ffq-cli",
3
+ "version": "0.1.0",
4
+ "description": "FiveThirtyEight reader responses to a food frequency questionnaire (FFQ).",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "bin": {
17
+ "fivethirtyeight-ffq": "./bin/cli"
18
+ },
19
+ "homepage": "https://stdlib.io",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git://github.com/stdlib-js/datasets-fivethirtyeight-ffq.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/stdlib-js/stdlib/issues"
26
+ },
27
+ "dependencies": {
28
+ "@stdlib/cli-ctor": "^0.1.0",
29
+ "@stdlib/fs-read-file": "^0.1.0",
30
+ "@stdlib/streams-node-stdout": "^0.1.0"
31
+ },
32
+ "devDependencies": {
33
+ "@stdlib/assert-is-browser": "^0.1.0",
34
+ "@stdlib/assert-is-windows": "^0.1.0",
35
+ "@stdlib/process-exec-path": "^0.1.0",
36
+ "proxyquire": "^2.0.0",
37
+ "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
38
+ "istanbul": "^0.4.1",
39
+ "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
40
+ },
41
+ "keywords": [
42
+ "stdlib",
43
+ "datasets",
44
+ "dataset",
45
+ "data",
46
+ "538",
47
+ "fivethirtyeight",
48
+ "nutrition",
49
+ "diet",
50
+ "dietary",
51
+ "p-hacking",
52
+ "data mining",
53
+ "ffq",
54
+ "survey",
55
+ "food",
56
+ "frequency",
57
+ "questionnaire",
58
+ "noise",
59
+ "correlations",
60
+ "correlation",
61
+ "spurious"
62
+ ],
63
+ "funding": {
64
+ "type": "opencollective",
65
+ "url": "https://opencollective.com/stdlib"
66
+ }
67
+ }
@@ -0,0 +1,172 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2019 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var resolve = require( 'path' ).resolve;
24
+ var exec = require( 'child_process' ).exec;
25
+ var tape = require( 'tape' );
26
+ var IS_BROWSER = require( '@stdlib/assert-is-browser' );
27
+ var IS_WINDOWS = require( '@stdlib/assert-is-windows' );
28
+ var EXEC_PATH = require( '@stdlib/process-exec-path' );
29
+ var readFileSync = require( '@stdlib/fs-read-file' ).sync;
30
+
31
+
32
+ // VARIABLES //
33
+
34
+ var fpath = resolve( __dirname, '..', 'bin', 'cli' );
35
+ var opts = {
36
+ 'skip': IS_BROWSER || IS_WINDOWS
37
+ };
38
+
39
+
40
+ // FIXTURES //
41
+
42
+ var PKG_VERSION = require( './../package.json' ).version;
43
+
44
+
45
+ // TESTS //
46
+
47
+ tape( 'command-line interface', function test( t ) {
48
+ t.ok( true, __filename );
49
+ t.end();
50
+ });
51
+
52
+ tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) {
53
+ var expected;
54
+ var cmd;
55
+
56
+ expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
57
+ 'encoding': 'utf8'
58
+ });
59
+ cmd = [
60
+ EXEC_PATH,
61
+ fpath,
62
+ '--help'
63
+ ];
64
+
65
+ exec( cmd.join( ' ' ), done );
66
+
67
+ function done( error, stdout, stderr ) {
68
+ if ( error ) {
69
+ t.fail( error.message );
70
+ } else {
71
+ t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
72
+ t.strictEqual( stderr.toString(), expected+'\n', 'expected value' );
73
+ }
74
+ t.end();
75
+ }
76
+ });
77
+
78
+ tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) {
79
+ var expected;
80
+ var cmd;
81
+
82
+ expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
83
+ 'encoding': 'utf8'
84
+ });
85
+ cmd = [
86
+ EXEC_PATH,
87
+ fpath,
88
+ '-h'
89
+ ];
90
+
91
+ exec( cmd.join( ' ' ), done );
92
+
93
+ function done( error, stdout, stderr ) {
94
+ if ( error ) {
95
+ t.fail( error.message );
96
+ } else {
97
+ t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
98
+ t.strictEqual( stderr.toString(), expected+'\n', 'expected value' );
99
+ }
100
+ t.end();
101
+ }
102
+ });
103
+
104
+ tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) {
105
+ var cmd = [
106
+ EXEC_PATH,
107
+ fpath,
108
+ '--version'
109
+ ];
110
+
111
+ exec( cmd.join( ' ' ), done );
112
+
113
+ function done( error, stdout, stderr ) {
114
+ if ( error ) {
115
+ t.fail( error.message );
116
+ } else {
117
+ t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
118
+ t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' );
119
+ }
120
+ t.end();
121
+ }
122
+ });
123
+
124
+ tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) {
125
+ var cmd = [
126
+ EXEC_PATH,
127
+ fpath,
128
+ '-V'
129
+ ];
130
+
131
+ exec( cmd.join( ' ' ), done );
132
+
133
+ function done( error, stdout, stderr ) {
134
+ if ( error ) {
135
+ t.fail( error.message );
136
+ } else {
137
+ t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' );
138
+ t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' );
139
+ }
140
+ t.end();
141
+ }
142
+ });
143
+
144
+ tape( 'the command-line interface prints FiveThirtyEight reader responses to a food frequency questionnaire (FFQ)', opts, function test( t ) {
145
+ var expected;
146
+ var opts;
147
+ var cmd;
148
+
149
+ cmd = [
150
+ EXEC_PATH,
151
+ fpath
152
+ ];
153
+
154
+ expected = readFileSync( resolve( __dirname, '..', 'data', 'data.csv' ) );
155
+
156
+ opts = {
157
+ 'maxBuffer': 10 * 1024 * 1024
158
+ };
159
+ exec( cmd.join( ' ' ), opts, done );
160
+
161
+ function done( error, stdout, stderr ) {
162
+ if ( error ) {
163
+ t.fail( error.message );
164
+ } else {
165
+ stdout = stdout.toString();
166
+ expected = expected.toString();
167
+ t.strictEqual( stdout, expected, 'prints data' );
168
+ t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
169
+ }
170
+ t.end();
171
+ }
172
+ });