Commit a01c26d 1 parent 898c722 commit a01c26d Copy full SHA for a01c26d
File tree 7 files changed +89
-0
lines changed
7 files changed +89
-0
lines changed Original file line number Diff line number Diff line change 34
34
"jsdoc" : " rimraf docs && jsdoc -c ./jsdoc.json ./README.md"
35
35
},
36
36
"dependencies" : {
37
+ "js-cookie" : " ^2.2.1" ,
37
38
"window-or-global" : " ^1.0.1"
38
39
},
39
40
"devDependencies" : {
Original file line number Diff line number Diff line change 7
7
8
8
export * from './escaperegexp' ;
9
9
export * from './featureflag' ;
10
+ export * from './ipcinfoCookie' ;
10
11
export * from './serialize' ;
11
12
export * from './settings' ;
Original file line number Diff line number Diff line change
1
+ import { ipcinfoCookie } from '../' ;
2
+
3
+ describe ( 'ipcinfo cookie utility' , ( ) => {
4
+ beforeEach ( ( ) => {
5
+ const document = {
6
+ cookie : 'ipcInfo=cc%253DUS%253Blc%253Den' ,
7
+ } ;
8
+ global . document = document ;
9
+ } ) ;
10
+
11
+ // it('should return undefined if cookie is not there', () => {
12
+ // const ipcinfo = ipcinfoCookie.get();
13
+ // expect(ipcinfo).toBe(undefined);
14
+ // });
15
+
16
+ it ( 'should fetch the ipcInfo cookie and return a neat object' , ( ) => {
17
+ const info = {
18
+ cc : 'US' ,
19
+ lc : 'en' ,
20
+ } ;
21
+
22
+ const ipcinfo = ipcinfoCookie . get ( ) ;
23
+ expect ( ipcinfo ) . toBe ( info ) ;
24
+ } ) ;
25
+
26
+ // it('should set the ipcInfo cookie', () => {
27
+ // const output = ipcinfoCookie.set('US', 'en');
28
+ // });
29
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright IBM Corp. 2016, 2018
3
+ *
4
+ * This source code is licensed under the Apache-2.0 license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ export { default as ipcinfoCookie } from './ipcinfoCookie' ;
Original file line number Diff line number Diff line change
1
+ import Cookies from 'js-cookie' ;
2
+
3
+ /**
4
+ * Utility to set and get the ipcInfo cookie needed to determine country and language code
5
+ *
6
+ */
7
+ class ipcinfoCookie {
8
+ /**
9
+ * retreive the ipcInfo cookie that contains the cc and lc
10
+ * decodes and converts to object
11
+ *
12
+ * @returns {object } objects ipc info object
13
+ */
14
+ static get ( ) {
15
+ const ipcinfo = Cookies . get ( 'ipcInfo' ) ;
16
+ if ( ipcinfo ) {
17
+ let cc ;
18
+ let lc ;
19
+ const info = decodeURIComponent ( ipcinfo ) . split ( ';' ) ;
20
+ info . map ( code => {
21
+ const itemParts = code . split ( '=' ) ;
22
+ if ( itemParts [ 0 ] === 'cc' ) cc = itemParts [ 1 ] ;
23
+ if ( itemParts [ 0 ] === 'lc' ) lc = itemParts [ 1 ] ;
24
+ } ) ;
25
+
26
+ return { cc, lc } ;
27
+ }
28
+ }
29
+
30
+ /**
31
+ * set the ipcInfo cookie
32
+ * takes care of converting to string and encoding
33
+ *
34
+ * @param {string } cc country coude
35
+ * @param {string } lc language code
36
+ *
37
+ */
38
+ static set ( cc , lc ) {
39
+ const info = `cc=${ cc } ;lc=${ lc } ` ;
40
+
41
+ Cookies . set ( 'ipcInfo' , encodeURIComponent ( info ) ) ;
42
+ }
43
+ }
44
+
45
+ export default ipcinfoCookie ;
Original file line number Diff line number Diff line change @@ -11131,6 +11131,11 @@ js-base64@^2.1.8:
11131
11131
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-2.5.1.tgz#1efa39ef2c5f7980bb1784ade4a8af2de3291121"
11132
11132
integrity sha512-M7kLczedRMYX4L8Mdh4MzyAMM9O5osx+4FcOQuTvr3A9F2D9S5JXheN0ewNbrvK2UatkTRhL5ejGmGSjNMiZuw==
11133
11133
11134
+ js-cookie@^2.2.1:
11135
+ version "2.2.1"
11136
+ resolved "https://registry.yarnpkg.com/js-cookie/-/js-cookie-2.2.1.tgz#69e106dc5d5806894562902aa5baec3744e9b2b8"
11137
+ integrity sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ==
11138
+
11134
11139
js-levenshtein@^1.1.3:
11135
11140
version "1.1.6"
11136
11141
resolved "https://registry.yarnpkg.com/js-levenshtein/-/js-levenshtein-1.1.6.tgz#c6cee58eb3550372df8deb85fad5ce66ce01d59d"
You can’t perform that action at this time.
0 commit comments