@zuzjs/core 0.1.1

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.
@@ -0,0 +1,27 @@
1
+ export declare const setCookie: (key: string, value: any, expiry?: number, host?: string) => string | undefined;
2
+ export declare const getCookie: (key: string) => string | {
3
+ [key: string]: string;
4
+ } | null;
5
+ export declare const removeCookie: (key: string) => void;
6
+ export declare const uuid: (len?: number) => string;
7
+ export declare const isEmail: (e: string) => boolean;
8
+ export declare const formatBytes: (bytes: number) => string;
9
+ export declare const formatSeconds: (n: number) => string;
10
+ export declare const formatTime: (time: (string | number)[]) => string;
11
+ export declare const createElem: (tag: string, classes?: string[], attrs?: {
12
+ [key: string]: string;
13
+ }) => HTMLElement;
14
+ export type ElementNode = {
15
+ tag: string;
16
+ id?: string;
17
+ text?: string;
18
+ classes?: string[];
19
+ attrs?: {
20
+ [x: string]: string;
21
+ };
22
+ childs?: ElementNode[];
23
+ };
24
+ export declare const createElems: (list: ElementNode[]) => Node[];
25
+ export declare const getPlatform: () => "MAC" | "WIN" | "UNKNOWN";
26
+ export declare const findParent: (node: HTMLElement, classes: string[], depth?: number) => HTMLElement | null;
27
+ export declare const ucfirst: (str: string) => string;
package/dist/index.js ADDED
@@ -0,0 +1,75 @@
1
+ import Hashids from "hashids";
2
+ import { nanoid } from "nanoid";
3
+ import Cookies from 'js-cookie';
4
+ const _Hashids = new Hashids('', 4);
5
+ export const setCookie = (key, value, expiry, host) => Cookies.set(key, value, { expires: expiry || 7, domain: host || window.location.host });
6
+ export const getCookie = (key) => key == `` ? Cookies.get() : Cookies.get(key) || null;
7
+ export const removeCookie = (key) => Cookies.remove(key);
8
+ export const uuid = (len = 11) => nanoid(len);
9
+ export const isEmail = (e) => {
10
+ let reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
11
+ return reg.test(e);
12
+ };
13
+ export const formatBytes = (bytes) => {
14
+ var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
15
+ if (bytes == 0)
16
+ return '0 Byte';
17
+ var i = Math.floor(Math.log(bytes) / Math.log(1024)), nx = bytes / Math.pow(1024, i);
18
+ return nx.toFixed(2) + ' ' + sizes[i];
19
+ };
20
+ export const formatSeconds = (n) => {
21
+ let d = new Date(n * 1000).toISOString().slice(11, 19);
22
+ return d.indexOf("00:") > -1 ? d.replace("00:", "") : d;
23
+ };
24
+ export const formatTime = (time) => {
25
+ let _time = time.toString().match(/^([01]\d|2[0-3])(:)([0-5]\d)(:[0-5]\d)?$/) || [time];
26
+ let __ = [];
27
+ if (_time.length > 1) { // If time format correct
28
+ __ = _time.slice(1); // Remove full string match value
29
+ __[5] = +_time[0] < 12 ? 'AM' : 'PM'; // Set AM/PM
30
+ __[0] = +_time[0] % 12 || 12;
31
+ }
32
+ return __.join('');
33
+ };
34
+ export const createElem = (tag, classes = [], attrs = {}) => {
35
+ for (var el = window.document.createElement(tag), i = 0; i < classes.length; i++)
36
+ "" != classes[i] && el.classList.add(classes[i]);
37
+ if (Object.keys(attrs).length > 0)
38
+ Object.keys(attrs)
39
+ .map((k) => el.setAttribute(k, attrs[k]));
40
+ return el;
41
+ };
42
+ export const createElems = (list) => {
43
+ let r = [], o;
44
+ list.map((item) => {
45
+ if (item.tag) {
46
+ o = createElem(item.tag, item.classes || [], item.attrs || {});
47
+ if (item.childs && item.childs.length > 0) {
48
+ let c = createElems(item.childs);
49
+ c.map((f) => o.appendChild(f));
50
+ }
51
+ else if (item.text && "" != item.text) {
52
+ // o = document.createTextNode(item.text)
53
+ o.textContent = item.text;
54
+ }
55
+ r.push(o);
56
+ }
57
+ });
58
+ return r;
59
+ };
60
+ export const getPlatform = () => {
61
+ return undefined !== typeof window ?
62
+ window.navigator.platform.toUpperCase().indexOf("MAC") > -1 ? `MAC` : `WIN` : `UNKNOWN`;
63
+ };
64
+ export const findParent = (node, classes, depth = 1) => {
65
+ var n, i = node.parentNode, o = 0, a = 0;
66
+ if (null === i || !i.classList || i.classList.length == 0)
67
+ return null;
68
+ for (n = classes.length; a < n; ++a)
69
+ i.classList.contains(classes[a]) && (o += 1);
70
+ return o === n ? i : 0 < depth ? findParent(i, classes, depth - 1) : null;
71
+ };
72
+ export const ucfirst = (str) => {
73
+ return str = str.trim(),
74
+ str.charAt(0).toUpperCase() + str.substring(1);
75
+ };
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@zuzjs/core",
3
+ "version": "0.1.1",
4
+ "keywords": [
5
+ "react",
6
+ "zuz",
7
+ "zuz.js"
8
+ ],
9
+ "description": "ZuzJS Core",
10
+ "author": "Zuz.js Team <support@zuz.com.pk>",
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "main": "dist/index.js",
14
+ "exports": {
15
+ ".": "./dist/index.js"
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "dev": "tsc -d -w -p tsconfig.json"
22
+ },
23
+ "engines": {
24
+ "node": ">=18.17.0"
25
+ },
26
+ "dependencies": {
27
+ "axios": "1.6.5",
28
+ "hashids": "2.3.0",
29
+ "js-cookie": "3.0.5",
30
+ "nanoid": "5.0.4",
31
+ "prettier": "3.2.4"
32
+ }
33
+ }