-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssv.js
166 lines (146 loc) · 2.88 KB
/
ssv.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
/** @preserve npm.im/ssv */
!function(root) {
var ssv = {}
var own = {}.hasOwnProperty
var word = /\S+/g
var space = " "
var empty = ""
function say(set) {
return set == null ? empty : empty + set
}
function match(set) {
return say(set).match(word)
}
function split(set) {
return match(set) || []
}
function jam(set) {
return split(set).join(space)
}
function count(set) {
return split(set).length
}
function blank(set) {
return !match(set)
}
function any(set, search) {
search = split(search)
var l = search.length
if (!l) return false
set = split(set)
var n = set.length
var j = 0
while (j < n) {
var i = l
var v = set[j++]
while (i--)
if (v === search[i])
return true
}
return false
}
function all(set, search) {
return !not(search, set)
}
function at(set, i) {
i = +i
if (i != i || i == i/0) return empty
set = split(set)
if (i < 0) i += set.length
return set[i] || empty
}
function gum(set, more) {
return jam(say(set) + space + say(more))
}
function or(set, more) {
return yolo(say(set) + space + say(more))
}
function xor(left, right) {
return or(
not(left, right),
not(right, left))
}
function and(left, right) {
return not(
or(left, right),
xor(left, right))
}
function yolo(set) {
set = split(set)
var n = 0
var u = []
var l = set.length
var i = 0
outer:while (i < l) {
var v = set[i++]
var j = n
while (j--)
if (u[j] === v)
continue outer
u[n++] = v
}
return u.join(space)
}
function not(set, less) {
var d = empty
set = split(set)
less = split(less)
var n = set.length
var l = less.length
var j = 0
outer:while (j < n) {
var i = l
var v = set[j++]
while (i--)
if (v === less[i])
continue outer
d ? d += space + v : d = v
}
return d
}
function edit(set, boss) {
var yes = empty
var noo = empty
if (typeof boss == "string")
yes = boss
else for (var key in boss)
if (own.call(boss, key))
boss[key]
? yes += space + key
: noo += space + key
var eco = set === yes
var emo = set === empty
var ace = eco || emo || !noo
set = ace ? set : not(set, noo)
return !yes || eco
? emo ? set : yolo(set)
: or(set, yes)
}
function state(set) {
return edit(empty, set)
}
function give(f) {
var method = f.name
ssv[method] = f
}
give(all)
give(and)
give(any)
give(at)
give(blank)
give(count)
give(edit)
give(gum)
give(jam)
give(not)
give(or)
give(say)
give(split)
give(state)
give(xor)
give(yolo)
typeof module != "undefined"
&& module.exports
? module.exports = ssv
: root["ssv"] = ssv
}(this)