Skip to content

Commit 5913127

Browse files
committed
Add card deck dataset
1 parent ac09cc5 commit 5913127

File tree

20 files changed

+1432
-0
lines changed

20 files changed

+1432
-0
lines changed

lib/node_modules/@stdlib/datasets/standard-card-deck/LICENSE

Lines changed: 356 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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+
# Standard 52-Card Deck
22+
23+
> A list of two or three letter abbreviations for each card in a standard 52-card deck.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var cards = require( '@stdlib/datasets/standard-card-deck' );
31+
```
32+
33+
#### cards()
34+
35+
Returns a list of two or three letter abbreviations for each card in a standard 52-card deck.
36+
37+
```javascript
38+
var list = cards();
39+
// returns [ 'AC', '2C', '3C', ... ]
40+
```
41+
42+
Abbreviation format:
43+
44+
```text
45+
<card><suit>
46+
```
47+
48+
Cards: **A**, **2**, **3**, **4**, **5**, **6**, **7**, **8**, **9**, **10**, **J**, **Q**, **K**,
49+
where
50+
51+
- `A`: ace
52+
- `J`: jack
53+
- `Q`: queen
54+
- `K`: king
55+
56+
Suit abbreviations:
57+
58+
- `C`: clubs
59+
- `D`: diamonds
60+
- `H`: hearts
61+
- `S`: spades
62+
63+
</section>
64+
65+
<!-- /.usage -->
66+
67+
<section class="examples">
68+
69+
<!-- TODO: more creative example. -->
70+
71+
## Examples
72+
73+
<!-- eslint no-undef: "error" -->
74+
75+
```javascript
76+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
77+
var cards = require( '@stdlib/datasets/standard-card-deck' );
78+
79+
var list;
80+
var len;
81+
var idx;
82+
var i;
83+
84+
list = cards();
85+
len = list.length;
86+
87+
// Select random cards from the list...
88+
for ( i = 0; i < 100; i++ ) {
89+
idx = discreteUniform( 0, len-1 );
90+
console.log( list[ idx ] );
91+
}
92+
```
93+
94+
</section>
95+
96+
<!-- /.examples -->
97+
98+
* * *
99+
100+
<section class="cli">
101+
102+
## CLI
103+
104+
<section class="usage">
105+
106+
### Usage
107+
108+
```text
109+
Usage: standard-card-deck [options]
110+
111+
Options:
112+
113+
-h, --help Print this message.
114+
-V, --version Print the package version.
115+
```
116+
117+
</section>
118+
119+
<!-- /.usage -->
120+
121+
<section class="examples">
122+
123+
### Examples
124+
125+
```bash
126+
$ standard-card-deck
127+
AC
128+
2C
129+
3C
130+
...
131+
```
132+
133+
</section>
134+
135+
<!-- /.examples -->
136+
137+
</section>
138+
139+
<!-- /.cli -->
140+
141+
<!-- <license> -->
142+
143+
## License
144+
145+
The data files (databases) are licensed under an [Open Data Commons Public Domain Dedication & License 1.0][pddl-1.0] and their contents are licensed under [Creative Commons Zero v1.0 Universal][cc0]. The software is licensed under [Apache License, Version 2.0][apache-license].
146+
147+
<!-- </license> -->
148+
149+
<section class="links">
150+
151+
[pddl-1.0]: http://opendatacommons.org/licenses/pddl/1.0/
152+
153+
[cc0]: https://creativecommons.org/publicdomain/zero/1.0
154+
155+
[apache-license]: https://www.apache.org/licenses/LICENSE-2.0
156+
157+
</section>
158+
159+
<!-- /.links -->
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 bench = require( '@stdlib/bench' );
24+
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
25+
var pkg = require( './../package.json' ).name;
26+
var cards = require( './../lib/browser.js' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+'::browser', function benchmark( b ) {
32+
var data;
33+
var i;
34+
b.tic();
35+
for ( i = 0; i < b.iterations; i++ ) {
36+
data = cards();
37+
if ( data.length === 0 ) {
38+
b.fail( 'should have a length greater than 0' );
39+
}
40+
}
41+
b.toc();
42+
if ( !isStringArray( data ) ) {
43+
b.fail( 'should return a string array' );
44+
}
45+
b.pass( 'benchmark finished' );
46+
b.end();
47+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 bench = require( '@stdlib/bench' );
24+
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
25+
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
26+
var pkg = require( './../package.json' ).name;
27+
var cards = require( './../lib' );
28+
29+
30+
// VARIABLES //
31+
32+
var opts = {
33+
'skip': IS_BROWSER
34+
};
35+
36+
37+
// MAIN //
38+
39+
bench( pkg, opts, function benchmark( b ) {
40+
var data;
41+
var i;
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
data = cards();
45+
if ( data.length === 0 ) {
46+
b.fail( 'should have a length greater than 0' );
47+
}
48+
}
49+
b.toc();
50+
if ( !isStringArray( data ) ) {
51+
b.fail( 'should return a string array' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
});
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/tools/cli' );
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.txt' );
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();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["AC","2C","3C","4C","5C","6C","7C","8C","9C","10C","JC","QC","KC","AD","2D","3D","4D","5D","6D","7D","8D","9D","10D","JD","QD","KD","AH","2H","3H","4H","5H","6H","7H","8H","9H","10H","JH","QH","KH","AS","2S","3S","4S","5S","6S","7S","8S","9S","10S","JS","QS","KS"]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
AC
2+
2C
3+
3C
4+
4C
5+
5C
6+
6C
7+
7C
8+
8C
9+
9C
10+
10C
11+
JC
12+
QC
13+
KC
14+
AD
15+
2D
16+
3D
17+
4D
18+
5D
19+
6D
20+
7D
21+
8D
22+
9D
23+
10D
24+
JD
25+
QD
26+
KD
27+
AH
28+
2H
29+
3H
30+
4H
31+
5H
32+
6H
33+
7H
34+
8H
35+
9H
36+
10H
37+
JH
38+
QH
39+
KH
40+
AS
41+
2S
42+
3S
43+
4S
44+
5S
45+
6S
46+
7S
47+
8S
48+
9S
49+
10S
50+
JS
51+
QS
52+
KS

0 commit comments

Comments
 (0)