-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (81 loc) · 2.31 KB
/
index.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
var outline = require('outline-numbering')
function withinAgreement (numbering) {
var first = numbering[0]
return (
first.series.number === 1 &&
first.element.number === 1)
}
function withinSchedules (numbering) {
var first = numbering[0]
return (
first.series.number === 1 &&
first.element.number === 2)
}
function stripNounPrefix (string) {
return string.replace('Section\u00a0', '')
}
module.exports = function (numbering, shortForm) {
var length = numbering.length
if (length < 1) {
throw new Error('Invalid numbering')
}
var first = numbering[0]
if (withinAgreement(numbering)) {
if (length === 1) {
return (shortForm ? 'Agreement.' : 'the Agreement')
} else {
return (
(!shortForm ? 'Section\u00a0' : '') +
stripNounPrefix(outline(numbering.slice(1), shortForm)) +
(!shortForm ? ' of the Agreement' : ''))
}
} else if (withinSchedules(numbering)) {
if (length === 1) {
return (shortForm ? 'Schedules.' : 'Schedules to the Agreement')
} else {
var scheduleNumber = (
'Schedule\u00a0' +
outline([numbering[1]], shortForm)
.replace('Section\u00a0', ''))
if (length === 2) {
return scheduleNumber
} else {
return (
(!shortForm ? 'Section\u00a0' : '') +
stripNounPrefix(outline(numbering.slice(2), shortForm)) +
(!shortForm ? (' of ' + scheduleNumber) : ''))
}
}
} else {
var inFirstSeries = (numbering[0].series.number === 1)
var exhibitNumber = (
'Exhibit\u00a0' +
stripNounPrefix(
outline(
[
{
series: {
number: first.series.number,
of: first.series.of
},
element: {
number: inFirstSeries
? (first.element.number - 2)
: first.element.number,
of: inFirstSeries
? (first.element.of - 2)
: first.element.of
}
}
],
shortForm)))
if (length === 1) {
return exhibitNumber
} else {
return (
(!shortForm ? 'Section\u00a0' : '') +
stripNounPrefix(outline(numbering.slice(1), shortForm)) +
(!shortForm ? (' of ' + exhibitNumber) : ''))
}
}
}