Skip to content

Commit aa7fefc

Browse files
committed
Core changes for sticky contexts
1 parent b183def commit aa7fefc

8 files changed

Lines changed: 3409 additions & 43 deletions

File tree

core/Gruntfile.js

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,45 @@
1414
*/
1515

1616
/*global module:false*/
17-
module.exports = function(grunt) {
17+
module.exports = function (grunt) {
1818

19-
grunt.initConfig({
19+
grunt.initConfig({
2020

21-
ts: {
22-
default : {
23-
tsconfig: true
24-
}
25-
},
21+
ts: {
22+
default: {
23+
tsconfig: true
24+
}
25+
},
2626

27-
dtsGenerator: {
28-
default: {
29-
options: {
30-
name: 'snowplow-tracker',
31-
project: '.',
32-
out: 'main.d.ts'
27+
dtsGenerator: {
28+
default: {
29+
options: {
30+
name: 'snowplow-tracker',
31+
project: '.',
32+
out: 'main.d.ts'
33+
}
3334
}
34-
}
35-
},
35+
},
3636

37-
intern: {
38-
unit: {
39-
options: {
40-
runType: 'client',
41-
config: 'tests/intern.js',
42-
suites: [
43-
'tests/unit/base64.js',
44-
'tests/unit/payload.js',
45-
'tests/unit/core.js'
46-
]
37+
intern: {
38+
unit: {
39+
options: {
40+
runType: 'client',
41+
config: 'tests/intern.js',
42+
suites: [
43+
'tests/unit/base64.js',
44+
'tests/unit/payload.js',
45+
'tests/unit/core.js',
46+
'tests/unit/contexts.js'
47+
]
48+
}
49+
}
4750
}
48-
}
49-
}
50-
});
51+
});
5152

52-
grunt.loadNpmTasks('intern');
53-
grunt.loadNpmTasks('grunt-ts');
54-
grunt.loadNpmTasks('dts-generator');
53+
grunt.loadNpmTasks('intern');
54+
grunt.loadNpmTasks('grunt-ts');
55+
grunt.loadNpmTasks('dts-generator');
5556

56-
grunt.registerTask('default', 'Compile and test', ['ts', 'dtsGenerator', 'intern']);
57+
grunt.registerTask('default', 'Compile and test', ['ts', 'dtsGenerator', 'intern']);
5758
};

core/lib/base64.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,71 @@ export function base64encode(data: string): string {
8383
return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
8484
}
8585

86+
export function base64decode(encodedData:string): string {
87+
// discuss at: http://locutus.io/php/base64_decode/
88+
// original by: Tyler Akins (http://rumkin.com)
89+
// improved by: Thunder.m
90+
// improved by: Kevin van Zonneveld (http://kvz.io)
91+
// improved by: Kevin van Zonneveld (http://kvz.io)
92+
// input by: Aman Gupta
93+
// input by: Brett Zamir (http://brett-zamir.me)
94+
// bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)
95+
// bugfixed by: Pellentesque Malesuada
96+
// bugfixed by: Kevin van Zonneveld (http://kvz.io)
97+
// improved by: Indigo744
98+
// example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==')
99+
// returns 1: 'Kevin van Zonneveld'
100+
// example 2: base64_decode('YQ==')
101+
// returns 2: 'a'
102+
// example 3: base64_decode('4pyTIMOgIGxhIG1vZGU=')
103+
// returns 3: '✓ à la mode'
104+
105+
// decodeUTF8string()
106+
// Internal function to decode properly UTF8 string
107+
// Adapted from Solution #1 at https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding
108+
var decodeUTF8string = function (str) {
109+
// Going backwards: from bytestream, to percent-encoding, to original string.
110+
return decodeURIComponent(str.split('').map(function (c) {
111+
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
112+
}).join(''))
113+
};
114+
115+
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
116+
var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
117+
ac = 0,
118+
dec = '',
119+
tmpArr: Array<string> = [];
120+
121+
if (!encodedData) {
122+
return encodedData;
123+
}
124+
125+
encodedData += '';
126+
127+
do {
128+
// unpack four hexets into three octets using index points in b64
129+
h1 = b64.indexOf(encodedData.charAt(i++));
130+
h2 = b64.indexOf(encodedData.charAt(i++));
131+
h3 = b64.indexOf(encodedData.charAt(i++));
132+
h4 = b64.indexOf(encodedData.charAt(i++));
133+
134+
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
135+
136+
o1 = bits >> 16 & 0xff;
137+
o2 = bits >> 8 & 0xff;
138+
o3 = bits & 0xff;
139+
140+
if (h3 === 64) {
141+
tmpArr[ac++] = String.fromCharCode(o1);
142+
} else if (h4 === 64) {
143+
tmpArr[ac++] = String.fromCharCode(o1, o2);
144+
} else {
145+
tmpArr[ac++] = String.fromCharCode(o1, o2, o3);
146+
}
147+
} while (i < encodedData.length);
148+
149+
dec = tmpArr.join('');
150+
151+
return decodeUTF8string(dec.replace(/\0+$/, ''));
152+
}
153+

0 commit comments

Comments
 (0)