@apia/util 0.0.7

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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Initiator
2
+
3
+ Este package se creó con la única utilidad de copiarlo entero y pegarlo a la hora de crear un nuevo package.
4
+
5
+ Este iniciador permite crear un paquete que compila typescript y puede ser importado desde otros packages.
6
+
7
+ ## Procedimiento
8
+
9
+ - Copiar la carpeta initiator y pegarla con otro nombre dentro de packages.
10
+ - Modificar el package.json:
11
+ - Eliminar la línea ```private: true```.
12
+ - Cambiar el nombre del package en la propiedad "name".
13
+ - Cambiar el repositorio en "repository".
14
+ - Ejecutar el comando lerna bootstrap desde la carpeta raíz.
15
+
16
+ Luego de ejecutar estos pasos, el package estaría listo para comenzar a usarse.
17
+
18
+ Este package trae como dependencias por defecto theme-ui y react. Si se desea agregar más dependencias se debe ejecutar el comando ```lerna add --scope="@apia/packageName" dependencyName```. Ejemplo, si creamos un paquete con el nombre @apia/myPackage y queremos agregar lodash como dependencia, ejecutamos el comando ```lerna add --scope="@apia/myPackage" lodash```. **Importante**: lerna no permite instalar de a varias dependencias a la vez como lo hace npm, por lo tanto, si se desea agregar varias dependencias se debe ejecutar el comando anterior tantas veces como dependencias se quiera agregar.
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";var re=Object.create;var x=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var ae=(e,t)=>{for(var r in t)x(e,r,{get:t[r],enumerable:!0})},O=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of oe(t))!ie.call(e,o)&&o!==r&&x(e,o,{get:()=>t[o],enumerable:!(n=ne(t,o))||n.enumerable});return e};var l=(e,t,r)=>(r=e!=null?re(se(e)):{},O(t||!e||!e.__esModule?x(r,"default",{value:e,enumerable:!0}):r,e)),ce=e=>O(x({},"__esModule",{value:!0}),e);var Y=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var f=(e,t,r)=>(Y(e,t,"read from private field"),r?r.call(e):t.get(e)),k=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},v=(e,t,r,n)=>(Y(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);var $=(e,t,r)=>new Promise((n,o)=>{var s=c=>{try{a(r.next(c))}catch(d){o(d)}},i=c=>{try{a(r.throw(c))}catch(d){o(d)}},a=c=>c.done?n(c.value):Promise.resolve(c.value).then(s,i);a((r=r.apply(e,t)).next())});var je={};ae(je,{EventEmitter:()=>m,WithEventsValue:()=>b,addBoundary:()=>ve,apiaDateToStandarFormat:()=>V,arrayOrArray:()=>R,cantFocusSelector:()=>_,customEvents:()=>de,dateToApiaFormat:()=>J,debugDispatcher:()=>T,decrypt:()=>ue,enableDebugDispatcher:()=>fe,encrypt:()=>le,focusSelector:()=>ye,formatMessage:()=>Me,getDateFormat:()=>h,getFocusSelector:()=>he,getIndex:()=>B,getLabel:()=>De,getSpecificParent:()=>C,getValueByPath:()=>G,isChild:()=>ge,isDebugDispatcherEnabled:()=>P,noNaN:()=>Fe,parseAsSize:()=>Ae,parseXmlAsync:()=>te,persistentStorage:()=>Z,setValueByPath:()=>Pe,shortcutController:()=>pe,toBoolean:()=>Ce,useCombinedRefs:()=>be,useLatest:()=>xe,useMount:()=>ke,usePrevious:()=>we,useStateRef:()=>Ke,useUnmount:()=>Ee,useUpdateEffect:()=>Se});module.exports=ce(je);function R(e){return Array.isArray(e)?e:[e]}var j=require("lodash-es");function B(e,t,r){for(let n=0;n<t.length;n++)if(typeof t[n]=="boolean"&&t[n]||(0,j.isFunction)(t[n])&&t[n]())return e[n];return e[r!=null?r:-1]}var y=l(require("crypto-js"));var A=l(require("crypto-js")),E=(e,t,r,n)=>A.default.PBKDF2(t,A.default.enc.Hex.parse(e),{keySize:r/32,iterations:n});var ue=(e,t,r,n,o,s)=>{let i=E(e,r,o,s),a=y.default.lib.CipherParams.create({ciphertext:y.default.enc.Base64.parse(n)});return y.default.AES.decrypt(a,i,{iv:y.default.enc.Hex.parse(t)}).toString(y.default.enc.Utf8)};var w=l(require("crypto-js"));var le=(e,t,r,n,o,s)=>{let i=E(e,r,o,s);return w.default.AES.encrypt(n,i,{iv:w.default.enc.Hex.parse(t)}).ciphertext.toString(w.default.enc.Base64)};var F=!0;function P(){return F}function fe(){F=!0}var T=new class{constructor(){this.callbacks={};this.actions={shout:()=>{console.log(Object.keys(this.callbacks))}};this.emit=(t,...r)=>{var n,o,s,i;if(this.actions[t])this.actions[t]();else{if(((n=this.callbacks[t])!=null?n:[]).length===1)return(s=(o=this.callbacks[t])==null?void 0:o[0])==null?void 0:s.call(o,r);((i=this.callbacks[t])!=null?i:[]).forEach(a=>a(r))}return null}}on(t,r,n,o=!1){if(!F&&o)return()=>{};if(Object.keys(this.actions).includes(t))throw new Error(`The action ${t} is a reserved word for the dispatcher.`);this.callbacks[t]||(this.callbacks[t]=[]);let s=Object.assign(r,{help:()=>{typeof n=="string"&&console.info(n)}});return this.callbacks[t].push(s),this[t]=Object.assign((...i)=>{this.emit(t,...i)},{help:()=>{typeof n=="string"&&console.info(n)}}),()=>{this.off(t,r)}}off(t,r){this.callbacks[t]=this.callbacks[t].filter(n=>n!==r)}};window.dd=T;window.adt=T;var pe=new class{constructor(){this.history=[];this.candidates=[];this.shortcuts={callbacks:[],children:[],key:{key:""}};this.shortcutsStrings=[];this.categories={dev:["shift&D"]};document.addEventListener("keydown",t=>{var r;((r=t.key)==null?void 0:r.length)!==1&&t.key!=="Escape"||(this.candidates=[...this.candidates.reduce((n,o)=>[...n,...o.children.filter(s=>s.key.key===t.key&&s.key.altKey===t.altKey&&s.key.ctrlKey===t.ctrlKey&&s.key.shiftKey===t.shiftKey)],[]),...this.shortcuts.children.filter(n=>n.key.key===t.key&&n.key.altKey===t.altKey&&n.key.ctrlKey===t.ctrlKey&&n.key.shiftKey===t.shiftKey)],this.candidates.forEach(n=>{var o;(n.fireEvenFromInputs||!(!t.key||t.key.length>1||["input","textarea","select"].includes((o=t.target.tagName)==null?void 0:o.toLowerCase())))&&n.callbacks&&n.callbacks.forEach(s=>s(t))}))}),T.on("shortcuts",()=>{console.info(this.shortcutsStrings),console.info(this.shortcuts,this.history)},"Muestra los shortcuts registrados"),this.on("short".split(""),()=>{this.shortcutsStrings.forEach(t=>console.info(t))},"dev")}parseKeyToString(t){return typeof t=="string"?t:`${t.altKey?"alt&":""}${t.ctrlKey?"ctrl&":""}${t.shiftKey?"shift&":""}${t.key}`}parseKey(t){let r=t.split("&"),n=r.includes("alt"),o=r.includes("ctrl"),s=r.includes("shift"),i=r.find(a=>a!=="shift"&&a!=="alt"&&a!=="ctrl");if(!i)throw new Error(`parseKey "${t}" does not have key.`);return{key:i,altKey:n,ctrlKey:o,shiftKey:s}}on(t,r,n,o){if(n==="dev"&&P())return;let s=this.shortcuts,i=n?[...this.categories[n],...t]:t;if(this.shortcutsStrings.includes(i.map(a=>this.parseKeyToString(a)).join(""))){console.warn(`The shortcut ${i.map(a=>this.parseKeyToString(a)).join("")} is being setted twice. The controller wont register more than one instance but this could be a hint if some unexpected behavior.`);return}for(let a of i){let c=typeof a=="string"?this.parseKey(a):a;if(c.key==="")throw new Error("Empty key ('') is not allowed");let d=s.children.find(u=>u.key.key===c.key||u.key.key===""&&u.key.altKey===c.altKey&&u.key.ctrlKey===c.ctrlKey&&u.key.shiftKey===c.shiftKey&&u.fireEvenFromInputs===o);if(d)s=d;else{let u={callbacks:[],children:[],key:c,fireEvenFromInputs:o};s.children.push(u),s=u}}this.shortcutsStrings.push(i.map(a=>this.parseKeyToString(a)).join("")),s.callbacks.push(r)}};var H=l(require("dayjs"));var L=l(require("dayjs")),I=l(require("dayjs/plugin/customParseFormat"));L.default.extend(I.default);var me="DD/MM/YYYY",h=()=>{switch(window.DATE_FORMAT){case"m/d/Y":return"MM/DD/YYYY";case"d/m/Y":return me;case"Y/m/d":return"YYYY/MM/DD";default:return"DD/MM/YYYY"}};function V(e){let t=(0,H.default)(e,h());return t.isValid()?t.format("YYYY-MM-DD"):""}var z=l(require("dayjs"));function J(e){return(0,z.default)(e).format(h())}var de={focus:"customFocus",iframeModalChangeTitle:"iframeModalChangeTitle",iframeModalClose:"iframeModalClose",iframeModalNotify:"iframeModalNotify",modalClose:"modalClose",hidePanel:"hidePanel",showPanel:"showPanel"};var _=["[disabled]",'[tabIndex="-1"]','[aria-hidden="true"]',"[readonly]","[data-focus-guard]",".modal__closeButton"].map(e=>`:not(${e})`).join(""),ye=["input","textarea","select","a","button:not(.toggleAccordionElement)","[contenteditable]","[tabIndex]",'[role="button"]'].map(e=>`${e}${_}`).join(",");function he(e){return`input${e!=null?e:""},
2
+ textarea${e!=null?e:""},
3
+ select${e!=null?e:""},
4
+ a${e!=null?e:""},
5
+ button:not(.toggleAccordionElement)${e!=null?e:""},
6
+ [contenteditable]${e!=null?e:""},
7
+ [tabIndex]${e!=null?e:""}`}function C(e,t){let r=e;for(;e!==document.documentElement&&r;){let n=t(r);if(n===null)return null;if(n)return r;let o=r.parentElement;if(o)r=o;else return null}return null}function ge(e,t){return!!C(e,t)}function Te(){let e={};return{on(t,r){var n;return Array.isArray(e[t])||(e[t]=[]),(n=e[t])==null||n.push(r),()=>{this.off(t,r)}},off(t,r){var n;e[t]=((n=e[t])!=null?n:[]).filter(o=>o!==r)},emit(t,r){var n;((n=e[t])!=null?n:[]).forEach(o=>o(r))}}}var p,m=class{constructor(){k(this,p,Te())}on(t,r){return f(this,p).on(t,r),()=>{f(this,p).off(t,r)}}off(t,r){f(this,p).off(t,r)}emit(t,r){f(this,p).emit(t,r)}};p=new WeakMap;var g,b=class extends m{constructor(r){super();k(this,g,void 0);v(this,g,r)}get value(){return f(this,g)}set value(r){v(this,g,r),this.emit("update",r)}};g=new WeakMap;var K=l(require("react"));function be(...e){let[t,r]=K.useState();return K.useEffect(()=>{e.forEach(n=>{n&&(typeof n=="function"?n(t):n.current=t)})},[e,t]),r}var U=require("react");function xe(e){let t=(0,U.useRef)(e);return t.current=e,t}var W=require("react");function ke(e){(0,W.useEffect)(e,[])}var X=require("react");function Ee(e){(0,X.useEffect)(()=>e,[])}var N=require("react");function we(e){let t=(0,N.useRef)(void 0),r=(0,N.useRef)(void 0);return t.current=r.current,r.current=e,t}var S=require("react");function Ke(e){let[t,r]=(0,S.useState)(e),n=(0,S.useRef)(t);return n.current=t,[t,r,n]}var D=require("react");function Se(e,t){let r=(0,D.useRef)(!1);(0,D.useEffect)(()=>r.current?e():(r.current=!0,()=>{}),t)}function De(e){return window[e]}var Me=(e,t)=>{let r=e;return Object.entries(t).forEach(([n,o])=>{let s;o!==""?s=`<${n}>`:s=`"<${n}>"`,r!=null&&r.includes(s)&&(r=r.replace(s,o||" "))}),r};function ve(e,t,r,n){let o=typeof e=="number"?e:e.number,s=typeof e=="number"?t:e.min,i=typeof e=="number"?r:e.max,a=typeof e=="number"?n:e.loop,c=Number(o!=null?o:0);return s!==void 0&&c<s&&(i!==void 0&&a?c=i:c=s),i!==void 0&&c>i&&(s!==void 0&&a?c=s:c=i),c}var Re=["b","kb","mb","gb","tb"];function Ae(e){let t=0,r=e;if(r===1/0)return"1000GB";for(;r>1024;)r/=1024,t++;return`${Math.round(r*10)/10}${Re[t]}`}function Fe(e,t=0){let r=Number(e);return e===null||Number.isNaN(r)?t:r}function G(e,t,r="."){let n=typeof t=="string"?t.split(r):t;if(typeof e!="object"||!e)return n.length===0?e:void 0;let o=n.shift();return n.length===0?e[o]:G(e[o],n,r)}var q=require("lodash-es");function Pe(e,t,r){let n=t.split(".");if(n.length===0)return console.warn(`An empty path was provoided ${t}`),null;let o=(0,q.clone)(e!=null?e:{}),s=o;for(let i=0;i<n.length-1;i++)if(s[n[i]]||(s[n[i]]={}),typeof s[n[i]]=="object")s=s[n[i]];else throw console.info({originalObject:e,originalPath:t,currentObj:s,currentStep:n[i]}),new Error(`The provided path ${t} cannot be applied due to it is not an object's path.`);return s[n.pop()]=r,o}var Q=new Proxy({remove(e){localStorage.removeItem(e)}},{get(e,t){try{let r=localStorage.getItem(String(t));return r?JSON.parse(r):void 0}catch(r){return}},set(e,t,r){return localStorage.setItem(String(t),JSON.stringify(r)),!0}});window.persistentStorage=Q;var Z=Q;function Ce(e){return typeof e=="string"?!["false",""].includes(e.toLowerCase()):Array.isArray(e)?e.length>0:!!e}var ee=l(require("xml2js")),M=require("xml2js/lib/processors");var Ne=e=>e==="a"?"form":e==="b"?"field":e==="g"?"possibleValues":e==="h"?"item":e==="z"?"focusTo":e==="r"?"reload":e==="p"?"proccess":e==="d"?"valueAttr":e,Oe=e=>e==="t"?"text":e==="label"?"LABEL":e,Ye=(e,t)=>t==="v"&&e==="T"?!0:t==="v"&&e==="F"?!1:e;var $e=(e,t)=>t==="value"&&typeof e=="number"&&Number.isNaN(e)||t==="valueType"&&typeof e=="string"&&e==="null"?"":(t==="cols"||t==="rows"||t==="x"||t==="y"||t==="length")&&typeof e=="string"?(0,M.parseNumbers)(e):e,te=e=>$(void 0,null,function*(){let t=new ee.default.Parser({trim:!0,normalize:!0,explicitRoot:!1,mergeAttrs:!0,explicitArray:!1,charkey:"label",attrValueProcessors:[M.parseBooleans,$e,Ye],tagNameProcessors:[Ne],attrNameProcessors:[Oe]});return yield new Promise((n,o)=>{t.parseString(e,(s,i)=>{s?o(s):n(i)})})});0&&(module.exports={EventEmitter,WithEventsValue,addBoundary,apiaDateToStandarFormat,arrayOrArray,cantFocusSelector,customEvents,dateToApiaFormat,debugDispatcher,decrypt,enableDebugDispatcher,encrypt,focusSelector,formatMessage,getDateFormat,getFocusSelector,getIndex,getLabel,getSpecificParent,getValueByPath,isChild,isDebugDispatcherEnabled,noNaN,parseAsSize,parseXmlAsync,persistentStorage,setValueByPath,shortcutController,toBoolean,useCombinedRefs,useLatest,useMount,usePrevious,useStateRef,useUnmount,useUpdateEffect});
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@apia/util",
3
+ "version": "0.0.7",
4
+ "author": "alexisleite <alexisleite@live.com>",
5
+ "homepage": "",
6
+ "license": "MIT",
7
+ "engines": {
8
+ "node": ">=14.16"
9
+ },
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "sideEffects": false,
13
+ "files": [
14
+ "lib"
15
+ ],
16
+ "jest": {
17
+ "testEnvironment": "jsdom",
18
+ "testMatch": "**/__tests__/*.test.js",
19
+ "moduleNameMapper": {
20
+ "^@src/(.*)$": "<rootDir>/src/$1"
21
+ },
22
+ "coverageThreshold": {
23
+ "global": {
24
+ "branches": 80,
25
+ "functions": 80,
26
+ "lines": 80,
27
+ "statements": 80
28
+ }
29
+ }
30
+ },
31
+ "scripts": {
32
+ "build": "tsup",
33
+ "buildDev": "tsup",
34
+ "test": "node ./__tests__/util.test.js"
35
+ },
36
+ "dependencies": {
37
+ "@apia/notifications": "^0.0.7",
38
+ "@types/crypto-js": "^4.1.1",
39
+ "@types/xml2js": "^0.4.11",
40
+ "crypto-js": "^4.1.1",
41
+ "dayjs": "^1.11.7",
42
+ "lodash-es": "^4.17.21",
43
+ "node-polyfill-webpack-plugin": "^2.0.1",
44
+ "stream": "^0.0.2",
45
+ "stream-browserify": "^3.0.0",
46
+ "timers": "^0.1.1",
47
+ "timers-browserify": "^2.0.12",
48
+ "xml2js": "^0.4.23"
49
+ },
50
+ "devDependencies": {
51
+ "@types/lodash-es": "^4.17.7",
52
+ "tsup": "^6.6.3",
53
+ "type-fest": "^3.6.1",
54
+ "typescript": "^4.9.5"
55
+ },
56
+ "peerDependencies": {
57
+ "@emotion/react": "^11.10.6",
58
+ "react": "^18.2.0",
59
+ "react-dom": "^18.2.0"
60
+ },
61
+ "gitHead": "a3010b3c00d9f5eac216a167418750c391f4201d",
62
+ "repository": {
63
+ "type": "git",
64
+ "url": "http://corp-gitlab-01.domst.st.net/products/apia/ApiaNPMPackages.git",
65
+ "directory": "packages/util"
66
+ },
67
+ "publishConfig": {
68
+ "access": "public",
69
+ "registry": "https://registry.npmjs.org/"
70
+ }
71
+ }