fortune-teller 0.1.0 → 0.3.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.
Files changed (67) hide show
  1. package/LICENSE +53 -0
  2. package/README.md +37 -0
  3. package/data/fortunes.json +1 -0
  4. package/lib/build-data.js +52 -0
  5. package/lib/fortune.js +16 -10
  6. package/lib/fortune.mjs +7 -0
  7. package/package.json +20 -5
  8. package/third-party/fortune-mod-1.99.1/Notes +178 -0
  9. package/third-party/fortune-mod-1.99.1/README.md +19 -0
  10. package/third-party/fortune-mod-1.99.1/fortune.c.license +37 -0
  11. package/.npmignore +0 -27
  12. package/fortunes/art +0 -2242
  13. package/fortunes/ascii-art +0 -153
  14. package/fortunes/computers +0 -5417
  15. package/fortunes/cookie +0 -5716
  16. package/fortunes/definitions +0 -5030
  17. package/fortunes/drugs +0 -1155
  18. package/fortunes/education +0 -952
  19. package/fortunes/ethnic +0 -854
  20. package/fortunes/food +0 -886
  21. package/fortunes/fortunes +0 -920
  22. package/fortunes/goedel +0 -204
  23. package/fortunes/humorists +0 -1016
  24. package/fortunes/kids +0 -710
  25. package/fortunes/law +0 -1260
  26. package/fortunes/linuxcookie +0 -499
  27. package/fortunes/literature +0 -1257
  28. package/fortunes/love +0 -576
  29. package/fortunes/magic +0 -194
  30. package/fortunes/medicine +0 -423
  31. package/fortunes/men-women +0 -2556
  32. package/fortunes/miscellaneous +0 -1738
  33. package/fortunes/news +0 -260
  34. package/fortunes/off/Makefile +0 -32
  35. package/fortunes/off/unrotated/astrology +0 -289
  36. package/fortunes/off/unrotated/black-humor +0 -1947
  37. package/fortunes/off/unrotated/definitions +0 -1397
  38. package/fortunes/off/unrotated/drugs +0 -360
  39. package/fortunes/off/unrotated/ethnic +0 -1082
  40. package/fortunes/off/unrotated/hphobia +0 -405
  41. package/fortunes/off/unrotated/limerick +0 -6376
  42. package/fortunes/off/unrotated/misandry +0 -83
  43. package/fortunes/off/unrotated/miscellaneous +0 -330
  44. package/fortunes/off/unrotated/misogyny +0 -297
  45. package/fortunes/off/unrotated/politics +0 -2018
  46. package/fortunes/off/unrotated/privates +0 -1015
  47. package/fortunes/off/unrotated/racism +0 -12
  48. package/fortunes/off/unrotated/religion +0 -1364
  49. package/fortunes/off/unrotated/riddles +0 -1089
  50. package/fortunes/off/unrotated/sex +0 -4578
  51. package/fortunes/off/unrotated/songs-poems +0 -2271
  52. package/fortunes/off/unrotated/vulgarity +0 -1089
  53. package/fortunes/people +0 -4265
  54. package/fortunes/pets +0 -186
  55. package/fortunes/platitudes +0 -1366
  56. package/fortunes/politics +0 -2918
  57. package/fortunes/riddles +0 -595
  58. package/fortunes/science +0 -3010
  59. package/fortunes/songs-poems +0 -7151
  60. package/fortunes/sports +0 -814
  61. package/fortunes/startrek +0 -820
  62. package/fortunes/translate-me +0 -64
  63. package/fortunes/wisdom +0 -1576
  64. package/fortunes/work +0 -2724
  65. package/fortunes/zippy +0 -1289
  66. package/lib/convert.js +0 -61
  67. package/lib/loader.js +0 -35
