conjur-asset-ui 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.git-hooks/pre_commit/ensure_livescript_compiled.rb +31 -0
- data/.git-hooks/pre_commit/trailing_whitespace.rb +26 -0
- data/.gitignore +20 -0
- data/.overcommit.yml +5 -0
- data/.project +18 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +3 -0
- data/compile_ls +6 -0
- data/conjur-asset-ui.gemspec +37 -0
- data/lib/conjur/command/ui.rb +46 -0
- data/lib/conjur/webserver/api_proxy.rb +94 -0
- data/lib/conjur/webserver/authorize.rb +28 -0
- data/lib/conjur/webserver/conjur_info.rb +33 -0
- data/lib/conjur/webserver/home.rb +42 -0
- data/lib/conjur/webserver/login.rb +57 -0
- data/lib/conjur/webserver/renderer.rb +34 -0
- data/lib/conjur/webserver/server.rb +113 -0
- data/lib/conjur-asset-ui-version.rb +7 -0
- data/lib/conjur-asset-ui.rb +7 -0
- data/livescript/views/audit.ls +136 -0
- data/public/_client_code.html +42 -0
- data/public/_client_libs.html +24 -0
- data/public/css/bootstrap.css +7 -0
- data/public/css/styles.less +461 -0
- data/public/fonts/glyphicons-halflings-regular.eot +0 -0
- data/public/fonts/glyphicons-halflings-regular.svg +229 -0
- data/public/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/public/fonts/glyphicons-halflings-regular.woff +0 -0
- data/public/images/conjur-logo.svg +26 -0
- data/public/images/icon-client-pc.svg +12 -0
- data/public/images/icon-environment.png +0 -0
- data/public/images/icon-person.svg +12 -0
- data/public/images/icon-policy.png +0 -0
- data/public/images/icon-resource.png +0 -0
- data/public/images/icon-service-dots.svg +13 -0
- data/public/images/icon-variable.png +0 -0
- data/public/index.html.erb +62 -0
- data/public/js/init.js +107 -0
- data/public/js/lib/JSXTransformer.js +10862 -0
- data/public/js/lib/async.js +958 -0
- data/public/js/lib/backbone.js +2 -0
- data/public/js/lib/bootstrap.js +6 -0
- data/public/js/lib/date.extensions.js +141 -0
- data/public/js/lib/less.js +16 -0
- data/public/js/lib/moment.js +7768 -0
- data/public/js/lib/pace.js +2 -0
- data/public/js/lib/prelude-browser-min.js +1 -0
- data/public/js/lib/react-bootstrap.js +5346 -0
- data/public/js/lib/react-bootstrap.min.js +4 -0
- data/public/js/lib/sorted-set.no-require.js +1170 -0
- data/public/js/lib/sorted-set.no-require.js.txt +6 -0
- data/public/js/lib/underscore-min.js +6 -0
- data/public/js/lib/underscore.string.min.js +1 -0
- data/public/js/main.js +57 -0
- data/public/js/models/groupRecord.js +70 -0
- data/public/js/models/hostRecord.js +55 -0
- data/public/js/models/layerRecord.js +77 -0
- data/public/js/models/namespace.js +10 -0
- data/public/js/models/policyList.js +14 -0
- data/public/js/models/policyRecord.js +54 -0
- data/public/js/models/record.js +85 -0
- data/public/js/models/resourceList.js +69 -0
- data/public/js/models/userList.js +20 -0
- data/public/js/models/userRecord.js +70 -0
- data/public/js/models/variableList.js +16 -0
- data/public/js/models/variableRecord.js +73 -0
- data/public/js/routers.js +205 -0
- data/public/js/views/annotations.js +36 -0
- data/public/js/views/audit.js +363 -0
- data/public/js/views/dashboard.js +67 -0
- data/public/js/views/generic.js +115 -0
- data/public/js/views/group.js +61 -0
- data/public/js/views/groups.js +30 -0
- data/public/js/views/host.js +64 -0
- data/public/js/views/hosts.js +30 -0
- data/public/js/views/layer.js +92 -0
- data/public/js/views/layers.js +30 -0
- data/public/js/views/mixins/search.js +15 -0
- data/public/js/views/mixins/tabs.js +114 -0
- data/public/js/views/namespaces.js +40 -0
- data/public/js/views/navSearch.js +25 -0
- data/public/js/views/owned.js +178 -0
- data/public/js/views/permissions.js +188 -0
- data/public/js/views/policies.js +28 -0
- data/public/js/views/policy.js +43 -0
- data/public/js/views/resource.js +39 -0
- data/public/js/views/role.js +41 -0
- data/public/js/views/searchResults.js +145 -0
- data/public/js/views/time.js +14 -0
- data/public/js/views/user.js +68 -0
- data/public/js/views/users.js +31 -0
- data/public/js/views/variable.js +70 -0
- data/public/js/views/variables.js +30 -0
- data/spec/javascripts/helpers/.gitkeep +0 -0
- data/spec/javascripts/support/jasmine.yml +112 -0
- data/spec/javascripts/support/jasmine_helper.rb +22 -0
- data/spec/javascripts/support/run.html.erb +23 -0
- data/spec/javascripts/views/AuditSpec.js +22 -0
- data/spec/javascripts/views/AuditSpec.ls +18 -0
- data/vendor/prelude-ls/.gitignore +2 -0
- data/vendor/prelude-ls/.travis.yml +3 -0
- data/vendor/prelude-ls/CHANGELOG.md +81 -0
- data/vendor/prelude-ls/LICENSE +22 -0
- data/vendor/prelude-ls/Makefile +50 -0
- data/vendor/prelude-ls/README.md +15 -0
- data/vendor/prelude-ls/browser/prelude-browser-min.js +1 -0
- data/vendor/prelude-ls/browser/prelude-browser.js +1172 -0
- data/vendor/prelude-ls/lib/Func.js +40 -0
- data/vendor/prelude-ls/lib/List.js +602 -0
- data/vendor/prelude-ls/lib/Num.js +129 -0
- data/vendor/prelude-ls/lib/Obj.js +153 -0
- data/vendor/prelude-ls/lib/Str.js +68 -0
- data/vendor/prelude-ls/lib/index.js +164 -0
- data/vendor/prelude-ls/package.json +50 -0
- data/vendor/prelude-ls/package.ls +46 -0
- data/vendor/prelude-ls/src/Func.ls +17 -0
- data/vendor/prelude-ls/src/List.ls +299 -0
- data/vendor/prelude-ls/src/Num.ls +83 -0
- data/vendor/prelude-ls/src/Obj.ls +61 -0
- data/vendor/prelude-ls/src/Str.ls +32 -0
- data/vendor/prelude-ls/src/index.ls +56 -0
- data/vendor/prelude-ls/test/Func.ls +36 -0
- data/vendor/prelude-ls/test/List.ls +751 -0
- data/vendor/prelude-ls/test/Num.ls +258 -0
- data/vendor/prelude-ls/test/Obj.ls +145 -0
- data/vendor/prelude-ls/test/Prelude.ls +49 -0
- data/vendor/prelude-ls/test/Str.ls +208 -0
- data/vendor/prelude-ls/test/browser.html +5 -0
- metadata +369 -0
@@ -0,0 +1,299 @@
|
|
1
|
+
each = (f, xs) -->
|
2
|
+
for x in xs then f x
|
3
|
+
xs
|
4
|
+
|
5
|
+
map = (f, xs) -->
|
6
|
+
[f x for x in xs]
|
7
|
+
|
8
|
+
compact = (xs) -->
|
9
|
+
[x for x in xs when x]
|
10
|
+
|
11
|
+
filter = (f, xs) -->
|
12
|
+
[x for x in xs when f x]
|
13
|
+
|
14
|
+
reject = (f, xs) -->
|
15
|
+
[x for x in xs when not f x]
|
16
|
+
|
17
|
+
partition = (f, xs) -->
|
18
|
+
passed = []
|
19
|
+
failed = []
|
20
|
+
for x in xs
|
21
|
+
(if f x then passed else failed).push x
|
22
|
+
[passed, failed]
|
23
|
+
|
24
|
+
find = (f, xs) -->
|
25
|
+
for x in xs when f x then return x
|
26
|
+
void
|
27
|
+
|
28
|
+
head = first = (xs) ->
|
29
|
+
return void unless xs.length
|
30
|
+
xs.0
|
31
|
+
|
32
|
+
tail = (xs) ->
|
33
|
+
return void unless xs.length
|
34
|
+
xs.slice 1
|
35
|
+
|
36
|
+
last = (xs) ->
|
37
|
+
return void unless xs.length
|
38
|
+
xs[*-1]
|
39
|
+
|
40
|
+
initial = (xs) ->
|
41
|
+
len = xs.length
|
42
|
+
return void unless len
|
43
|
+
xs.slice 0, len - 1
|
44
|
+
|
45
|
+
empty = (xs) ->
|
46
|
+
not xs.length
|
47
|
+
|
48
|
+
reverse = (xs) ->
|
49
|
+
xs.concat!.reverse!
|
50
|
+
|
51
|
+
unique = (xs) ->
|
52
|
+
result = []
|
53
|
+
for x in xs when x not in result
|
54
|
+
result.push x
|
55
|
+
result
|
56
|
+
|
57
|
+
fold = foldl = (f, memo, xs) -->
|
58
|
+
for x in xs then memo = f memo, x
|
59
|
+
memo
|
60
|
+
|
61
|
+
fold1 = foldl1 = (f, xs) -->
|
62
|
+
fold f, xs.0, xs.slice 1
|
63
|
+
|
64
|
+
foldr = (f, memo, xs) -->
|
65
|
+
fold f, memo, (xs.concat!.reverse!)
|
66
|
+
|
67
|
+
foldr1 = (f, xs) -->
|
68
|
+
ys = xs.concat!.reverse!
|
69
|
+
fold f, ys.0, ys.slice 1
|
70
|
+
|
71
|
+
unfoldr = (f, b) -->
|
72
|
+
result = []
|
73
|
+
x = b
|
74
|
+
while (f x)?
|
75
|
+
result.push that.0
|
76
|
+
x = that.1
|
77
|
+
result
|
78
|
+
|
79
|
+
concat = (xss) ->
|
80
|
+
[].concat.apply [], xss
|
81
|
+
|
82
|
+
concat-map = (f, xs) -->
|
83
|
+
[].concat.apply [], [f x for x in xs]
|
84
|
+
|
85
|
+
flatten = (xs) -->
|
86
|
+
[].concat.apply [], [(if typeof! x is 'Array' then flatten x else x) for x in xs]
|
87
|
+
|
88
|
+
difference = (xs, ...yss) ->
|
89
|
+
results = []
|
90
|
+
:outer for x in xs
|
91
|
+
for ys in yss
|
92
|
+
continue outer if x in ys
|
93
|
+
results.push x
|
94
|
+
results
|
95
|
+
|
96
|
+
intersection = (xs, ...yss) ->
|
97
|
+
results = []
|
98
|
+
:outer for x in xs
|
99
|
+
for ys in yss
|
100
|
+
continue outer unless x in ys
|
101
|
+
results.push x
|
102
|
+
results
|
103
|
+
|
104
|
+
union = (...xss) ->
|
105
|
+
results = []
|
106
|
+
for xs in xss
|
107
|
+
for x in xs
|
108
|
+
results.push x unless x in results
|
109
|
+
results
|
110
|
+
|
111
|
+
count-by = (f, xs) -->
|
112
|
+
results = {}
|
113
|
+
for x in xs
|
114
|
+
key = f x
|
115
|
+
if key of results
|
116
|
+
results[key] += 1
|
117
|
+
else
|
118
|
+
results[key] = 1
|
119
|
+
results
|
120
|
+
|
121
|
+
group-by = (f, xs) -->
|
122
|
+
results = {}
|
123
|
+
for x in xs
|
124
|
+
key = f x
|
125
|
+
if key of results
|
126
|
+
results[key].push x
|
127
|
+
else
|
128
|
+
results[key] = [x]
|
129
|
+
results
|
130
|
+
|
131
|
+
and-list = (xs) ->
|
132
|
+
for x in xs when not x
|
133
|
+
return false
|
134
|
+
true
|
135
|
+
|
136
|
+
or-list = (xs) ->
|
137
|
+
for x in xs when x
|
138
|
+
return true
|
139
|
+
false
|
140
|
+
|
141
|
+
any = (f, xs) -->
|
142
|
+
for x in xs when f x
|
143
|
+
return true
|
144
|
+
false
|
145
|
+
|
146
|
+
all = (f, xs) -->
|
147
|
+
for x in xs when not f x
|
148
|
+
return false
|
149
|
+
true
|
150
|
+
|
151
|
+
sort = (xs) ->
|
152
|
+
xs.concat!.sort (x, y) ->
|
153
|
+
if x > y
|
154
|
+
1
|
155
|
+
else if x < y
|
156
|
+
-1
|
157
|
+
else
|
158
|
+
0
|
159
|
+
|
160
|
+
sort-with = (f, xs) -->
|
161
|
+
return [] unless xs.length
|
162
|
+
xs.concat!.sort f
|
163
|
+
|
164
|
+
sort-by = (f, xs) -->
|
165
|
+
return [] unless xs.length
|
166
|
+
xs.concat!.sort (x, y) ->
|
167
|
+
if (f x) > (f y)
|
168
|
+
1
|
169
|
+
else if (f x) < (f y)
|
170
|
+
-1
|
171
|
+
else
|
172
|
+
0
|
173
|
+
|
174
|
+
sum = (xs) ->
|
175
|
+
result = 0
|
176
|
+
for x in xs
|
177
|
+
result += x
|
178
|
+
result
|
179
|
+
|
180
|
+
product = (xs) ->
|
181
|
+
result = 1
|
182
|
+
for x in xs
|
183
|
+
result *= x
|
184
|
+
result
|
185
|
+
|
186
|
+
mean = average = (xs) ->
|
187
|
+
sum = 0
|
188
|
+
len = xs.length
|
189
|
+
for i til len
|
190
|
+
sum += xs[i]
|
191
|
+
sum / len
|
192
|
+
|
193
|
+
maximum = (xs) ->
|
194
|
+
max = xs.0
|
195
|
+
for x in xs.slice 1 when x > max
|
196
|
+
max = x
|
197
|
+
max
|
198
|
+
|
199
|
+
minimum = (xs) ->
|
200
|
+
min = xs.0
|
201
|
+
for x in xs.slice 1 when x < min
|
202
|
+
min = x
|
203
|
+
min
|
204
|
+
|
205
|
+
scan = scanl = (f, memo, xs) -->
|
206
|
+
last = memo
|
207
|
+
[memo] ++ [last = f last, x for x in xs]
|
208
|
+
|
209
|
+
scan1 = scanl1 = (f, xs) -->
|
210
|
+
return void unless xs.length
|
211
|
+
scan f, xs.0, xs.slice 1
|
212
|
+
|
213
|
+
scanr = (f, memo, xs) -->
|
214
|
+
xs = xs.concat!.reverse!
|
215
|
+
(scan f, memo, xs).reverse!
|
216
|
+
|
217
|
+
scanr1 = (f, xs) -->
|
218
|
+
return void unless xs.length
|
219
|
+
xs = xs.concat!.reverse!
|
220
|
+
(scan f, xs.0, xs.slice 1).reverse!
|
221
|
+
|
222
|
+
slice = (x, y, xs) -->
|
223
|
+
xs.slice x, y
|
224
|
+
|
225
|
+
take = (n, xs) -->
|
226
|
+
if n <= 0
|
227
|
+
xs.slice 0, 0
|
228
|
+
else if not xs.length
|
229
|
+
xs
|
230
|
+
else
|
231
|
+
xs.slice 0, n
|
232
|
+
|
233
|
+
drop = (n, xs) -->
|
234
|
+
if n <= 0 or not xs.length
|
235
|
+
xs
|
236
|
+
else
|
237
|
+
xs.slice n
|
238
|
+
|
239
|
+
split-at = (n, xs) --> [(take n, xs), (drop n, xs)]
|
240
|
+
|
241
|
+
take-while = (p, xs) -->
|
242
|
+
len = xs.length
|
243
|
+
return xs unless len
|
244
|
+
i = 0
|
245
|
+
while i < len and p xs[i]
|
246
|
+
i += 1
|
247
|
+
xs.slice 0 i
|
248
|
+
|
249
|
+
drop-while = (p, xs) -->
|
250
|
+
len = xs.length
|
251
|
+
return xs unless len
|
252
|
+
i = 0
|
253
|
+
while i < len and p xs[i]
|
254
|
+
i += 1
|
255
|
+
xs.slice i
|
256
|
+
|
257
|
+
span = (p, xs) --> [(take-while p, xs), (drop-while p, xs)]
|
258
|
+
|
259
|
+
break-list = (p, xs) --> span (not) << p, xs
|
260
|
+
|
261
|
+
zip = (xs, ys) -->
|
262
|
+
result = []
|
263
|
+
len = ys.length
|
264
|
+
for x, i in xs
|
265
|
+
break if i is len
|
266
|
+
result.push [x, ys[i]]
|
267
|
+
result
|
268
|
+
|
269
|
+
zip-with = (f, xs, ys) -->
|
270
|
+
result = []
|
271
|
+
len = ys.length
|
272
|
+
for x, i in xs
|
273
|
+
break if i is len
|
274
|
+
result.push f x, ys[i]
|
275
|
+
result
|
276
|
+
|
277
|
+
zip-all = (...xss) ->
|
278
|
+
min-length = 9e9
|
279
|
+
for xs in xss
|
280
|
+
min-length <?= xs.length
|
281
|
+
[[xs[i] for xs in xss] for i til min-length]
|
282
|
+
|
283
|
+
zip-all-with = (f, ...xss) ->
|
284
|
+
min-length = 9e9
|
285
|
+
for xs in xss
|
286
|
+
min-length <?= xs.length
|
287
|
+
[f.apply(null, [xs[i] for xs in xss]) for i til min-length]
|
288
|
+
|
289
|
+
module.exports = {
|
290
|
+
each, map, filter, compact, reject, partition, find,
|
291
|
+
head, first, tail, last, initial, empty,
|
292
|
+
reverse, difference, intersection, union, count-by, group-by,
|
293
|
+
fold, fold1, foldl, foldl1, foldr, foldr1, unfoldr, and-list, or-list,
|
294
|
+
any, all, unique, sort, sort-with, sort-by, sum, product, mean, average,
|
295
|
+
concat, concat-map, flatten,
|
296
|
+
maximum, minimum, scan, scan1, scanl, scanl1, scanr, scanr1,
|
297
|
+
slice, take, drop, split-at, take-while, drop-while, span, break-list,
|
298
|
+
zip, zip-with, zip-all, zip-all-with,
|
299
|
+
}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
max = (>?)
|
2
|
+
|
3
|
+
min = (<?)
|
4
|
+
|
5
|
+
negate = (x) -> -x
|
6
|
+
|
7
|
+
abs = Math.abs
|
8
|
+
|
9
|
+
signum = (x) ->
|
10
|
+
if x < 0
|
11
|
+
-1
|
12
|
+
else if x > 0
|
13
|
+
1
|
14
|
+
else
|
15
|
+
0
|
16
|
+
|
17
|
+
quot = (x, y) --> ~~(x / y)
|
18
|
+
|
19
|
+
rem = (%)
|
20
|
+
|
21
|
+
div = (x, y) --> Math.floor x / y
|
22
|
+
|
23
|
+
mod = (%%)
|
24
|
+
|
25
|
+
recip = (1 /)
|
26
|
+
|
27
|
+
pi = Math.PI
|
28
|
+
|
29
|
+
tau = pi * 2
|
30
|
+
|
31
|
+
exp = Math.exp
|
32
|
+
|
33
|
+
sqrt = Math.sqrt
|
34
|
+
|
35
|
+
ln = Math.log
|
36
|
+
|
37
|
+
pow = (^)
|
38
|
+
|
39
|
+
sin = Math.sin
|
40
|
+
|
41
|
+
tan = Math.tan
|
42
|
+
|
43
|
+
cos = Math.cos
|
44
|
+
|
45
|
+
asin = Math.asin
|
46
|
+
|
47
|
+
acos = Math.acos
|
48
|
+
|
49
|
+
atan = Math.atan
|
50
|
+
|
51
|
+
atan2 = (x, y) --> Math.atan2 x, y
|
52
|
+
|
53
|
+
truncate = (x) -> ~~x
|
54
|
+
|
55
|
+
round = Math.round
|
56
|
+
|
57
|
+
ceiling = Math.ceil
|
58
|
+
|
59
|
+
floor = Math.floor
|
60
|
+
|
61
|
+
is-it-NaN = (x) -> x isnt x
|
62
|
+
|
63
|
+
even = (x) -> x % 2 == 0
|
64
|
+
|
65
|
+
odd = (x) -> x % 2 != 0
|
66
|
+
|
67
|
+
gcd = (x, y) -->
|
68
|
+
x = Math.abs x
|
69
|
+
y = Math.abs y
|
70
|
+
until y is 0
|
71
|
+
z = x % y
|
72
|
+
x = y
|
73
|
+
y = z
|
74
|
+
x
|
75
|
+
|
76
|
+
lcm = (x, y) -->
|
77
|
+
Math.abs Math.floor (x / (gcd x, y) * y)
|
78
|
+
|
79
|
+
module.exports = {
|
80
|
+
max, min, negate, abs, signum, quot, rem, div, mod, recip,
|
81
|
+
pi, tau, exp, sqrt, ln, pow, sin, tan, cos, acos, asin, atan, atan2,
|
82
|
+
truncate, round, ceiling, floor, is-it-NaN, even, odd, gcd, lcm,
|
83
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
values = (object) ->
|
2
|
+
[x for , x of object]
|
3
|
+
|
4
|
+
keys = (object) ->
|
5
|
+
[x for x of object]
|
6
|
+
|
7
|
+
pairs-to-obj= (object) ->
|
8
|
+
{[x.0, x.1] for x in object}
|
9
|
+
|
10
|
+
obj-to-pairs = (object) ->
|
11
|
+
[[key, value] for key, value of object]
|
12
|
+
|
13
|
+
lists-to-obj= (keys, values) -->
|
14
|
+
{[key, values[i]] for key, i in keys}
|
15
|
+
|
16
|
+
obj-to-lists = (objectect) ->
|
17
|
+
keys = []
|
18
|
+
values = []
|
19
|
+
for key, value of objectect
|
20
|
+
keys.push key
|
21
|
+
values.push value
|
22
|
+
[keys, values]
|
23
|
+
|
24
|
+
|
25
|
+
empty = (object) ->
|
26
|
+
for x of object then return false
|
27
|
+
true
|
28
|
+
|
29
|
+
each = (f, object) -->
|
30
|
+
for , x of object then f x
|
31
|
+
object
|
32
|
+
|
33
|
+
map = (f, object) -->
|
34
|
+
{[k, f x] for k, x of object}
|
35
|
+
|
36
|
+
compact = (object) -->
|
37
|
+
{[k, x] for k, x of object when x}
|
38
|
+
|
39
|
+
filter = (f, object) -->
|
40
|
+
{[k, x] for k, x of object when f x}
|
41
|
+
|
42
|
+
reject = (f, object) -->
|
43
|
+
{[k, x] for k, x of object when not f x}
|
44
|
+
|
45
|
+
partition = (f, object) -->
|
46
|
+
passed = {}
|
47
|
+
failed = {}
|
48
|
+
for k, x of object
|
49
|
+
(if f x then passed else failed)[k] = x
|
50
|
+
[passed, failed]
|
51
|
+
|
52
|
+
find = (f, object) -->
|
53
|
+
for , x of object when f x then return x
|
54
|
+
void
|
55
|
+
|
56
|
+
module.exports = {
|
57
|
+
values, keys,
|
58
|
+
pairs-to-obj, obj-to-pairs, lists-to-obj, obj-to-lists,
|
59
|
+
|
60
|
+
empty, each, map, filter, compact, reject, partition, find,
|
61
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
split = (sep, str) -->
|
2
|
+
str.split sep
|
3
|
+
|
4
|
+
join = (sep, xs) -->
|
5
|
+
xs.join sep
|
6
|
+
|
7
|
+
lines = (str) ->
|
8
|
+
return [] unless str.length
|
9
|
+
str.split '\n'
|
10
|
+
|
11
|
+
unlines = (.join '\n')
|
12
|
+
|
13
|
+
words = (str) ->
|
14
|
+
return [] unless str.length
|
15
|
+
str.split /[ ]+/
|
16
|
+
|
17
|
+
unwords = (.join ' ')
|
18
|
+
|
19
|
+
chars = (.split '')
|
20
|
+
|
21
|
+
unchars = (.join '')
|
22
|
+
|
23
|
+
reverse = (str) ->
|
24
|
+
str.split '' .reverse!.join ''
|
25
|
+
|
26
|
+
repeat = (n, str) -->
|
27
|
+
out = [str for til n]
|
28
|
+
out.join ''
|
29
|
+
|
30
|
+
module.exports = {
|
31
|
+
split, join, lines, unlines, words, unwords, chars, unchars, reverse, repeat,
|
32
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require! [
|
2
|
+
'./Func.js'
|
3
|
+
'./List.js'
|
4
|
+
'./Obj.js'
|
5
|
+
'./Str.js'
|
6
|
+
'./Num.js'
|
7
|
+
]
|
8
|
+
|
9
|
+
id = (x) -> x
|
10
|
+
|
11
|
+
is-type = (type, x) --> typeof! x is type
|
12
|
+
|
13
|
+
replicate = (n, x) -->
|
14
|
+
[x for til n]
|
15
|
+
|
16
|
+
|
17
|
+
Str <<< List{
|
18
|
+
empty, slice, take, drop, split-at, take-while, drop-while, span, break-str: break-list
|
19
|
+
}
|
20
|
+
|
21
|
+
prelude = {
|
22
|
+
Func, List, Obj, Str, Num,
|
23
|
+
id, is-type
|
24
|
+
replicate,
|
25
|
+
}
|
26
|
+
prelude <<< List{
|
27
|
+
each, map, filter, compact, reject, partition, find,
|
28
|
+
head, first, tail, last, initial, empty,
|
29
|
+
reverse, difference, intersection, union, count-by, group-by,
|
30
|
+
fold, foldl, fold1, foldl1, foldr, foldr1, unfoldr, and-list, or-list,
|
31
|
+
any, all, unique, sort, sort-with, sort-by, sum, product, mean, average,
|
32
|
+
concat, concat-map, flatten,
|
33
|
+
maximum, minimum, scan, scanl, scan1, scanl1, scanr, scanr1,
|
34
|
+
slice, take, drop, split-at, take-while, drop-while, span, break-list,
|
35
|
+
zip, zip-with, zip-all, zip-all-with,
|
36
|
+
}
|
37
|
+
prelude <<< Func{
|
38
|
+
apply, curry, flip, fix,
|
39
|
+
}
|
40
|
+
prelude <<< Str{
|
41
|
+
split, join, lines, unlines, words, unwords, chars, unchars
|
42
|
+
}
|
43
|
+
# not importing all of Obj's functions
|
44
|
+
prelude <<< Obj{
|
45
|
+
values, keys,
|
46
|
+
pairs-to-obj, obj-to-pairs, lists-to-obj, obj-to-lists,
|
47
|
+
}
|
48
|
+
prelude <<< Num{
|
49
|
+
max, min, negate, abs, signum, quot, rem, div, mod, recip,
|
50
|
+
pi, tau, exp, sqrt, ln, pow, sin, tan, cos, acos, asin, atan, atan2,
|
51
|
+
truncate, round, ceiling, floor, is-it-NaN, even, odd, gcd, lcm,
|
52
|
+
}
|
53
|
+
|
54
|
+
prelude.VERSION = '1.0.3'
|
55
|
+
|
56
|
+
module.exports = prelude
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{apply, curry, flip, fix} = require '..' .Func
|
2
|
+
{equal: eq, deep-equal: deep-eq, ok} = require 'assert'
|
3
|
+
|
4
|
+
suite 'apply' ->
|
5
|
+
test 'empty list' ->
|
6
|
+
f = -> 1
|
7
|
+
eq 1, apply f, []
|
8
|
+
|
9
|
+
test 'a couple of args' ->
|
10
|
+
eq 5, apply (+), [2 3]
|
11
|
+
|
12
|
+
test 'curried' ->
|
13
|
+
f = apply (+)
|
14
|
+
eq 5, f [2 3]
|
15
|
+
|
16
|
+
suite 'curry' ->
|
17
|
+
test 'simple function' ->
|
18
|
+
add = (x, y) -> x + y
|
19
|
+
add-curried = curry add
|
20
|
+
add-four = add-curried 4
|
21
|
+
eq 6 add-four 2
|
22
|
+
|
23
|
+
suite 'flip' ->
|
24
|
+
test 'minus op' ->
|
25
|
+
eq 10, (flip (-)) 5 15
|
26
|
+
|
27
|
+
suite 'fix' ->
|
28
|
+
test 'single arg' ->
|
29
|
+
eq 89, (fix (fib) -> (n) ->
|
30
|
+
| n <= 1 => 1
|
31
|
+
| otherwise => fib(n-1) + fib(n-2))(10)
|
32
|
+
|
33
|
+
test 'multi-arg variation' ->
|
34
|
+
eq 89, (fix (fib) -> (n, minus=0) ->
|
35
|
+
| (n - minus) <= 1 => 1
|
36
|
+
| otherwise => fib(n, minus+1) + fib(n, minus+2))(10)
|