-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·51 lines (45 loc) · 1.48 KB
/
script.js
File metadata and controls
executable file
·51 lines (45 loc) · 1.48 KB
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
// Code goes here
function buildStringFrom(text){
if (!text) return '';
text = ' '+ text.split('').join(' ') + ' '
var toReturn = ''
var textArr = text.split('')
for (var i = 0; i<=6; i++){
textArr.forEach(function(letter){
toReturn += map[letter][i]
})
toReturn += '\n'
}
return toReturn;
}
var convertToEmoji = function(str,light,dark){
str = str.toLowerCase()
str = buildStringFrom(str)
return str.replace(/0/g,light).replace(/1/g,dark)
}
var app = angular.module('emojiConverter', [])
app.controller('MainCtrl', function($scope){
$scope.lightSquare = ':white_square:'
$scope.darkSquare = ':black_square:'
$scope.convert = function(){
checkInput();
$scope.output = convertToEmoji($scope.inputStr,$scope.lightSquare,$scope.darkSquare)
if ($scope.output.length > 4000) $scope.error = 'You are over the Slack character limit! Try using a shorter emoji name or less characters'
}
var checkInput = function(){
$scope.error = ''
if ($scope.inputStr && $scope.inputStr.match(/[.,-\/#!$%\^&\*;:{}=\-_`~()]|[0-9]/)){
$scope.error = "Sorry, punctuation and numbers are not yet supported"
}
}
$scope.copyToClipboard = function(){
var copyFrom = document.createElement("textarea");
copyFrom.textContent = $scope.output
var body = document.getElementsByTagName('body')[0];
body.appendChild(copyFrom);
copyFrom.select();
document.execCommand('copy');
body.removeChild(copyFrom);
};
$scope.error = ''
})