@@ -0,0 +1,52 @@
1
+ // Regenerates data/fortunes.json from the raw fortune files in fortunes/.
2
+ // The generated file is committed and ships inside the npm tarball, so
3
+ // installing this package never runs a build script.
4
+ //
5
+ // npm run build
6
+
7
+ var fs = require('fs');
8
+ var path = require('path');
9
+
10
+ var ROOT = path.join(__dirname, '..');
11
+ var FORTUNE_FOLDER = path.join(ROOT, 'fortunes');
12
+ var OUTPUT = path.join(ROOT, 'data', 'fortunes.json');
13
+
14
+ // The npm package ships data/fortunes.json and not fortunes/, so there is
15
+ // nothing to rebuild in an installed copy. Say so and exit, rather than
16
+ // throwing an ENOENT from readdirSync.
17
+ if (!fs.existsSync(FORTUNE_FOLDER)) {
18
+ console.log('No fortunes/ directory: this package ships prebuilt data.');
19
+ console.log('Run `npm run build` in a git checkout to regenerate it.');
20
+ process.exit(0);
21
+ }
22
+
23
+ function readFolder(folder) {
24
+ var out = {};
25
+
26
+ fs.readdirSync(path.join(FORTUNE_FOLDER, folder)).sort().forEach(function (file) {
27
+ if (file.indexOf('Makefile') !== -1) return;
28
+
29
+ var rel = folder ? folder + '/' + file : file;
30
+ var full = path.join(FORTUNE_FOLDER, rel);
31
+
32
+ if (fs.statSync(full).isDirectory()) {
33
+ out[file] = readFolder(rel);
34
+ } else {
35
+ // Same delimiter the C fortune(1) uses. Every file ends with a
36
+ // trailing %, so the last element of the split is blank; drop
37
+ // blanks or fortune() returns an empty string.
38
+ out[file] = fs.readFileSync(full, 'utf8').split('%\n').filter(function (text) {
39
+ return /\S/.test(text);
40
+ });
41
+ }
42
+ });
43
+
44
+ return out;
45
+ }
46
+
47
+ var data = readFolder('');
48
+
49
+ fs.mkdirSync(path.dirname(OUTPUT), { recursive: true });
50
+ fs.writeFileSync(OUTPUT, JSON.stringify(data));
51
+
52
+ console.log('Wrote %s', path.relative(ROOT, OUTPUT));
package/lib/fortune.js CHANGED
@@ -1,14 +1,20 @@
1
- var loader = require('./loader');
1
+ var data = require('../data/fortunes.json');
2
2
 
3
- (function(){
4
- var fortune = {};
3
+ var fortunes = [];
5
4
 
6
- var fortunes = loader.load();
5
+ (function walk(node) {
6
+ Object.keys(node).forEach(function (key) {
7
+ if (Array.isArray(node[key])) fortunes = fortunes.concat(node[key]);
8
+ else walk(node[key]);
9
+ });
10
+ })(data);
7
11
 
8
- fortune.fortune = function(){
9
- var r = Math.floor(Math.random() * fortunes.list.length);
10
- return fortunes.list[r];
11
- };
12
+ function fortune() {
13
+ return fortunes[Math.floor(Math.random() * fortunes.length)];
14
+ }
12
15
 
13
- module.exports = fortune;
14
- })();
16
+ // 0.1.x exported an object with a single .fortune() method, so both
17
+ // fortune() and fortune.fortune() have to keep working.
18
+ fortune.fortune = fortune;
19
+
20
+ module.exports = fortune;
@@ -0,0 +1,7 @@
1
+ // ESM entry point. The implementation is CommonJS, so this wrapper just
2
+ // re-exports it with real named exports; without it, `import { fortune }`
3
+ // would not be statically analyzable.
4
+ import fortune from './fortune.js';
5
+
6
+ export default fortune;
7
+ export { fortune };
package/package.json CHANGED
@@ -1,22 +1,37 @@
1
1
  {
2
2
  "name": "fortune-teller",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Fortune for Node.js",
5
5
  "main": "./lib/fortune.js",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./lib/fortune.mjs",
9
+ "require": "./lib/fortune.js",
10
+ "default": "./lib/fortune.js"
11
+ },
12
+ "./package.json": "./package.json"
13
+ },
6
14
  "scripts": {
7
- "postinstall": "node lib/convert"
15
+ "build": "node lib/build-data.js"
8
16
  },
9
17
  "repository": {
10
18
  "type": "git",
11
- "url": "https://github.com/williamfligor/fortune"
19
+ "url": "git+https://github.com/williamfligor/fortune.git"
12
20
  },
13
21
  "keywords": [
14
22
  "fortune"
15
23
  ],
16
24
  "author": "William Fligor <will@fligor.us> (http://williamfligor.com/)",
