show-a-license 1.0.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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +226 -0
  3. package/lib/index.js +194 -0
  4. package/package.json +148 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-22 Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ <!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+ # show-a-license
21
+
22
+ [![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations] [![Ask me anything](https://img.shields.io/badge/ask%20me-anything-1abc9c.svg)](https://github.com/IonicaBizau/ama) [![Version](https://img.shields.io/npm/v/show-a-license.svg)](https://www.npmjs.com/package/show-a-license) [![Downloads](https://img.shields.io/npm/dt/show-a-license.svg)](https://www.npmjs.com/package/show-a-license) [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/johnnyb?utm_source=github&utm_medium=button&utm_term=johnnyb&utm_campaign=github)
23
+
24
+ <a href="https://www.buymeacoffee.com/H96WwChMy" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" alt="Buy Me A Coffee"></a>
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ > A site to provide an easy way to show licenses and their human-readable explanations.
33
+
34
+
35
+
36
+
37
+
38
+
39
+ ## Your help is needed! :heart:
40
+
41
+
42
+ Contribute by explaining licenses. Check out [this issue](https://github.com/IonicaBizau/show-the-license/issues/1). :memo: :book:
43
+
44
+ ## Usage
45
+
46
+
47
+ Whether you just want to show a license or see its human-readable explanation, you can use this website. It provides a nice querystring API documented below:
48
+
49
+
50
+ - `#license-<license>` (hash): set the license to display
51
+ - `fullname=<name>`: set the copyright holder name
52
+ - `year=<name>`: set the starting copyright yea
53
+ - `hide_explanations=<true|false>` (default: `false`): hide the explanations column
54
+
55
+ ## Developer installation
56
+
57
+
58
+ - `cd build; node update-licenses-list.js; cd ..`
59
+ - In the end, run in parallel `npm run watch` and `npm start`
60
+ - Open in your browser [http://localhost:9000/index.html](http://localhost:9000/index.html).
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+ [![show-a-license](http://i.imgur.com/AB42LJo.png)](#)
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+ ## Examples
91
+
92
+
93
+ - To see the MIT license access this url: https://ionicabizau.github.io/show-a-license#license-mit
94
+ - To set the copyright holder name, use the `fullname=<name>` querystring parameter: https://ionicabizau.github.io/show-a-license?fullname=Alice#license-mit
95
+ - To set the starting copyright year use the `year` parameter: https://ionicabizau.github.io/show-a-license?year=2013&fullname=Alice#license-mit
96
+ - To hide the explanations column, you have to use `hide_explanations=true`: https://ionicabizau.github.io/show-a-license?hide_explanations=true&year=2013&fullname=Alice#license-mit
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+ ## :question: Get Help
105
+
106
+ There are few ways to get help:
107
+
108
+
109
+
110
+ 1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
111
+ 2. For bug reports and feature requests, open issues. :bug:
112
+ 3. For direct and quick help, you can [use Codementor](https://www.codementor.io/johnnyb). :rocket:
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+ ## :yum: How to contribute
130
+ Have an idea? Found a bug? See [how to contribute][contributing].
131
+
132
+
133
+ ## :sparkling_heart: Support my projects
134
+ I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously,
135
+ this takes time. You can integrate and use these projects in your applications *for free*! You can even change the source code and redistribute (even resell it).
136
+
137
+ However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
138
+
139
+
140
+ - Starring and sharing the projects you like :rocket:
141
+ - [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book:
142
+ - [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:
143
+ - [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
144
+ - **Bitcoin**—You can send me bitcoins at this address (or scanning the code below): `1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`
145
+
146
+ ![](https://i.imgur.com/z6OQI95.png)
147
+
148
+
149
+ Thanks! :heart:
150
+
151
+
152
+
153
+
154
+ ### Explaining a license
155
+
156
+
157
+ Explanations are kept in `txt` files in the [`explanations`](/explanations) directory, having the license names (e.g. `mit.txt`).
158
+
159
+
160
+ Contributions in this directions are really appreciated.
161
+
162
+
163
+ 1. Fork this repository.
164
+ 2. Edit the `explanations/<license>.txt` file (you can follow [`explanations/mit.txt`](/explanations/mit.txt) as example).
165
+ 3. Add yourself as contributor in [`package.json`](/package.json).
166
+ 4. Raise a pull request! :tada:
167
+
168
+ ### Adding a new license
169
+
170
+
171
+ If the license you're searching for is missing, make sure you add it.
172
+
173
+
174
+ 1. Fork this repository.
175
+ 2. Add a new file in the [`licenses`](/licenses) directory, named `<license>.txt` (replace `<license>` with the license name) and then do the same in the [`explanations`](/explanations) directory (you can follow the MIT license example: see [`explanations/mit.txt`](/explanations/mit.txt) and [`licenses/mit.txt`](/licenses/mit.txt)).
176
+ 3. Give nice, funny and useful explanation in the `explanations/<license>.txt` file you added.
177
+ 4. Add yourself as contributor in [`package.json`](/package.json).
178
+ 5. Raise a pull request! :tada:
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+ ## :cake: Thanks
187
+
188
+ - [github/choosealicense.com](https://github.com/github/choosealicense.com)–a good inspiration source (some ideas and CSS were taken from here) :sparkle:
189
+ - [**@Cerberus-tm**](https://github.com/Cerberus-tm)–who had the idea for the site name :cake:
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+ ## :scroll: License
208
+
209
+ [MIT][license] © [Ionică Bizău][website]
210
+
211
+
212
+
213
+
214
+
215
+
216
+ [license]: /LICENSE
217
+ [website]: https://ionicabizau.net
218
+ [contributing]: /CONTRIBUTING.md
219
+ [docs]: /DOCUMENTATION.md
220
+ [badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg
221
+ [badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg
222
+ [badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg
223
+ [badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg
224
+ [patreon]: https://www.patreon.com/ionicabizau
225
+ [amazon]: http://amzn.eu/hRo9sIZ
226
+ [paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW
package/lib/index.js ADDED
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+
3
+ // Dependencies
4
+ var $ = require("elm-select"),
5
+ _fetch = require("whatwg-fetch"),
6
+ sameTime = require("same-time"),
7
+ barbe = require("barbe"),
8
+ Err = require("err"),
9
+ yearRange = require("year-range");
10
+
11
+ // Constants
12
+ var HASH_PREFIX = "#license-";
13
+
14
+ // Get the elements
15
+ var licenseTable = $(".license-view table")[0],
16
+ tableTbody = $("tbody", licenseTable)[0],
17
+ viewExplanationsEl = $("tfoot", licenseTable)[0],
18
+ searchLicenseEl = $("input.search-license-name.awesomplete")[0],
19
+ linkLicenseEl = $("input.link-license-name.awesomplete")[0];
20
+ form = $('form')[0];
21
+
22
+ var licenses = _licenses.join(",");
23
+
24
+ searchLicenseEl.setAttribute("data-list", licenses);
25
+ linkLicenseEl.setAttribute("data-list", licenses);
26
+
27
+ searchLicenseEl.addEventListener("awesomplete-selectcomplete", function () {
28
+ location.hash = HASH_PREFIX + this.value;
29
+
30
+ // If the user starts by opening the `this.value` license, I suppose he will
31
+ // want to build a link to the same license after he comes back from the
32
+ // license page, so I set the license page link editor's license field to
33
+ // the same value.
34
+ linkLicenseEl.value = this.value;
35
+ });
36
+
37
+ form.addEventListener('submit', function (evt) {
38
+ form.action = HASH_PREFIX + linkLicenseEl.value;
39
+ }, false);
40
+
41
+ // Config
42
+ var showExplanations;
43
+
44
+ function checkExplanationState() {
45
+ showExplanations = Url.queryString("hide_explanations") !== "true";
46
+ if (showExplanations) {
47
+ $(".text", viewExplanationsEl)[0].innerHTML = "Hide explanations";
48
+ } else {
49
+ $(".text", viewExplanationsEl)[0].innerHTML = "Show explanations";
50
+ }
51
+ }
52
+
53
+ // Handle the view explanation url
54
+ viewExplanationsEl.addEventListener("click", function (e) {
55
+ e.preventDefault();
56
+ Url.updateSearchParam("hide_explanations", showExplanations ? "true" : undefined);
57
+ location.reload();
58
+ });
59
+
60
+ function showNormalView() {
61
+ $(".license-view", function (elm) {
62
+ elm.classList.add("hide");
63
+ });
64
+ $(".main-view", function (elm) {
65
+ elm.classList.remove("hide");
66
+ });
67
+ searchLicenseEl.focus();
68
+ }
69
+
70
+ function renderInfo(c) {
71
+ var data = {},
72
+ startYear = parseInt(Url.queryString("year"));
73
+
74
+ data.year = startYear;
75
+ data.fullname = Url.queryString("fullname");
76
+
77
+ if (!data.fullname) {
78
+ delete data.fullname;
79
+ }
80
+
81
+ if (data.year) {
82
+ data.year = yearRange(data.year);
83
+ } else {
84
+ delete data.year;
85
+ }
86
+
87
+ return barbe(c, ["[", "]"], data).replace(/</g, "&lt;").replace(/>/g, "&gt;");
88
+ }
89
+
90
+ function doRequest(url) {
91
+ return function (done) {
92
+ fetch(url).then(function (res) {
93
+ if (res.status === 404) {
94
+ throw new Err("Not found: " + url, 404);
95
+ }
96
+ if (res.status >= 400) {
97
+ throw new Err("Failed to fetch the url: " + url, res.status);
98
+ }
99
+ return res.text();
100
+ }).then(function (text) {
101
+ done(null, renderInfo(text));
102
+ }).catch(done);
103
+ };
104
+ }
105
+
106
+ function getLicense(license, fn) {
107
+ sameTime([doRequest("/licenses/" + license + ".txt"), doRequest("/explanations/" + license + ".txt")], function (err, data) {
108
+ if (err) {
109
+ return fn(err);
110
+ }
111
+ data = data.map(function (c) {
112
+ return c.split("\n\n");
113
+ });
114
+ fn(null, {
115
+ license: data[0],
116
+ explanation: data[1]
117
+ });
118
+ });
119
+ }
120
+
121
+ function showError(err) {
122
+ err = err[0] || err;
123
+ var sweetErr = {
124
+ title: "Oops...",
125
+ text: err.toString(),
126
+ type: "error",
127
+ html: true
128
+ };
129
+
130
+ // License not found
131
+ if (err.code === 404) {
132
+ sweetErr.text = "Cannot find such a licence. Feel free to <a href='https://github.com/IonicaBizau/show-a-license#adding-a-new-license'>add it</a>.";
133
+ location.hash = "";
134
+ } else if (err.code === "EXPLANATION_DOES_NOT_EXIST") {
135
+ sweetErr.type = "warning";
136
+ sweetErr.text = "This license doesn't have any explanation. Feel free to <a href='https://github.com/IonicaBizau/show-a-license#explaining-a-license'>add it</a>.";
137
+ }
138
+
139
+ // Show the error
140
+ sweetAlert(sweetErr);
141
+ }
142
+
143
+ function renderLicense(err, data) {
144
+
145
+ if (err) {
146
+ return showError(err);
147
+ }
148
+
149
+ if (showExplanations) {
150
+ if (!data.explanation.join("")) {
151
+ showError(new Err("Explanation doesn't exist. You can add it ", "EXPLANATION_DOES_NOT_EXIST"));
152
+ showExplanations = false;
153
+ Url.updateSearchParam("hide_explanations", true);
154
+ checkExplanationState();
155
+ } else {
156
+ licenseTable.classList.remove("shadow");
157
+ }
158
+ }
159
+
160
+ var html = "";
161
+ data.license.forEach(function (c, i) {
162
+ html += "<tr>";
163
+ if (showExplanations) {
164
+ html += "<td class='explanation'>" + data.explanation[i] + "</td>";
165
+ }
166
+ html += "<td><pre>" + c + "</pre></td>";
167
+ html += "</tr>";
168
+ });
169
+
170
+ tableTbody.innerHTML = html;
171
+ }
172
+
173
+ function showLicenseView(license) {
174
+ getLicense(license, renderLicense);
175
+ $(".main-view", function (elm) {
176
+ elm.classList.add("hide");
177
+ });
178
+ $(".license-view", function (elm) {
179
+ elm.classList.remove("hide");
180
+ });
181
+ }
182
+
183
+ function checkHash() {
184
+ var hash = location.hash;
185
+ if (hash.indexOf(HASH_PREFIX) !== 0) {
186
+ return showNormalView();
187
+ }
188
+ var license = hash.substring(HASH_PREFIX.length).toLowerCase();
189
+ showLicenseView(license);
190
+ checkExplanationState();
191
+ }
192
+
193
+ window.addEventListener("hashchange", checkHash);
194
+ window.addEventListener("load", checkHash);
package/package.json ADDED
@@ -0,0 +1,148 @@
1
+ {
2
+ "name": "show-a-license",
3
+ "version": "1.0.0",
4
+ "description": "A site to provide an easy way to show licenses and their human-readable explanations.",
5
+ "main": "lib/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "start": "statique -p 9000",
9
+ "watch": "watchify lib/index.js -o js/index.js -v"
10
+ },
11
+ "author": "Ionică Bizău <bizauionica@gmail.com> (https://ionicabizau.net)",
12
+ "contributors": [
13
+ "Silviu Bogan <silviubogan@gmail.com> (https://lumea-lui-silviu.blogspot.ro)"
14
+ ],
15
+ "license": "MIT",
16
+ "blah": {
17
+ "ex_img": "http://i.imgur.com/AB42LJo.png",
18
+ "description": [
19
+ {
20
+ "h2": "Your help is needed! :heart:"
21
+ },
22
+ {
23
+ "p": "Contribute by explaining licenses. Check out [this issue](https://github.com/IonicaBizau/show-the-license/issues/1). :memo: :book:"
24
+ },
25
+ {
26
+ "h2": "Usage"
27
+ },
28
+ {
29
+ "p": "Whether you just want to show a license or see its human-readable explanation, you can use this website. It provides a nice querystring API documented below:"
30
+ },
31
+ {
32
+ "ul": [
33
+ "`#license-<license>` (hash): set the license to display",
34
+ "`fullname=<name>`: set the copyright holder name",
35
+ "`year=<name>`: set the starting copyright yea",
36
+ "`hide_explanations=<true|false>` (default: `false`): hide the explanations column"
37
+ ]
38
+ },
39
+ {
40
+ "h2": "Developer installation"
41
+ },
42
+ {
43
+ "ul": [
44
+ "`cd build; node update-licenses-list.js; cd ..`",
45
+ "In the end, run in parallel `npm run watch` and `npm start`",
46
+ "Open in your browser [http://localhost:9000/index.html](http://localhost:9000/index.html)."
47
+ ]
48
+ }
49
+ ],
50
+ "example": [
51
+ {
52
+ "h2": "Examples"
53
+ },
54
+ {
55
+ "ul": [
56
+ "To see the MIT license access this url: https://ionicabizau.github.io/show-a-license#license-mit",
57
+ "To set the copyright holder name, use the `fullname=<name>` querystring parameter: https://ionicabizau.github.io/show-a-license?fullname=Alice#license-mit",
58
+ "To set the starting copyright year use the `year` parameter: https://ionicabizau.github.io/show-a-license?year=2013&fullname=Alice#license-mit",
59
+ "To hide the explanations column, you have to use `hide_explanations=true`: https://ionicabizau.github.io/show-a-license?hide_explanations=true&year=2013&fullname=Alice#license-mit"
60
+ ]
61
+ }
62
+ ],
63
+ "contributing": [
64
+ {
65
+ "h3": "Explaining a license"
66
+ },
67
+ {
68
+ "p": "Explanations are kept in `txt` files in the [`explanations`](/explanations) directory, having the license names (e.g. `mit.txt`)."
69
+ },
70
+ {
71
+ "p": "Contributions in this directions are really appreciated."
72
+ },
73
+ {
74
+ "ol": [
75
+ "Fork this repository.",
76
+ "Edit the `explanations/<license>.txt` file (you can follow [`explanations/mit.txt`](/explanations/mit.txt) as example).",
77
+ "Add yourself as contributor in [`package.json`](/package.json).",
78
+ "Raise a pull request! :tada:"
79
+ ]
80
+ },
81
+ {
82
+ "h3": "Adding a new license"
83
+ },
84
+ {
85
+ "p": "If the license you're searching for is missing, make sure you add it."
86
+ },
87
+ {
88
+ "ol": [
89
+ "Fork this repository.",
90
+ "Add a new file in the [`licenses`](/licenses) directory, named `<license>.txt` (replace `<license>` with the license name) and then do the same in the [`explanations`](/explanations) directory (you can follow the MIT license example: see [`explanations/mit.txt`](/explanations/mit.txt) and [`licenses/mit.txt`](/licenses/mit.txt)).",
91
+ "Give nice, funny and useful explanation in the `explanations/<license>.txt` file you added.",
92
+ "Add yourself as contributor in [`package.json`](/package.json).",
93
+ "Raise a pull request! :tada:"
94
+ ]
95
+ }
96
+ ],
97
+ "thanks": {
98
+ "ul": [
99
+ "[github/choosealicense.com](https://github.com/github/choosealicense.com)–a good inspiration source (some ideas and CSS were taken from here) :sparkle:",
100
+ "[**@Cerberus-tm**](https://github.com/Cerberus-tm)–who had the idea for the site name :cake:"
101
+ ]
102
+ }
103
+ },
104
+ "dependencies": {
105
+ "barbe": "^2.1.0",
106
+ "elm-select": "^1.3.0",
107
+ "err": "^1.0.0",
108
+ "same-time": "^2.2.0",
109
+ "whatwg-fetch": "^0.10.1",
110
+ "year-range": "^1.1.0"
111
+ },
112
+ "devDependencies": {
113
+ "abs": "^1.1.0",
114
+ "statique": "^3.1.0",
115
+ "w-json": "^1.2.0",
116
+ "watchify": "^3.6.1"
117
+ },
118
+ "repository": {
119
+ "type": "git",
120
+ "url": "git+https://github.com/IonicaBizau/show-a-license.git"
121
+ },
122
+ "keywords": [
123
+ "license",
124
+ "show",
125
+ "understand",
126
+ "list",
127
+ "explain"
128
+ ],
129
+ "bugs": {
130
+ "url": "https://github.com/IonicaBizau/show-a-license/issues"
131
+ },
132
+ "homepage": "https://github.com/IonicaBizau/show-a-license#readme",
133
+ "files": [
134
+ "bin/",
135
+ "app/",
136
+ "lib/",
137
+ "dist/",
138
+ "src/",
139
+ "scripts/",
140
+ "resources/",
141
+ "menu/",
142
+ "cli.js",
143
+ "index.js",
144
+ "bloggify.js",
145
+ "bloggify.json",
146
+ "bloggify/"
147
+ ]
148
+ }