This repository was archived by the owner on Aug 27, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
98 lines (84 loc) · 2.54 KB
/
Copy pathutils.js
File metadata and controls
98 lines (84 loc) · 2.54 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
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
/**
* This utility object contains a few function that is used in various placed, and is more generic functions.
*/
define(function(require, exports, module) {
"use strict";
/* jslint bitwise: true */
/* jshint ignore:start */
var
moment = require('bower/momentjs/moment');
var utils = {
"guid": function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0;
var v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
},
// Credits to
// http://shebang.brandonmintern.com/foolproof-html-escaping-in-javascript/
"escape": function(s, forAttribute) {
var r = ((forAttribute !== false) ?
new RegExp('[&<>\'"]', 'g') :
new RegExp('[&<>]', 'g'));
var MAP = { '&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''};
var p = s.replace(r, function(c) {
return MAP[c];
});
return p;
},
"getKeys": function(obj) {
var list = [];
if (typeof obj !== "object") {
return list;
}
for(var key in obj) {
if (obj.hasOwnProperty(key)) {
list.push(key);
}
}
return list;
},
"parseDate": function (input) {
var x = input.substring(0, 19) + 'Z';
// console.log("About to parse date " + input, x);
return moment(x);
},
// Normalize search term.
"normalizeST": function(searchTerm) {
var x = searchTerm.toLowerCase().replace(/[^a-zæøåA-ZÆØÅ ]/g, '');
if (x === '') {
return null;
}
return x;
},
"stok" : function(str) {
// console.log("STR", str);
if (str === null) {return true;}
if (str.length > 2) { return true; }
return false;
},
"quoteattr" : function(s, preserveCR) {
preserveCR = preserveCR ? ' ' : '\n';
return ('' + s) /* Forces the conversion to string. */
.replace(/&/g, '&') /* This MUST be the 1st replacement. */
.replace(/'/g, ''') /* The 4 other predefined entities, required. */
.replace(/"/g, '"')
.replace(/</g, '<')
.replace(/>/g, '>')
/*
You may add other replacements here for HTML only
(but it's not necessary).
Or for XML, only if the named entities are defined in its DTD.
*/
.replace(/\r\n/g, preserveCR) /* Must be before the next replacement. */
.replace(/[\r\n]/g, preserveCR);
}
};
return utils;
/* jshint ignore:end */
});