17
- "license": "ISC",
25
+ "license": "BSD-3-Clause",
18
26
  "bugs": {
19
27
  "url": "https://github.com/williamfligor/fortune/issues"
20
28
  },
21
- "homepage": "https://github.com/williamfligor/fortune"
29
+ "homepage": "https://github.com/williamfligor/fortune",
30
+ "files": [
31
+ "lib/fortune.js",
32
+ "lib/fortune.mjs",
33
+ "lib/build-data.js",
34
+ "third-party/",
35
+ "data/"
36
+ ]
22
37
  }
@@ -0,0 +1,178 @@
1
+ # $NetBSD: Notes,v 1.2 1995/03/23 08:28:26 cgd Exp $
2
+ # @(#)Notes 8.1 (Berkeley) 5/31/93
3
+
4
+ Warning:
5
+ The fortunes contained in the fortune database have been collected
6
+ haphazardly from a cacophony of sources, in number so huge it
7
+ boggles the mind. It is impossible to do any meaningful quality
8
+ control on attributions, or lack thereof, or exactness of the quote.
9
+ Since this database is not used for profit, and since entire works
10
+ are not published, it falls under fair use, as we understand it.
11
+ However, if any half-assed idiot decides to make a profit off of
12
+ this, they will need to double check it all, and nobody not involved
13
+ of such an effort makes any warranty that anything in the database
14
+ bears any relation to the real world of literature, law, or other
15
+ bizzarrity.
16
+
17
+ ==> GENERAL INFORMATION
18
+ By default, fortune retrieves its fortune files from the directory
19
+ /usr/local/share/games/fortune. A fortune file has two parts: the source file
20
+ (which contains the fortunes themselves) and the data file which describes
21
+ the fortunes. The data fil always has the same name as the fortune file
22
+ with the string ".dat" concatenated, e.g. if "fort" is a standard fortune
23
+ database, then "fort.dat" is the data file which describes it. See
24
+ strfile(8) for more information on creating the data files.
25
+ Fortunes are split into potentially offensive and not potentially
26
+ offensive parts. The offensive version of a file has the same name as the
27
+ non-offensive version but exists in the offensive fortunes directory
28
+ (/usr/local/share/games/fortune/off by default). The fortune program
29
+ automatically assumes that any file in the offensive fortune directory
30
+ is potentially offensive, and should therefore only be displayed if
31
+ explicitly requested, either with the -o option, by specifying a file name
32
+ on the command line, or by appending "-o" to the name.
33
+ Potentially offensive fortune files should NEVER be maintained in
34
+ clear text on the system. They are rotated (see caesar(6)) 13 positions.
35
+ To create a new, potentially offensive database, use caesar to rotate it,
36
+ and then create its data file with the -x option to strfile(8). The fortune
37
+ program automatically decrypts the text when it prints entries from such
38
+ databases.
39
+ Anything which would not make it onto network prime time programming
40
+ (or which would only be broadcast if some discredited kind of guy said it)
41
+ MUST be in the potentially offensive database. Fortunes containing any
42
+ explicit language (see George Carlin's recent updated list) MUST be in the
43
+ potentially offensive database. Political and religious opinions are often
44
+ sequestered in the potentially offensive section as well. Anything which
45
+ assumes as a world view blatantly racist, mysogynist (sexist), or homophobic
46
+ ideas should not be in either, since they are not really funny unless *you*
47
+ are racist, mysogynist, or homophobic.
48
+ The point of this is that people have should have a reasonable
49
+ expectation that, should they just run "fortune", they will not be offended.
50
+ We know that some people take offense at anything, but normal people do have
51
+ opinions, too, and have a right not to have their sensibilities offended by
52
+ a program which is supposed to be entertaining. People who run "fortune
53
+ -o" or "fortune -a" are saying, in effect, that they are willing to have
54
+ their sensibilities tweaked. However, they should not have their personal
55
+ worth seriously (i.e., not in jest) assaulted. Jokes which depend for their
56
+ humor on racist, mysogynist, or homophobic stereotypes *do* seriously
57
+ assault individual personal worth, and in an general entertainment medium
58
+ we should be able to get by without it.
59
+
60
+ ==> FORMATTING
61
+ This file describes the format for fortunes in the database. This
62
+ is done in detail to make it easier to keep track of things. Any rule given
63
+ here may be broken to make a better joke.
64
+
65
+ [All examples are indented by one tab stop -- KCRCA]
66
+
67
+ Numbers should be given in parentheses, e.g.,
68
+
69
+ (1) Everything depends.
70
+ (2) Nothing is always.
71
+ (3) Everything is sometimes.
72
+
73
+ Attributions are two tab stops, followed by two hyphens, followed by a
74
+ space, followed by the attribution, and are *not* preceded by blank
75
+ lines. Book, journal, movie, and all other titles are in quotes, e.g.,
76
+
77
+ $100 invested at 7% interest for 100 years will become $100,000, at
78
+ which time it will be worth absolutely nothing.
79
+ -- Lazarus Long, "Time Enough for Love"
80
+
81
+ Attributions which do not fit on one (72 char) line should be continued
82
+ on a line which lines up below the first text of the attribution, e.g.,
83
+
84
+ -- A very long attribution which might not fit on one
85
+ line, "Ken Arnold's Stupid Sayings"
86
+
87
+ Single paragraph fortunes are in left justified (non-indented) paragraphs
88
+ unless they fall into another category listed below (see example above).
89
+ Longer fortunes should also be in left justified paragraphs, but if this
90
+ makes it too long, try indented paragraphs, with indentations of either one
91
+ tab stop or 5 chars. Indentations of less than 5 are too hard to read.
92
+
93
+ Laws have the title left justified and capitalized, followed by a colon,
94
+ with all the text of the law itself indented one tab stop, initially
95
+ capitalized, e.g.,
96
+
97
+ A Law of Computer Programming:
98
+ Make it possible for programmers to write in English and
99
+ you will find the programmers cannot write in English.
100
+
101
+ Limericks are indented as follows, all lines capitalized:
102
+
103
+ A computer, to print out a fact,
104
+ Will divide, multiply, and subtract.
105
+ But this output can be
106
+ No more than debris,
107
+ If the input was short of exact.
108
+
109
+ Accents precede the letter they are over, e.g., "`^He" for e with a grave
110
+ accent. Underlining is done on a word-by-word basis, with the underlines
111
+ preceding the word, e.g., "__^H^Hhi ____^H^H^H^Hthere".
112
+
113
+ No fortune should run beyond 72 characters on a single line without good
114
+ justification (er, no pun intended). And no right margin justification,
115
+ either. Sorry. For BSD people, there is a program called "fmt" which can
116
+ make this kind of formatting easier.
117
+
118
+ Definitions are given with the word or phrase left justified, followed by
119
+ the part of speech (if appropriate) and a colon. The definition starts
120
+ indented by one tab stop, with subsequent lines left justified, e.g.,
121
+
122
+ Afternoon, n.:
123
+ That part of the day we spend worrying about how we wasted
124
+ the morning.
125
+
126
+ Quotes are sometimes put around statements which are funnier or make more
127
+ sense if they are understood as being spoken, rather than written,
128
+ communication, e.g.,
129
+
130
+ "All my friends and I are crazy. That's the only thing that
131
+ keeps us sane."
132
+
133
+ Ellipses are always surrounded by spaces, except when next to punctuation,
134
+ and are three dots long.
135
+
136
+ "... all the modern inconveniences ..."
137
+ -- Mark Twain
138
+
139
+ Human initials always have spaces after the periods, e.g, "P. T. Barnum",
140
+ not "P.T. Barnum". However, "P.T.A.", not "P. T. A.".
141
+
142
+ All fortunes should be attributed, but if and only if they are original with
143
+ somebody. Many people have said things that are folk sayings (i.e., are
144
+ common among the folk (i.e., us common slobs)). There is nothing wrong with
145
+ this, of course, but such statements should not be attributed to individuals
146
+ who did not invent them.
147
+
148
+ Horoscopes should have the sign indented by one tab stop, followed by the
149
+ dates of the sign, with the text left justified below it, e.g.,
150
+
151
+ AQUARIUS (Jan 20 - Feb 18)
152
+ You have an inventive mind and are inclined to be progressive. You
153
+ lie a great deal. On the other hand, you are inclined to be
154
+ careless and impractical, causing you to make the same mistakes over
155
+ and over again. People think you are stupid.
156
+
157
+ Single quotes should not be used except as quotes within quotes. Not even
158
+ single quotes masquerading as double quotes are to be used, e.g., don't say
159
+ ``hi there'' or `hi there' or 'hi there', but "hi there". However, you
160
+ *can* say "I said, `hi there'".
161
+
162
+ A long poem or song can be ordered as follows in order to make it fit on a
163
+ screen (fortunes should be 19 lines or less if at all possible) (numbers
164
+ here are stanza numbers):
165
+
166
+ 11111111111111111111
167
+ 11111111111111111111
168
+ 11111111111111111111 22222222222222222222
169
+ 11111111111111111111 22222222222222222222
170
+ 22222222222222222222
171
+ 33333333333333333333 22222222222222222222
172
+ 33333333333333333333
173
+ 33333333333333333333 44444444444444444444
174
+ 33333333333333333333 44444444444444444444
175
+ 44444444444444444444
176
+ 44444444444444444444
177
+
178
+
@@ -0,0 +1,19 @@
1
+ # fortune-mod 1.99.1 notices
2
+
3
+ Verbatim from the `fortune-mod-1.99.1` tarball
4
+ (<https://github.com/shlomif/fortune-mod/archive/refs/tags/fortune-mod-1.99.1.tar.gz>,
5
+ sha256 `22bfb63917192718df8929e2cb2beb5e85e7e1afbd643e6280cc138116f77a33`), so
6
+ the attribution travels with the package instead of pointing at a tarball.
7
+
8
+ - `fortune.c.license` — `fortune/fortune.c`, lines 1-37: the 4-clause BSD notice
9
+ for fortune(6), copyright 1986, 1993 The Regents of the University of
10
+ California, derived from software contributed to Berkeley by Ken Arnold.
11
+ Berkeley rescinded the advertising clause for its own code in 1999, so it is
12
+ usually quoted as BSD 3-Clause today. It covers the C program, not the
13
+ quotations.
14
+ - `Notes` — `Notes` (NetBSD, `$NetBSD: Notes,v 1.2 1995/03/23 08:28:26 cgd Exp $`):
15
+ the only statement upstream makes about the database, which was collected
16
+ haphazardly, has uncheckable attributions, and is used under fair use.
17
+
18
+ The release contains no `COPYING` or `LICENSE` file, and no file under
19
+ `datfiles/` carries a notice.
@@ -0,0 +1,37 @@
1
+ /* $NetBSD: fortune.c,v 1.8 1995/03/23 08:28:40 cgd Exp $ */
2
+
3
+ /*-
4
+ * Copyright (c) 1986, 1993
5
+ * The Regents of the University of California. All rights reserved.
6
+ *
7
+ * This code is derived from software contributed to Berkeley by
8
+ * Ken Arnold.
9
+ *
10
+ * Redistribution and use in source and binary forms, with or without
11
+ * modification, are permitted provided that the following conditions
12
+ * are met:
13
+ * 1. Redistributions of source code must retain the above copyright
14
+ * notice, this list of conditions and the following disclaimer.
15
+ * 2. Redistributions in binary form must reproduce the above copyright
16
+ * notice, this list of conditions and the following disclaimer in the
17
+ * documentation and/or other materials provided with the distribution.
18
+ * 3. All advertising materials mentioning features or use of this software
19
+ * must display the following acknowledgement:
20
+ * This product includes software developed by the University of
21
+ * California, Berkeley and its contributors.
22
+ * 4. Neither the name of the University nor the names of its contributors
23
+ * may be used to endorse or promote products derived from this software
24
+ * without specific prior written permission.
25
+ *
26
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36
+ * SUCH DAMAGE.
37
+ */
package/.npmignore DELETED
@@ -1,27 +0,0 @@
1
- # Logs
2
- logs
3
- *.log
4
-
5
- # Runtime data
6
- pids
7
- *.pid
8
- *.seed
9
-
10
- # Directory for instrumented libs generated by jscoverage/JSCover
11
- lib-cov
12
-
13
- # Coverage directory used by tools like istanbul
14
- coverage
15
-
16
- # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17
- .grunt
18
-
19
- # Compiled binary addons (http://nodejs.org/api/addons.html)
20
- build/Release
21
-
22
- # Dependency directory
23
- # Deployed apps should consider commenting this line out:
24
- # see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
25
- node_modules
26
-
27
- build