UNPKG

2.1 kBJavaScriptView Raw
1// Generated by LiveScript 1.6.0
2var split, join, lines, unlines, words, unwords, chars, unchars, reverse, repeat, capitalize, camelize, dasherize;
3split = curry$(function(sep, str){
4 return str.split(sep);
5});
6join = curry$(function(sep, xs){
7 return xs.join(sep);
8});
9lines = function(str){
10 if (!str.length) {
11 return [];
12 }
13 return str.split('\n');
14};
15unlines = function(it){
16 return it.join('\n');
17};
18words = function(str){
19 if (!str.length) {
20 return [];
21 }
22 return str.split(/[ ]+/);
23};
24unwords = function(it){
25 return it.join(' ');
26};
27chars = function(it){
28 return it.split('');
29};
30unchars = function(it){
31 return it.join('');
32};
33reverse = function(str){
34 return str.split('').reverse().join('');
35};
36repeat = curry$(function(n, str){
37 var result, i$;
38 result = '';
39 for (i$ = 0; i$ < n; ++i$) {
40 result += str;
41 }
42 return result;
43});
44capitalize = function(str){
45 return str.charAt(0).toUpperCase() + str.slice(1);
46};
47camelize = function(it){
48 return it.replace(/[-_]+(.)?/g, function(arg$, c){
49 return (c != null ? c : '').toUpperCase();
50 });
51};
52dasherize = function(str){
53 return str.replace(/([^-A-Z])([A-Z]+)/g, function(arg$, lower, upper){
54 return lower + "-" + (upper.length > 1
55 ? upper
56 : upper.toLowerCase());
57 }).replace(/^([A-Z]+)/, function(arg$, upper){
58 if (upper.length > 1) {
59 return upper + "-";
60 } else {
61 return upper.toLowerCase();
62 }
63 });
64};
65module.exports = {
66 split: split,
67 join: join,
68 lines: lines,
69 unlines: unlines,
70 words: words,
71 unwords: unwords,
72 chars: chars,
73 unchars: unchars,
74 reverse: reverse,
75 repeat: repeat,
76 capitalize: capitalize,
77 camelize: camelize,
78 dasherize: dasherize
79};
80function curry$(f, bound){
81 var context,
82 _curry = function(args) {
83 return f.length > 1 ? function(){
84 var params = args ? args.concat() : [];
85 context = bound ? context || this : this;
86 return params.push.apply(params, arguments) <
87 f.length && arguments.length ?
88 _curry.call(context, params) : f.apply(context, params);
89 } : f;
90 };
91 return _curry();
92}
\No newline at end of file