/usr/share/javascript/objectpath/ObjectPath.js is in libjs-objectpath 1.2.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | 'use strict';
;!function(undefined) {
var ObjectPath = {
parse: function(str){
if(typeof str !== 'string'){
throw new TypeError('ObjectPath.parse must be passed a string');
}
var i = 0;
var parts = [];
var d, b, q, c;
while (i < str.length){
d = str.indexOf('.', i);
b = str.indexOf('[', i);
// we've reached the end
if (d === -1 && b === -1){
parts.push(str.slice(i, str.length));
i = str.length;
}
// dots
else if (b === -1 || (d !== -1 && d < b)) {
parts.push(str.slice(i, d));
i = d + 1;
}
// brackets
else {
if (b > i){
parts.push(str.slice(i, b));
i = b;
}
q = str.slice(b+1, b+2);
if (q !== '"' && q !=='\'') {
c = str.indexOf(']', b);
if (c === -1) c = str.length;
parts.push(str.slice(i + 1, c));
i = (str.slice(c + 1, c + 2) === '.') ? c + 2 : c + 1;
} else {
c = str.indexOf(q+']', b);
if (c === -1) c = str.length;
while (str.slice(c - 1, c) === '\\' && b < str.length){
b++;
c = str.indexOf(q+']', b);
}
parts.push(str.slice(i + 2, c).replace(new RegExp('\\'+q,'g'), q));
i = (str.slice(c + 2, c + 3) === '.') ? c + 3 : c + 2;
}
}
}
return parts;
},
// root === true : auto calculate root; must be dot-notation friendly
// root String : the string to use as root
stringify: function(arr, quote){
if(!Array.isArray(arr))
arr = [arr.toString()];
quote = quote === '"' ? '"' : '\'';
return arr.map(function(n){ return '[' + quote + (n.toString()).replace(new RegExp(quote, 'g'), '\\' + quote) + quote + ']'; }).join('');
},
normalize: function(data, quote){
return ObjectPath.stringify(Array.isArray(data) ? data : ObjectPath.parse(data), quote);
},
// Angular
registerModule: function(angular) {
angular.module('ObjectPath', []).provider('ObjectPath', function(){
this.parse = ObjectPath.parse;
this.stringify = ObjectPath.stringify;
this.normalize = ObjectPath.normalize;
this.$get = function(){
return ObjectPath;
};
});
}
};
// AMD
if (typeof define === 'function' && define.amd) {
define(function() {
return {ObjectPath: ObjectPath};
});
}
// CommonJS
else if (typeof exports === 'object') {
exports.ObjectPath = ObjectPath;
}
// Browser global
else {
window.ObjectPath = ObjectPath;
}
}();
|