@kizmann/pico-js 1.0.12 → 1.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizmann/pico-js",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "private": false,
package/src/index.js CHANGED
@@ -69,24 +69,22 @@ export const Pico = {
69
69
  Route: Route,
70
70
  }
71
71
 
72
- /**
73
- * @const window
74
- */
72
+ let win = Any.global();
75
73
 
76
- if ( typeof window.IE === 'undefined' && window.navigator ) {
77
- window.IE = !! window.navigator.userAgent.match(/Edge\/|Trident\/|MSIE /);
74
+ if ( typeof win.IE === 'undefined' && win.navigator ) {
75
+ win.IE = !! win.navigator.userAgent.match(/Edge\/|Trident\/|MSIE /);
78
76
  }
79
77
 
80
- if ( typeof window.WIN === 'undefined' && window.navigator ) {
81
- window.WIN = !! window.navigator.userAgent.match(/Windows/);
78
+ if ( typeof win.WIN === 'undefined' && win.navigator ) {
79
+ win.WIN = !! win.navigator.userAgent.match(/Windows/);
82
80
  }
83
81
 
84
- if ( typeof window.pi === 'undefined' && window.navigator ) {
85
- window.pi = Pico;
82
+ if ( typeof win.pi === 'undefined' && win.navigator ) {
83
+ win.pi = Pico;
86
84
  }
87
85
 
88
- if ( typeof window.pi !== 'undefined' && window.document ) {
89
- window.pi.Dom.ready(window.pi.Element.listen);
86
+ if ( typeof win.pi !== 'undefined' && win.document ) {
87
+ win.pi.Dom.ready(win.pi.Element.listen);
90
88
  }
91
89
 
92
90
  export default Pico;
@@ -2,7 +2,7 @@ import { Arr, Obj, Num, Any, Event } from "../index.js";
2
2
 
3
3
  export class Data
4
4
  {
5
- static data = Obj.get(window, '_data', {});
5
+ static data = Obj.get(Any.global(), '_data', {});
6
6
 
7
7
  static has(input)
8
8
  {
@@ -1,11 +1,11 @@
1
- import { Obj } from "../index.js";
1
+ import { Obj, Any } from "../index.js";
2
2
 
3
3
  export class Locale
4
4
  {
5
5
  /**
6
6
  * Get locales from window if present.
7
7
  */
8
- static locales = Obj.get(window, '_locales', {});
8
+ static locales = Obj.get(Any.global(), '_locales', {});
9
9
 
10
10
  static pickByCount(splits, count)
11
11
  {
@@ -2,7 +2,7 @@ import { Obj, Str, Any } from "../index.js";
2
2
 
3
3
  export default class Route
4
4
  {
5
- static routes = Obj.get(window, '_routes', {});
5
+ static routes = Obj.get(Any.global(), '_routes', {});
6
6
 
7
7
  static set (key, value)
8
8
  {
@@ -2,6 +2,19 @@ import { Arr, Obj, Now } from "../index.js";
2
2
 
3
3
  export class Any
4
4
  {
5
+ static global(fallback = {})
6
+ {
7
+ if ( window !== undefined ) {
8
+ return window;
9
+ }
10
+
11
+ if ( global !== undefined ) {
12
+ return global;
13
+ }
14
+
15
+ return fallback;
16
+ }
17
+
5
18
  static isEmpty(val)
6
19
  {
7
20
  if ( this.isNumber(val) ) {
@@ -7,7 +7,9 @@ export class Now
7
7
 
8
8
  constructor(date = null, format = 'YYYY-MM-DD HH:mm:ss')
9
9
  {
10
- if ( ! window.moment ) {
10
+ let win = Any.global();
11
+
12
+ if ( ! win.moment ) {
11
13
  throw new Error('Moment.js is required for pi.Now');
12
14
  }
13
15
 
@@ -18,14 +20,14 @@ export class Now
18
20
  this.initialDate = date;
19
21
 
20
22
  if ( ! Any.isString(date) ) {
21
- this.moment = window.moment(date || new Date, format);
23
+ this.moment = win.moment(date || new Date, format);
22
24
  }
23
25
 
24
26
  if ( this.moment !== null ) {
25
27
  return this;
26
28
  }
27
29
 
28
- this.moment = window.moment(date.match(/^now/) ?
30
+ this.moment = win.moment(date.match(/^now/) ?
29
31
  new Date : date, format);
30
32
 
31
33
  let second = this.initialDate.match(/(\+|-)([0-9]+)seconds?/);
@@ -92,7 +94,7 @@ export class Now
92
94
  valid()
93
95
  {
94
96
  return ! Any.isEmpty(this.initialDate) &&
95
- window.moment(this.initialDate).isValid();
97
+ Any.global().moment(this.initialDate).isValid();
96
98
  }
97
99
 
98
100
  clone()
@@ -362,7 +362,7 @@ export class Obj
362
362
  {
363
363
  let result = {};
364
364
 
365
- if ( window.FormData && obj instanceof FormData ) {
365
+ if ( FormData && obj instanceof FormData ) {
366
366
 
367
367
  for ( let [key, value] of obj.entries() ) {
368
368
  result[key] = callback(value, key);