@wikicasa-dev/utilities 1.0.3 → 1.0.5

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=e=>e.includes("@gmail");async function i(e){const r=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",r);return Array.from(new Uint8Array(n)).map(a=>a.toString(16).padStart(2,"0")).join("")}const h=e=>{const r=e.split("@");if(r.length<2)throw new Error("The email has nothing before the '@' symbol");const n=r[0];let s="";for(const t of n)if(t!=="."){if(t==="+")break;s+=t}return`${s}@${r[1]}`},c=e=>{if(!e||!e.trim())throw new Error("The email in null or empty");let r=e;return o(r)&&(r=h(e)),i(r)};exports.hashEmail=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=e=>e.includes("@gmail"),a=async e=>{const r=new TextEncoder().encode(e),n=await crypto.subtle.digest("SHA-256",r);return Array.from(new Uint8Array(n)).map(o=>o.toString(16).padStart(2,"0")).join("")},i=e=>{const r=e.split("@");if(r.length<2)throw new Error("The email has nothing before the '@' symbol");const n=r[0];let s="";for(const t of n)if(t!=="."){if(t==="+")break;s+=t}return`${s}@${r[1]}`},c=e=>{if(!e||!e.trim())throw new Error("The email in null or empty");let r=e;return h(r)&&(r=i(e)),a(r)};exports.hash256=a;exports.hashEmail=c;
@@ -1,9 +1,7 @@
1
- const a = (r) => r.includes("@gmail");
2
- async function h(r) {
1
+ const a = (r) => r.includes("@gmail"), h = async (r) => {
3
2
  const e = new TextEncoder().encode(r), t = await crypto.subtle.digest("SHA-256", e);
4
3
  return Array.from(new Uint8Array(t)).map((o) => o.toString(16).padStart(2, "0")).join("");
5
- }
6
- const i = (r) => {
4
+ }, i = (r) => {
7
5
  const e = r.split("@");
8
6
  if (e.length < 2)
9
7
  throw new Error("The email has nothing before the '@' symbol");
@@ -23,5 +21,6 @@ const i = (r) => {
23
21
  return a(e) && (e = i(r)), h(e);
24
22
  };
25
23
  export {
24
+ h as hash256,
26
25
  c as hashEmail
27
26
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n={maximumAge:6*60*1e3,timeout:10*1e3},o=()=>!!window.navigator.geolocation,r=(t=n)=>{if(o())return new Promise((e,i)=>{navigator.geolocation.getCurrentPosition(e,i,t)})};exports.browserSupportGeolocation=o;exports.getUserPosition=r;
@@ -0,0 +1,19 @@
1
+ const i = {
2
+ //maximum age in milliseconds of a possible cached position
3
+ maximumAge: 36e4,
4
+ //--> 1 hour
5
+ //maximum length of time (in milliseconds) the device is allowed to take in order to return a position
6
+ timeout: 1e4
7
+ //--> 10 sec
8
+ }, n = () => !!window.navigator.geolocation, r = (o = i) => {
9
+ if (n())
10
+ return new Promise(
11
+ (t, e) => {
12
+ navigator.geolocation.getCurrentPosition(t, e, o);
13
+ }
14
+ );
15
+ };
16
+ export {
17
+ n as browserSupportGeolocation,
18
+ r as getUserPosition
19
+ };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./ArrayUtils.cjs"),u=require("./ColorUtils.cjs"),i=require("./CookieUtils.cjs"),d=require("./CurrencyUtils.cjs"),b=require("./DateUtils.cjs"),o=require("./DeviceDetectionUtils.cjs"),s=require("./DOMUtils.cjs"),O=require("./EmailUtils.cjs"),l=require("./FunctionUtils.cjs"),n=require("./GenericUtils.cjs"),t=require("./NumberUtils.cjs"),a=require("./ObjectUtils.cjs"),R=require("./ObserverUtils.cjs"),c=require("./PermissionUtils.cjs"),E=require("./RESB_UrlBuilder.cjs"),r=require("./StringUtils.cjs"),C=require("./URLBuilderUtils.cjs"),e=require("./RegexUtils.cjs");exports.isArrNullOrEmpty=m.isArrNullOrEmpty;exports.rgba=u.rgba;exports.decodeCookie=i.decodeCookie;exports.encodeCookie=i.encodeCookie;exports.getCookie=i.getCookie;exports.removeCookie=i.removeCookie;exports.formatCurrency=d.formatCurrency;exports.formatDate=b.formatDate;exports.getCurrentDeviceSize=o.getCurrentDeviceSize;exports.isMobile=o.isMobile;exports.isSafari=o.isSafari;exports.isiOSDevice=o.isiOSDevice;exports.emptyElem=s.emptyElem;exports.getSingleElement=s.getSingleElement;exports.hideElem=s.hideElem;exports.showElem=s.showElem;exports.hashEmail=O.hashEmail;exports.debounce=l.debounce;exports.isPromise=l.isPromise;exports.awaitableSetTimeout=n.awaitableSetTimeout;exports.createCustomEvent=n.createCustomEvent;exports.formatFloat=t.formatFloat;exports.formatInteger=t.formatInteger;exports.formatLocaleNumber=t.formatLocaleNumber;exports.formatNumber=t.formatNumber;exports.formatterNumberObj=t.formatterNumberObj;exports.parseLocaleNumber=t.parseLocaleNumber;exports.deepCopy=a.deepCopy;exports.isEmptyObject=a.isEmptyObject;exports.shallowCopyObjectTo=a.shallowCopyObjectTo;exports.observeOnce=R.observeOnce;exports.addPermissionStateListener=c.addPermissionStateListener;exports.onNotificationsPermissionChange=c.onNotificationsPermissionChange;exports.buildParams=E.buildParams;exports.buildParamsForAgency=E.buildParamsForAgency;exports.buildURL=E.buildURL;exports.capitalizeFirstLetter=r.capitalizeFirstLetter;exports.cleanASCII=r.cleanASCII;exports.decodeTextWithEntities=r.decodeTextWithEntities;exports.formatAddress=r.formatAddress;exports.replaceAll=r.replaceAll;exports.replaceAllTokens=r.replaceAllTokens;exports.stringToHyphened=r.stringToHyphened;exports.appendQueryString=C.appendQueryString;exports.COMPETITOR_REGEX=e.COMPETITOR_REGEX;exports.DATE_REGEX=e.DATE_REGEX;exports.EMAIL_REGEX=e.EMAIL_REGEX;exports.EMAIL_REGEX_INTO_TEXT=e.EMAIL_REGEX_INTO_TEXT;exports.EXCLUDED_REGEX=e.EXCLUDED_REGEX;exports.GLOBAL_PHONE_REGEX=e.GLOBAL_PHONE_REGEX;exports.PASSWORD_REGEX=e.PASSWORD_REGEX;exports.PHONE_REGEX=e.PHONE_REGEX;exports.ROOMS_REGEX=e.ROOMS_REGEX;exports.SQM_REGEX=e.SQM_REGEX;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./ArrayUtils.cjs"),b=require("./ColorUtils.cjs"),i=require("./CookieUtils.cjs"),O=require("./CurrencyUtils.cjs"),p=require("./DateUtils.cjs"),o=require("./DeviceDetectionUtils.cjs"),s=require("./DOMUtils.cjs"),n=require("./EmailUtils.cjs"),E=require("./FunctionUtils.cjs"),c=require("./GenericUtils.cjs"),t=require("./NumberUtils.cjs"),a=require("./ObjectUtils.cjs"),R=require("./ObserverUtils.cjs"),m=require("./PermissionUtils.cjs"),l=require("./RESB_UrlBuilder.cjs"),r=require("./StringUtils.cjs"),S=require("./URLBuilderUtils.cjs"),e=require("./RegexUtils.cjs"),u=require("./GeolocationUtils.cjs");exports.isArrNullOrEmpty=d.isArrNullOrEmpty;exports.rgba=b.rgba;exports.decodeCookie=i.decodeCookie;exports.encodeCookie=i.encodeCookie;exports.getCookie=i.getCookie;exports.removeCookie=i.removeCookie;exports.formatCurrency=O.formatCurrency;exports.formatDate=p.formatDate;exports.getCurrentDeviceSize=o.getCurrentDeviceSize;exports.isMobile=o.isMobile;exports.isSafari=o.isSafari;exports.isiOSDevice=o.isiOSDevice;exports.emptyElem=s.emptyElem;exports.getSingleElement=s.getSingleElement;exports.hideElem=s.hideElem;exports.showElem=s.showElem;exports.hash256=n.hash256;exports.hashEmail=n.hashEmail;exports.debounce=E.debounce;exports.isPromise=E.isPromise;exports.awaitableSetTimeout=c.awaitableSetTimeout;exports.createCustomEvent=c.createCustomEvent;exports.formatFloat=t.formatFloat;exports.formatInteger=t.formatInteger;exports.formatLocaleNumber=t.formatLocaleNumber;exports.formatNumber=t.formatNumber;exports.formatterNumberObj=t.formatterNumberObj;exports.parseLocaleNumber=t.parseLocaleNumber;exports.deepCopy=a.deepCopy;exports.isEmptyObject=a.isEmptyObject;exports.shallowCopyObjectTo=a.shallowCopyObjectTo;exports.observeOnce=R.observeOnce;exports.addPermissionStateListener=m.addPermissionStateListener;exports.onNotificationsPermissionChange=m.onNotificationsPermissionChange;exports.buildParams=l.buildParams;exports.buildParamsForAgency=l.buildParamsForAgency;exports.buildURL=l.buildURL;exports.capitalizeFirstLetter=r.capitalizeFirstLetter;exports.cleanASCII=r.cleanASCII;exports.decodeTextWithEntities=r.decodeTextWithEntities;exports.formatAddress=r.formatAddress;exports.replaceAll=r.replaceAll;exports.replaceAllTokens=r.replaceAllTokens;exports.stringToHyphened=r.stringToHyphened;exports.appendQueryString=S.appendQueryString;exports.COMPETITOR_REGEX=e.COMPETITOR_REGEX;exports.DATE_REGEX=e.DATE_REGEX;exports.EMAIL_REGEX=e.EMAIL_REGEX;exports.EMAIL_REGEX_INTO_TEXT=e.EMAIL_REGEX_INTO_TEXT;exports.EXCLUDED_REGEX=e.EXCLUDED_REGEX;exports.GLOBAL_PHONE_REGEX=e.GLOBAL_PHONE_REGEX;exports.PASSWORD_REGEX=e.PASSWORD_REGEX;exports.PHONE_REGEX=e.PHONE_REGEX;exports.ROOMS_REGEX=e.ROOMS_REGEX;exports.SQM_REGEX=e.SQM_REGEX;exports.browserSupportGeolocation=u.browserSupportGeolocation;exports.getUserPosition=u.getUserPosition;
package/dist/index.d.ts CHANGED
@@ -16,3 +16,4 @@ export * from './utils/RESB_UrlBuilder';
16
16
  export * from './utils/StringUtils';
17
17
  export * from './utils/URLBuilderUtils';
18
18
  export * from './utils/RegexUtils';
19
+ export * from './utils/GeolocationUtils';
package/dist/index.js CHANGED
@@ -1,74 +1,78 @@
1
1
  import { isArrNullOrEmpty as r } from "./ArrayUtils.js";
2
2
  import { rgba as m } from "./ColorUtils.js";
3
- import { decodeCookie as E, encodeCookie as a, getCookie as p, removeCookie as f } from "./CookieUtils.js";
3
+ import { decodeCookie as a, encodeCookie as E, getCookie as p, removeCookie as s } from "./CookieUtils.js";
4
4
  import { formatCurrency as l } from "./CurrencyUtils.js";
5
5
  import { formatDate as c } from "./DateUtils.js";
6
- import { getCurrentDeviceSize as d, isMobile as b, isSafari as O, isiOSDevice as u } from "./DeviceDetectionUtils.js";
7
- import { emptyElem as C, getSingleElement as _, hideElem as S, showElem as X } from "./DOMUtils.js";
8
- import { hashEmail as G } from "./EmailUtils.js";
9
- import { debounce as g, isPromise as L } from "./FunctionUtils.js";
10
- import { awaitableSetTimeout as N, createCustomEvent as P } from "./GenericUtils.js";
11
- import { formatFloat as D, formatInteger as I, formatLocaleNumber as M, formatNumber as k, formatterNumberObj as v, parseLocaleNumber as j } from "./NumberUtils.js";
12
- import { deepCopy as F, isEmptyObject as H, shallowCopyObjectTo as z } from "./ObjectUtils.js";
13
- import { observeOnce as U } from "./ObserverUtils.js";
14
- import { addPermissionStateListener as B, onNotificationsPermissionChange as q } from "./PermissionUtils.js";
15
- import { buildParams as K, buildParamsForAgency as V, buildURL as Y } from "./RESB_UrlBuilder.js";
16
- import { capitalizeFirstLetter as $, cleanASCII as ee, decodeTextWithEntities as oe, formatAddress as re, replaceAll as te, replaceAllTokens as me, stringToHyphened as ie } from "./StringUtils.js";
17
- import { appendQueryString as ae } from "./URLBuilderUtils.js";
18
- import { COMPETITOR_REGEX as fe, DATE_REGEX as se, EMAIL_REGEX as le, EMAIL_REGEX_INTO_TEXT as ne, EXCLUDED_REGEX as ce, GLOBAL_PHONE_REGEX as xe, PASSWORD_REGEX as de, PHONE_REGEX as be, ROOMS_REGEX as Oe, SQM_REGEX as ue } from "./RegexUtils.js";
6
+ import { getCurrentDeviceSize as d, isMobile as b, isSafari as u, isiOSDevice as O } from "./DeviceDetectionUtils.js";
7
+ import { emptyElem as C, getSingleElement as S, hideElem as _, showElem as G } from "./DOMUtils.js";
8
+ import { hash256 as g, hashEmail as A } from "./EmailUtils.js";
9
+ import { debounce as h, isPromise as L } from "./FunctionUtils.js";
10
+ import { awaitableSetTimeout as y, createCustomEvent as N } from "./GenericUtils.js";
11
+ import { formatFloat as I, formatInteger as M, formatLocaleNumber as k, formatNumber as v, formatterNumberObj as w, parseLocaleNumber as j } from "./NumberUtils.js";
12
+ import { deepCopy as H, isEmptyObject as U, shallowCopyObjectTo as z } from "./ObjectUtils.js";
13
+ import { observeOnce as W } from "./ObserverUtils.js";
14
+ import { addPermissionStateListener as q, onNotificationsPermissionChange as J } from "./PermissionUtils.js";
15
+ import { buildParams as V, buildParamsForAgency as Y, buildURL as Z } from "./RESB_UrlBuilder.js";
16
+ import { capitalizeFirstLetter as ee, cleanASCII as oe, decodeTextWithEntities as re, formatAddress as te, replaceAll as me, replaceAllTokens as ie, stringToHyphened as ae } from "./StringUtils.js";
17
+ import { appendQueryString as pe } from "./URLBuilderUtils.js";
18
+ import { COMPETITOR_REGEX as fe, DATE_REGEX as le, EMAIL_REGEX as ne, EMAIL_REGEX_INTO_TEXT as ce, EXCLUDED_REGEX as xe, GLOBAL_PHONE_REGEX as de, PASSWORD_REGEX as be, PHONE_REGEX as ue, ROOMS_REGEX as Oe, SQM_REGEX as Re } from "./RegexUtils.js";
19
+ import { browserSupportGeolocation as Se, getUserPosition as _e } from "./GeolocationUtils.js";
19
20
  export {
20
21
  fe as COMPETITOR_REGEX,
21
- se as DATE_REGEX,
22
- le as EMAIL_REGEX,
23
- ne as EMAIL_REGEX_INTO_TEXT,
24
- ce as EXCLUDED_REGEX,
25
- xe as GLOBAL_PHONE_REGEX,
26
- de as PASSWORD_REGEX,
27
- be as PHONE_REGEX,
22
+ le as DATE_REGEX,
23
+ ne as EMAIL_REGEX,
24
+ ce as EMAIL_REGEX_INTO_TEXT,
25
+ xe as EXCLUDED_REGEX,
26
+ de as GLOBAL_PHONE_REGEX,
27
+ be as PASSWORD_REGEX,
28
+ ue as PHONE_REGEX,
28
29
  Oe as ROOMS_REGEX,
29
- ue as SQM_REGEX,
30
- B as addPermissionStateListener,
31
- ae as appendQueryString,
32
- N as awaitableSetTimeout,
33
- K as buildParams,
34
- V as buildParamsForAgency,
35
- Y as buildURL,
36
- $ as capitalizeFirstLetter,
37
- ee as cleanASCII,
38
- P as createCustomEvent,
39
- g as debounce,
40
- E as decodeCookie,
41
- oe as decodeTextWithEntities,
42
- F as deepCopy,
30
+ Re as SQM_REGEX,
31
+ q as addPermissionStateListener,
32
+ pe as appendQueryString,
33
+ y as awaitableSetTimeout,
34
+ Se as browserSupportGeolocation,
35
+ V as buildParams,
36
+ Y as buildParamsForAgency,
37
+ Z as buildURL,
38
+ ee as capitalizeFirstLetter,
39
+ oe as cleanASCII,
40
+ N as createCustomEvent,
41
+ h as debounce,
42
+ a as decodeCookie,
43
+ re as decodeTextWithEntities,
44
+ H as deepCopy,
43
45
  C as emptyElem,
44
- a as encodeCookie,
45
- re as formatAddress,
46
+ E as encodeCookie,
47
+ te as formatAddress,
46
48
  l as formatCurrency,
47
49
  c as formatDate,
48
- D as formatFloat,
49
- I as formatInteger,
50
- M as formatLocaleNumber,
51
- k as formatNumber,
52
- v as formatterNumberObj,
50
+ I as formatFloat,
51
+ M as formatInteger,
52
+ k as formatLocaleNumber,
53
+ v as formatNumber,
54
+ w as formatterNumberObj,
53
55
  p as getCookie,
54
56
  d as getCurrentDeviceSize,
55
- _ as getSingleElement,
56
- G as hashEmail,
57
- S as hideElem,
57
+ S as getSingleElement,
58
+ _e as getUserPosition,
59
+ g as hash256,
60
+ A as hashEmail,
61
+ _ as hideElem,
58
62
  r as isArrNullOrEmpty,
59
- H as isEmptyObject,
63
+ U as isEmptyObject,
60
64
  b as isMobile,
61
65
  L as isPromise,
62
- O as isSafari,
63
- u as isiOSDevice,
64
- U as observeOnce,
65
- q as onNotificationsPermissionChange,
66
+ u as isSafari,
67
+ O as isiOSDevice,
68
+ W as observeOnce,
69
+ J as onNotificationsPermissionChange,
66
70
  j as parseLocaleNumber,
67
- f as removeCookie,
68
- te as replaceAll,
69
- me as replaceAllTokens,
71
+ s as removeCookie,
72
+ me as replaceAll,
73
+ ie as replaceAllTokens,
70
74
  m as rgba,
71
75
  z as shallowCopyObjectTo,
72
- X as showElem,
73
- ie as stringToHyphened
76
+ G as showElem,
77
+ ae as stringToHyphened
74
78
  };
@@ -23,8 +23,8 @@ type BreakpointType = {
23
23
  xl: number;
24
24
  };
25
25
  /**
26
- * Determines the current device size based on the window.innerWidth and provided breakpoints.
27
- * @param breakpoints - An object containing the breakpoints for different device sizes.
26
+ * Returns the current device size based on the window.innerWidth and provided breakpoints.
27
+ * @param breakpoints - An object containing breakpoints for different device sizes. Defaults to { sm: 576, md: 768, lg: 992, xl: 1200 }.
28
28
  * @returns A string indicating the current device size: "desktop", "mobile", or "tablet".
29
29
  */
30
30
  export declare const getCurrentDeviceSize: (breakpoints?: BreakpointType) => "desktop" | "mobile" | "tablet";
@@ -1,2 +1,17 @@
1
1
  import type { Nullable } from "@wikicasa-dev/types";
2
+ /**
3
+ * Calculates the SHA-256 hash of the input string.
4
+ *
5
+ * @param string - The string to be hashed using the SHA-256 algorithm.
6
+ * @returns A Promise that resolves to the hexadecimal representation of the SHA-256 hash.
7
+ */
8
+ export declare const hash256: (string: string) => Promise<string>;
9
+ /**
10
+ * Takes a nullable email address, normalizes it if it is a Gmail address by removing dots and ignoring characters after '+',
11
+ * and then hashes it using SHA-256 algorithm.
12
+ *
13
+ * @param emailToNormalize - The email address to be normalized and hashed.
14
+ * @returns A Promise that resolves to the hashed email address.
15
+ * @throws Error if the email is null, empty, or if normalization fails.
16
+ */
2
17
  export declare const hashEmail: (emailToNormalize: Nullable<string>) => Promise<string>;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Checks if the browser supports geolocation.
3
+ * @returns A boolean indicating whether the browser supports geolocation.
4
+ */
5
+ export declare const browserSupportGeolocation: () => boolean;
6
+ /**
7
+ * Gets the user's geolocation position.
8
+ * @param options - The options for getting the geolocation position. Defaults to { maximumAge: 6*60*1000, timeout: 10*1000 }.
9
+ * @returns A promise that resolves with the geolocation position.
10
+ */
11
+ export declare const getUserPosition: (options?: PositionOptions) => Promise<GeolocationPosition> | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wikicasa-dev/utilities",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Wikicasa frontend utilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -38,7 +38,7 @@
38
38
  "typescript": "^5.4.3",
39
39
  "vite": "^5.2.3",
40
40
  "vite-plugin-dts": "^3.7.3",
41
- "@wikicasa-dev/types": "^1.0.11"
41
+ "@wikicasa-dev/types": "^1.2.1"
42
42
  },
43
43
  "dependencies": {
44
44
  "axios": "^1.4.0",