@kizmann/pico-js 2.0.11 → 2.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": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "private": false,
@@ -81,6 +81,10 @@ export class PicoNowDefault
81
81
  */
82
82
  set(value : any, scope : string) : PicoNow
83
83
  {
84
+ if ( value == null) {
85
+ return <PicoNow> <unknown> this;
86
+ }
87
+
84
88
  if ( !Mix.isNum(value) ) {
85
89
  value = Mix.int(value);
86
90
  }
@@ -70,6 +70,7 @@ export class PicoNowFormat
70
70
  format = 'YYYY-MM-DD';
71
71
  }
72
72
 
73
+
73
74
  if ( this.isModifible(value) ) {
74
75
  return this.modify(value);
75
76
  }
@@ -1,5 +1,5 @@
1
1
  import { Arr } from "../index.esm.ts";
2
- import { PicoNowInterface } from "../utils/Now.ts";
2
+ import { PicoNow, PicoNowInterface } from "../utils/Now.ts";
3
3
  import PicoNowWalker from "./NowWalker.js";
4
4
 
5
5
  export interface PicoNowGrid extends PicoNowInterface,
@@ -19,9 +19,9 @@ export class PicoNowGrid
19
19
  * @example Now.grid("month") // => [Now, Now, ...]
20
20
  *
21
21
  * @param {string} [scope] Grid scope
22
- * @returns {Array<PicoNowInterface>} Array of dates
22
+ * @returns {Array<PicoNow>} Array of dates
23
23
  */
