@osimatic/helpers-js 1.4.20 → 1.4.22

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.
Files changed (3) hide show
  1. package/date_time.js +15 -0
  2. package/package.json +1 -1
  3. package/string.js +29 -0
package/date_time.js CHANGED
@@ -298,6 +298,16 @@ class DateTime {
298
298
  }
299
299
 
300
300
  class DatePeriod {
301
+ static isSameDay(jsDate1, jsDate2) {
302
+ return jsDate1.getFullYear() === jsDate2.getFullYear() &&
303
+ jsDate1.getMonth() === jsDate2.getMonth() &&
304
+ jsDate1.getDate() === jsDate2.getDate();
305
+ }
306
+
307
+ static isHalfDay(partOfDay) {
308
+ return partOfDay === DatePeriod.PART_OF_DAY_MORNING || partOfDay === DatePeriod.PART_OF_DAY_AFTERNOON;
309
+ }
310
+
301
311
  static getNbDayBetweenTwo(jsDate1, jsDate2, asPeriod=false, timeZone="Europe/Paris") {
302
312
  //jsDate1.set
303
313
  if (jsDate1 == null || jsDate2 == null) {
@@ -627,4 +637,9 @@ class SqlDateTime {
627
637
 
628
638
  }
629
639
 
640
+ // Part of day
641
+ DatePeriod.PART_OF_DAY_MORNING = 'MORNING';
642
+ DatePeriod.PART_OF_DAY_AFTERNOON = 'AFTERNOON';
643
+
644
+
630
645
  module.exports = { DateTime, DatePeriod, TimestampUnix, SqlDate, SqlTime, SqlDateTime };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osimatic/helpers-js",
3
- "version": "1.4.20",
3
+ "version": "1.4.22",
4
4
  "main": "main.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/string.js CHANGED
@@ -136,6 +136,21 @@ String.prototype.isNumeric = String.prototype.isNumeric || function() {
136
136
  return IsNumber;
137
137
  }
138
138
 
139
+ String.prototype.isBase64 = String.prototype.isBase64 || function() {
140
+ // Vérifie les caractères autorisés par le base64
141
+ if (!/^[A-Za-z0-9+/=]+$/.test(this)) return false;
142
+
143
+ // Longueur multiple de 4
144
+ if (this.length % 4 !== 0) return false;
145
+
146
+ try {
147
+ atob(this); // Tentative de décodage
148
+ return true; // OK → c’est du base64
149
+ } catch (e) {
150
+ return false; // Erreur → pas du base64
151
+ }
152
+ }
153
+
139
154
  // s'utilise : "ma chaine {0} de caracteres"
140
155
  if (!String.format) {
141
156
  String.format = function(format) {
@@ -144,6 +159,20 @@ if (!String.format) {
144
159
  };
145
160
  }
146
161
 
162
+ if (!JSON.encodeJsonForDataAttr) {
163
+ JSON.encodeJsonForDataAttr = function(obj) {
164
+ const json = JSON.stringify(obj);
165
+ return btoa(encodeURIComponent(json));
166
+ }
167
+ }
168
+
169
+ if (!JSON.decodeJsonFromDataAttr) {
170
+ JSON.decodeJsonFromDataAttr = function(str) {
171
+ const json = decodeURIComponent(atob(str));
172
+ return JSON.parse(json);
173
+ }
174
+ }
175
+
147
176
  /*
148
177
  function selectionnerContenuNode(node) {
149
178
  if (window.getSelection) {