@ouroboros/browser 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cookies.d.ts CHANGED
@@ -46,7 +46,7 @@ declare function remove(name: string, domain?: string, path?: string): void;
46
46
  * @param {string?} path The optional path of the cookie
47
47
  * @return {void}
48
48
  */
49
- declare function set(name: string, value: string, expires: number, domain?: string, path?: string): void;
49
+ declare function set(name: string, value: string, expires?: number, domain?: string, path?: string): void;
50
50
  declare const cookies: {
51
51
  get: typeof get;
52
52
  remove: typeof remove;
package/cookies.js CHANGED
@@ -67,20 +67,28 @@ function remove(name, domain, path) {
67
67
  * @return {void}
68
68
  */
69
69
  function set(name, value, expires, domain, path) {
70
- // Generate the expires time
71
- const d = new Date();
72
- d.setTime(d.getTime() + (expires * 1000));
73
- // Generate the cookie string
74
- let s = name + '=' + encodeURIComponent(value) +
75
- '; expires=' + d.toUTCString() + ';';
70
+ // Init the sections with the name and value
71
+ const lSections = [
72
+ `${name}=${encodeURIComponent(value)}`
73
+ ];
74
+ // If we have an expires
75
+ if (expires) {
76
+ // Generate the expires time
77
+ const d = new Date();
78
+ d.setTime(d.getTime() + (expires * 1000));
79
+ // Add it to the sections
80
+ lSections.push(`expires=${d.toUTCString()}`);
81
+ }
82
+ // If we have a domain
76
83
  if (domain) {
77
- s += ' domain=' + domain + ';';
84
+ lSections.push(`domain=${domain}`);
78
85
  }
86
+ // If we have a path
79
87
  if (path) {
80
- s += ' path=' + path + ';';
88
+ lSections.push(`path=${path}`);
81
89
  }
82
- // Set the cookie
83
- document.cookie = s;
90
+ // Set the cookie by combining the sections
91
+ document.cookie = lSections.join('; ');
84
92
  }
85
93
  // Default export
86
94
  const cookies = { get, remove, set };
package/cookies.ts CHANGED
@@ -73,24 +73,36 @@ function remove(name: string, domain?: string, path?: string): void {
73
73
  * @param {string?} path The optional path of the cookie
74
74
  * @return {void}
75
75
  */
76
- function set(name: string, value: string, expires: number, domain?: string, path?: string): void {
76
+ function set(name: string, value: string, expires?: number, domain?: string, path?: string): void {
77
77
 
78
- // Generate the expires time
79
- const d = new Date();
80
- d.setTime(d.getTime() + (expires*1000))
78
+ // Init the sections with the name and value
79
+ const lSections = [
80
+ `${name}=${encodeURIComponent(value)}`
81
+ ];
81
82
 
82
- // Generate the cookie string
83
- let s = name + '=' + encodeURIComponent(value) +
84
- '; expires=' + d.toUTCString() + ';';
83
+ // If we have an expires
84
+ if(expires) {
85
+
86
+ // Generate the expires time
87
+ const d = new Date();
88
+ d.setTime(d.getTime() + (expires * 1000))
89
+
90
+ // Add it to the sections
91
+ lSections.push(`expires=${d.toUTCString()}`);
92
+ }
93
+
94
+ // If we have a domain
85
95
  if(domain) {
86
- s += ' domain=' + domain + ';';
96
+ lSections.push(`domain=${domain}`);
87
97
  }
98
+
99
+ // If we have a path
88
100
  if(path) {
89
- s += ' path=' + path + ';';
101
+ lSections.push(`path=${path}`);
90
102
  }
91
103
 
92
- // Set the cookie
93
- document.cookie = s;
104
+ // Set the cookie by combining the sections
105
+ document.cookie = lSections.join('; ');
94
106
  }
95
107
 
96
108
  // Default export
package/hash.js CHANGED
@@ -8,7 +8,8 @@
8
8
  * @created 2018-12-09
9
9
  */
10
10
  // Generic modules
11
- import { clone, empty, isObject, parseQuery } from '@ouroboros/tools';
11
+ import clone from '@ouroboros/clone';
12
+ import { empty, isObject, parseQuery } from '@ouroboros/tools';
12
13
  // name regex
13
14
  const nameRE = /^[a-zA-Z_]+$/;
14
15
  // Callbacks
package/hash.ts CHANGED
@@ -9,7 +9,8 @@
9
9
  */
10
10
 
11
11
  // Generic modules
12
- import { clone, empty, isObject, parseQuery } from '@ouroboros/tools';
12
+ import clone from '@ouroboros/clone';
13
+ import { empty, isObject, parseQuery } from '@ouroboros/tools';
13
14
 
14
15
  // Callback type
15
16
  type Callback = (value: string | null) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouroboros/browser",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Package to handle common browser functionality.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -33,7 +33,7 @@
33
33
  "typescript": "^4.8.3"
34
34
  },
35
35
  "dependencies": {
36
- "@ouroboros/tools": "^0.3.0"
37
- },
38
- "peerDependencies": {}
39
- }
36
+ "@ouroboros/clone": "^1.0.1",
37
+ "@ouroboros/tools": "^0.4.1"
38
+ }
39
+ }