24
- grid(scope : string = 'day') : Array<PicoNowInterface>
24
+ grid(scope : string = 'day') : Array<PicoNow>
25
25
  {
26
26
  if ( /^seconds?$/i.test(scope) ) {
27
27
  return this.getSecondsGrid();
@@ -64,9 +64,9 @@ export class PicoNowGrid
64
64
  * @example Now.getSecondsGrid(10)
65
65
  *
66
66
  * @param {number} [interval] Step interval
67
- * @returns {Array<PicoNowInterface>} Array of dates
67
+ * @returns {Array<PicoNow>} Array of dates
68
68
  */
69
- getSecondsGrid(interval : number = 1) : Array<PicoNowInterface>
69
+ getSecondsGrid(interval : number = 1) : Array<PicoNow>
70
70
  {
71
71
  if ( interval == null ) {
72
72
  interval = 1;
@@ -83,9 +83,9 @@ export class PicoNowGrid
83
83
  * @example Now.getMinutesGrid(10)
84
84
  *
85
85
  * @param {number} [interval] Step interval
86
- * @returns {Array<PicoNowInterface>} Array of dates
86
+ * @returns {Array<PicoNow>} Array of dates
87
87
  */
88
- getMinutesGrid(interval : number = 1) : Array<PicoNowInterface>
88
+ getMinutesGrid(interval : number = 1) : Array<PicoNow>
89
89
  {
90
90
  if ( interval == null ) {
91
91
  interval = 1;
@@ -102,9 +102,9 @@ export class PicoNowGrid
102
102
  * @example Now.getHoursGrid(2)
103
103
  *
104
104
  * @param {number} [interval] Step interval
105
- * @returns {Array<PicoNowInterface>} Array of dates
105
+ * @returns {Array<PicoNow>} Array of dates
106
106
  */
107
- getHoursGrid(interval : number = 1) : Array<PicoNowInterface>
107
+ getHoursGrid(interval : number = 1) : Array<PicoNow>
108
108
  {
109
109
  if ( interval == null ) {
110
110
  interval = 1;
@@ -120,9 +120,9 @@ export class PicoNowGrid
120
120
  *
121
121
  * @example Now.getDaysGrid()
122
122
  *
123
- * @returns {Array<PicoNowInterface>} Array of dates
123
+ * @returns {Array<PicoNow>} Array of dates
124
124
  */
125
- getDaysGrid() : Array<PicoNowInterface>
125
+ getDaysGrid() : Array<PicoNow>
126
126
  {
127
127
  let dates = [
128
128
  this.first('date').first('day'), this.last('date').last('day')
@@ -136,9 +136,9 @@ export class PicoNowGrid
136
136
  *
137
137
  * @example Now.getDatesGrid()
138
138
  *
139
- * @returns {Array<PicoNowInterface>} Array of dates
139
+ * @returns {Array<PicoNow>} Array of dates
140
140
  */
141
- getDatesGrid() : Array<PicoNowInterface>
141
+ getDatesGrid() : Array<PicoNow>
142
142
  {
143
143
  let dates = [
144
144
  this.first('date'), this.last('date')
@@ -152,9 +152,9 @@ export class PicoNowGrid
152
152
  *
153
153
  * @example Now.getMonthsGrid()
154
154
  *
155
- * @returns {Array<PicoNowInterface>} Array of dates
155
+ * @returns {Array<PicoNow>} Array of dates
156
156
  */
157
- getMonthsGrid() : Array<PicoNowInterface>
157
+ getMonthsGrid() : Array<PicoNow>
158
158
  {
159
159
  let dates = [
160
160
  this.first('month'), this.last('month')
@@ -168,9 +168,9 @@ export class PicoNowGrid
168
168
  *
169
169
  * @example Now.getYearsGrid()
170
170
  *
171
- * @returns {Array<PicoNowInterface>} Array of dates
171
+ * @returns {Array<PicoNow>} Array of dates
172
172
  */
173
- getYearsGrid() : Array<PicoNowInterface>
173
+ getYearsGrid() : Array<PicoNow>
174
174
  {
175
175
  let dates = [
176
176
  this.first('year'), this.clone().last('year')
@@ -184,9 +184,9 @@ export class PicoNowGrid
184
184
  *
185
185
  * @example Now.getDecadesGrid()
186
186
  *
187
- * @returns {Array<PicoNowInterface>} Array of dates
187
+ * @returns {Array<PicoNow>} Array of dates
188
188
  */
189
- getDecadesGrid() : Array<PicoNowInterface>
189
+ getDecadesGrid() : Array<PicoNow>
190
190
  {
191
191
  let dates = [
192
192
  this.first('decade'), this.clone().last('decade')
@@ -201,7 +201,7 @@ export class PicoNowGrid
201
201
  * @deprecated use Now.grid instead
202
202
  */
203
203
  // @ts-ignore
204
- PicoNowGrid.prototype.getYears = function() : Array<PicoNowInterface> {
204
+ PicoNowGrid.prototype.getYears = function() : Array<PicoNow> {
205
205
  console.warn('Now.getYears() is deprecated, use Now.grid(\'years\') instead.');
206
206
  return this.grid('years');
207
207
  };
@@ -210,7 +210,7 @@ PicoNowGrid.prototype.getYears = function() : Array<PicoNowInterface> {
210
210
  * @deprecated use Now.grid instead
211
211
  */
212
212
  // @ts-ignore
213
- PicoNowGrid.prototype.getMonths = function() : Array<PicoNowInterface> {
213
+ PicoNowGrid.prototype.getMonths = function() : Array<PicoNow> {
214
214
  console.warn('Now.getMonths() is deprecated, use Now.grid(\'months\') instead.');
215
215
  return this.grid('months');
216
216
  };
@@ -219,7 +219,7 @@ PicoNowGrid.prototype.getMonths = function() : Array<PicoNowInterface> {
219
219
  * @deprecated use Now.grid instead
220
220
  */
221
221
  // @ts-ignore
222
- PicoNowGrid.prototype.getDates = function() : Array<PicoNowInterface> {
222
+ PicoNowGrid.prototype.getDates = function() : Array<PicoNow> {
223
223
  console.warn('Now.getDates() is deprecated, use Now.grid(\'dates\') instead.');
224
224
  return this.grid('dates');
225
225
  };
@@ -228,7 +228,7 @@ PicoNowGrid.prototype.getDates = function() : Array<PicoNowInterface> {
228
228
  * @deprecated use Now.grid instead
229
229
  */
230
230
  // @ts-ignore
231
- PicoNowGrid.prototype.getHours = function() : Array<PicoNowInterface> {
231
+ PicoNowGrid.prototype.getHours = function() : Array<PicoNow> {
232
232
  console.warn('Now.getHours() is deprecated, use Now.grid(\'hours\') instead.');
233
233
  return this.grid('hours');
234
234
  };
@@ -237,7 +237,7 @@ PicoNowGrid.prototype.getHours = function() : Array<PicoNowInterface> {
237
237
  * @deprecated use Now.grid instead
238
238
  */
239
239
  // @ts-ignore
240
- PicoNowGrid.prototype.getMinutes = function() : Array<PicoNowInterface> {
240
+ PicoNowGrid.prototype.getMinutes = function() : Array<PicoNow> {
241
241
  console.warn('Now.getMinutes() is deprecated, use Now.grid(\'minutes\') instead.');
242
242
  return this.grid('minutes');
243
243
  };
@@ -246,7 +246,7 @@ PicoNowGrid.prototype.getMinutes = function() : Array<PicoNowInterface> {
246
246
  * @deprecated use Now.grid instead
247
247
  */
248
248
  // @ts-ignore
249
- PicoNowGrid.prototype.getSeconds = function() : Array<PicoNowInterface> {
249
+ PicoNowGrid.prototype.getSeconds = function() : Array<PicoNow> {
250
250
  console.warn('Now.getSeconds() is deprecated, use Now.grid(\'seconds\') instead.');
251
251
  return this.grid('seconds');
252
252
  };
@@ -66,7 +66,7 @@ export class PicoNowHuman
66
66
  */
67
67
  getHumanDay(substr : number = null) : string
68
68
  {
69
- let day = this.day() - 1;
69
+ let day = this.day();
70
70
 
71
71
  if ( !NOW_HUMAN_DAYS[day] ) {
72
72
  throw new Error(`Invalid day number "${day}".`);
@@ -91,7 +91,7 @@ export class PicoNowHuman
91
91
  */
92
92
  getHumanMonth(substr : number = null) : string
93
93
  {
94
- let month = this.day() - 1;
94
+ let month = this.month() - 1;
95
95
 
96
96
  if ( !NOW_HUMAN_MONTHS[month] ) {
97
97
  throw new Error(`Invalid month number "${month}".`);
package/src/utils/Now.ts CHANGED
@@ -62,9 +62,9 @@ export class PicoNow extends trait(PicoNowPlugins)
62
62
  /**
63
63
  * Original input value
64
64
  *
65
- * @type {any}
65
+ * @type {Date}
66
66
  */
67
- input : any = null;
67
+ input : Date = null;
68
68
 
69
69
  /**
70
70
  * Current Date instance
@@ -195,7 +195,8 @@ export class PicoNow extends trait(PicoNowPlugins)
195
195
  */
196
196
  valid() : boolean
197
197
  {
198
- return !isNaN(this.input);
198
+ // @ts-ignore
199
+ return !isNaN(this.input) && !isNaN(this.value);
199
200
  }
200
201
 
201
202
  /**
@@ -111,6 +111,32 @@ export class PicoNumber
111
111
  return Math.round(value);
112
112
  }
113
113
 
114
+ /**
115
+ * Keep value within min and max range
116
+ *
117
+ * @example Num.minmax(10, 0, 5) // => 0
118
+ * @example Num.minmax(-1, 0, 5) // => 5
119
+ *
120
+ * @param {any} value Input value
121
+ * @param {number} [min=0] Minimum value
122
+ * @param {number} [max=Number.MAX_SAFE_INTEGER] Maximum value
123
+ * @returns {number} Normalized value
124
+ */
125
+ static minmax(value : any, min : number = 0, max : number = Number.MAX_SAFE_INTEGER) : number
126
+ {
127
+ value = Mix.num(value);
128
+
129
+ if ( value < min ) {
130
+ value = max;
131
+ }
132
+
133
+ if ( value > max ) {
134
+ value = min;
135
+ }
136
+
137
+ return Mix.num(value);
138
+ }
139
+
114
140
  /**
115
141
  * Sum numbers in list
116
142
  *
@@ -1,4 +1,4 @@
1
- import { PicoNowInterface } from "../utils/Now.ts";
1
+ import { PicoNow, PicoNowInterface } from "../utils/Now.ts";
2
2
  import PicoNowWalker from "./NowWalker.js";
3
3
  export interface PicoNowGrid extends PicoNowInterface, PicoNowWalker {
4
4
  }
@@ -12,75 +12,75 @@ export declare class PicoNowGrid {
12
12
  * @example Now.grid("month") // => [Now, Now, ...]
13
13
  *
14
14
  * @param {string} [scope] Grid scope
15
- * @returns {Array<PicoNowInterface>} Array of dates
15
+ * @returns {Array<PicoNow>} Array of dates
16
16
  */
17
- grid(scope?: string): Array<PicoNowInterface>;
17
+ grid(scope?: string): Array<PicoNow>;
18
18
  /**
19
19
  * Get seconds grid
20
20
  *
21
21
  * @example Now.getSecondsGrid(10)
22
22
  *
23
23
  * @param {number} [interval] Step interval
24
- * @returns {Array<PicoNowInterface>} Array of dates
24
+ * @returns {Array<PicoNow>} Array of dates
25
25
  */
26
- getSecondsGrid(interval?: number): Array<PicoNowInterface>;
26
+ getSecondsGrid(interval?: number): Array<PicoNow>;
27
27
  /**
28
28
  * Get minutes grid
29
29
  *
30
30
  * @example Now.getMinutesGrid(10)
31
31
  *
32
32
  * @param {number} [interval] Step interval
33
- * @returns {Array<PicoNowInterface>} Array of dates
33
+ * @returns {Array<PicoNow>} Array of dates
34
34
  */
35
- getMinutesGrid(interval?: number): Array<PicoNowInterface>;
35
+ getMinutesGrid(interval?: number): Array<PicoNow>;
36
36
  /**
37
37
  * Get hours grid
38
38
  *
39
39
  * @example Now.getHoursGrid(2)
40
40
  *
41
41
  * @param {number} [interval] Step interval
42
- * @returns {Array<PicoNowInterface>} Array of dates
42
+ * @returns {Array<PicoNow>} Array of dates
43
43
  */
44
- getHoursGrid(interval?: number): Array<PicoNowInterface>;
44
+ getHoursGrid(interval?: number): Array<PicoNow>;
45
45
  /**
46
46
  * Get days grid
47
47
  *
48
48
  * @example Now.getDaysGrid()
49
49
  *
50
- * @returns {Array<PicoNowInterface>} Array of dates
50
+ * @returns {Array<PicoNow>} Array of dates
51
51
  */
52
- getDaysGrid(): Array<PicoNowInterface>;
52
+ getDaysGrid(): Array<PicoNow>;
53
53
  /**
54
54
  * Get dates grid
55
55
  *
56
56
  * @example Now.getDatesGrid()
57
57
  *
58
- * @returns {Array<PicoNowInterface>} Array of dates
58
+ * @returns {Array<PicoNow>} Array of dates
59
59
  */
60
- getDatesGrid(): Array<PicoNowInterface>;
60
+ getDatesGrid(): Array<PicoNow>;
61
61
  /**
62
62
  * Get months grid
63
63
  *
64
64
  * @example Now.getMonthsGrid()
65
65
  *
66
- * @returns {Array<PicoNowInterface>} Array of dates
66
+ * @returns {Array<PicoNow>} Array of dates
67
67
  */
68
- getMonthsGrid(): Array<PicoNowInterface>;
68
+ getMonthsGrid(): Array<PicoNow>;
69
69
  /**
70
70
  * Get years grid
71
71
  *
72
72
  * @example Now.getYearsGrid()
73
73
  *
74
- * @returns {Array<PicoNowInterface>} Array of dates
74
+ * @returns {Array<PicoNow>} Array of dates
75
75
  */
76
- getYearsGrid(): Array<PicoNowInterface>;
76
+ getYearsGrid(): Array<PicoNow>;
77
77
  /**
78
78
  * Get decades grid
79
79
  *
80
80
  * @example Now.getDecadesGrid()
81
81
  *
82
- * @returns {Array<PicoNowInterface>} Array of dates
82
+ * @returns {Array<PicoNow>} Array of dates
83
83
  */
84
- getDecadesGrid(): Array<PicoNowInterface>;
84
+ getDecadesGrid(): Array<PicoNow>;
85
85
  }
86
86
  export default PicoNowGrid;
@@ -38,9 +38,9 @@ export declare class PicoNow extends PicoNow_base {
38
38
  /**
39
39
  * Original input value
40
40
  *
41
- * @type {any}
41
+ * @type {Date}
42
42
  */
43
- input: any;
43
+ input: Date;
44
44
  /**
45
45
  * Current Date instance
46
46
  *
@@ -60,6 +60,18 @@ export declare class PicoNumber {
60
60
  * @returns {number} Rounded value
61
61
  */
62
62
  static round(value: any): number;
63
+ /**
64
+ * Keep value within min and max range
65
+ *
66
+ * @example Num.minmax(10, 0, 5) // => 0
67
+ * @example Num.minmax(-1, 0, 5) // => 5
68
+ *
69
+ * @param {any} value Input value
70
+ * @param {number} [min=0] Minimum value
71
+ * @param {number} [max=Number.MAX_SAFE_INTEGER] Maximum value
72
+ * @returns {number} Normalized value
73
+ */
74
+ static minmax(value: any, min?: number, max?: number): number;
63
75
  /**
64
76
  * Sum numbers in list
65
77
  *