-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
381 lines (357 loc) · 9.44 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
document.addEventListener('DOMContentLoaded', function () {
addRegenerateButton()
addLicenseElement()
generateLicense()
})
function addRegenerateButton () {
var main = document.getElementById('main')
var button = document.createElement('button')
button.appendChild(document.createTextNode('Regenerate'))
button.addEventListener('click', function () {
generateLicense()
})
main.appendChild(button)
}
function addLicenseElement () {
var main = document.getElementById('main')
var pre = document.createElement('pre')
pre.id = 'license'
main.appendChild(pre)
}
var components = [
{
id: 'copyright',
alternatives: [
function () {
return 'Copyright' +
optional(' (c)') +
' {copyright holders}'
}
]
},
{
id: 'grant',
alternatives: [
function mitStyleGrant () {
return select([
(
select([
'Permission is hereby granted',
'Permission is granted'
]) +
' to any person obtaining a copy of this software'
),
'You are hereby licensed',
'You are licensed',
'The copyright holders hereby grant you a license',
'The copyright holders grant you a license'
]) +
optional(', free of charge,') +
' to deal in this software without restriction' +
optional(
', including without limitation the rights to ' +
list('and/or', shuffle([
'use',
'copy',
'modify',
'merge',
'publish',
'distribute',
'sublicense',
'sell copies of'
])) +
' this software'
) +
'.'
},
function bsdStyleGrant () {
return select([
'Redistribution and use',
'Use and redistribution'
]) +
' in source and binary forms,' +
' with or without modification,' +
' are permitted.'
},
function blueOakStyleGrant () {
return 'The copyright holders license you' +
' to do everything with this software' +
' that would otherwise infringe their copyright in it,' +
' and to do everything with this software' +
' that would otherwise any patents they have on it.'
}
]
},
{
id: 'notice',
alternatives: [
function mitStyleNotice () {
return 'The above copyright notice' +
' and the text of this license' +
select([
' shall be',
' must be',
' have to be',
' are required to be'
]) +
' included in all copies or substantial portions of this software' +
'.'
},
function bsdStyleNotice () {
return 'Redistributions of source code' +
' must retain ' +
list('and', shuffle([
'the above copyright notice',
'the text of this license'
])) +
'.' +
' Redistributions in binary form' +
' must reproduce ' +
list('and', shuffle([
'the above copyright notice',
'the text of this license'
])) +
' in the documentation and/or other materials' +
' provided with the distribution.'
},
function blueOakStyleNotice () {
return 'You must ensure' +
' that everyone who gets a copy' +
' of any part of this software from you,' +
' with or without changes,' +
' also gets ' +
list('and', shuffle([
'the text of this license',
'the copyright notice'
])) +
'.'
}
]
},
{
id: 'disclaimer',
conspicuous: true,
alternatives: [
function mitStyleDisclaimer () {
return 'This software' +
select([
' is provided "as is"',
' is provided as is',
' comes "as is"',
' comes as is'
]) +
' without warranty' +
optional(' or condition') +
optional(' of any kind') +
optional(', express or implied') +
optional(
', including but not limited to the warranties of ' +
list('and', shuffle([
'merchantability',
'fitness for a particular purpose',
'noninfringement'
]))
) +
'.'
},
function bsdStyleDisclaimer () {
return 'This software' +
' is provided by the ' +
list('and', shuffle([
'copyright holders',
'contributors'
])) +
select([
' "as is"' +
' as is'
]) +
' and any ' +
list(
select(['or', 'and']),
shuffle(['express', 'implied'])
) +
' warranties' +
optional(
', including, but not limited to,' +
' the implied warranties of ' +
list('and', shuffle([
'merchantability',
'fitness for a particular purpose'
])) +
','
) +
' are disclaimed. '
},
function blueOakStyleDisclaimer () {
return select([
'As far as the law allows',
'To the fullest legal extent',
(
select([
'To the limits of',
'Within the limits of'
]) +
select([
' applicable law',
' the law'
])
)
]) +
', this software comes as is, without any warranty' +
optional(' or condition') +
'.'
}
]
},
{
id: 'exclusion',
conspicuous: true,
alternatives: [
function mitStyleExclusion () {
return 'In no event' +
' shall the authors or copyright holders' +
' be liable' +
' for any ' +
select([
'claim, damages',
'damage, claim'
]) +
' or other liability,' +
' whether in an action of ' +
select([
'contract, tort',
'tort, contract'
]) +
' or otherwise,' +
' arising from, out of or in connection with ' +
list('or', shuffle([
'this software',
'the use or other dealings in this software'
])) +
'.'
},
function bsdStyleExclusion () {
return 'In no event' +
' shall the ' +
list('or', shuffle([
'copyright holders',
'contributors'
])) +
' be liable for any' +
list('or', shuffle([
'direct',
'indirect',
'incidental',
'special',
'exemplary',
'consequential'
])) +
' damages' +
optional(
'(' +
'including, but not limited to,' +
list('or', shuffle([
'procurement of ' +
list('or', shuffle([
'substitute goods', 'services'
])),
'loss of ' +
list('or', shuffle([
'use', 'data', 'profits'
])),
'business interruption'
])) +
')'
) +
' however caused and on any theory of liability' +
', whether in ' +
list('or', shuffle([
'contract',
'strict liability',
'tort (including negligence or otherwise)'
])) +
' arising in any way out of the use of this software' +
', even if advised of the possibility of such damage.'
},
function blueOakStyleExclusion () {
return 'As far as the law allows,' +
' no contributor will be liable to anyone' +
' for any damages related to this software or this license,' +
' under any kind of legal claim' +
'.'
}
]
}
]
function coinFlip () {
return Math.random() >= 0.5
}
function optional (element) {
if (coinFlip()) {
return element
} else {
return ''
}
}
function generateLicense () {
var shuffled = [components[0]]
.concat(shuffle(components.slice(1)))
var selected = shuffled.map(function (component) {
var alternative = select(component.alternatives)
var type = typeof alternative
var text
if (type === 'string') {
text = alternative
} else if (type === 'function') {
text = alternative()
}
if (component.conspicuous) {
text = text.toUpperCase()
}
return text
})
var text = selected.join('\n\n') + '\n'
if (coinFlip()) {
text = britify(text)
}
displayLicense(text)
}
function britify (string) {
return string
.replace(/license/g, 'licence')
.replace(/License/g, 'Licence')
}
function displayLicense (text) {
var license = document.getElementById('license')
license.innerHTML = ''
license.appendChild(document.createTextNode(text))
}
function list (conjunction, items) {
var length = items.length
if (length === 0) {
return ''
} else if (length === 1) {
return items[0]
} else if (length === 2) {
return items[0] + ' ' + conjunction + ' ' + items[1]
} else {
return items.slice(0, length - 1).join(', ') + ', ' + conjunction + ' ' + items[items.length - 1]
}
}
function random (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min
}
function select (array) {
return array[random(0, array.length - 1)]
}
function shuffle (array) {
var length = array.length
var last = length - 1
for (var index = 0; index < length; index++) {
var rand = random(index, last)
var temp = array[index]
array[index] = array[rand]
array[rand] = temp
}
return array
}