@unparallel/url-manager 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 UNPARALLEL Innovation, Lda
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,26 @@
1
+ # URL Manager
2
+
3
+ Element used to store an retrieved query parameters from the URL encoded in JSON
4
+
5
+ ## Constructor
6
+
7
+ ```typescript
8
+ const urlManager = new URLManager({ id: "page" })
9
+ ```
10
+
11
+ **id:** each instance have an id, this allows to have in the same URL several jsons, this could be useful to store the data of different elements in the ame url
12
+
13
+ ## Methods
14
+
15
+ ```typescript
16
+ urlManager.updateKey<T=any>(key: string, value: T, addToHistoric?: boolean)
17
+ ```
18
+ Updates a JSON entry, by providing a key/value pair
19
+
20
+ ```typescript
21
+ urlManager.getKeyFromComponent<T = any>(key: string): T | undefined
22
+ ```
23
+ Obtains the JSON associated with a key
24
+
25
+ ## Example
26
+ A React Component with an example is available in "/src/App.tsx" on this repository
@@ -0,0 +1,20 @@
1
+ import { EventEmitter } from 'events';
2
+ import { URLManagerTools, StringHM } from '../URLManagerTools';
3
+ export interface URLManagerProps {
4
+ id: string;
5
+ hashChain?: StringHM;
6
+ urlManagerComponentId?: string;
7
+ }
8
+ export declare class URLManager extends URLManagerTools {
9
+ id: string;
10
+ disableUrlManager: boolean;
11
+ hashLength: number;
12
+ hash: string;
13
+ events: EventEmitter;
14
+ urlManagerComponentId: string | undefined;
15
+ constructor(props: URLManagerProps, disableUrlManager?: boolean);
16
+ setNewHashChain(hashChain: StringHM): void;
17
+ updateKey<T = any>(key: string, value: T, addToHistoric?: boolean): void;
18
+ getKeyFromComponent<T = any>(key: string): T | undefined;
19
+ getJSONFromComponent(hash: string): any;
20
+ }
@@ -0,0 +1,45 @@
1
+ var l = Object.defineProperty;
2
+ var c = (h, e, t) => e in h ? l(h, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[e] = t;
3
+ var o = (h, e, t) => c(h, typeof e != "symbol" ? e + "" : e, t);
4
+ import m from "query-string";
5
+ import { EventEmitter as u } from "events";
6
+ import { URLManagerTools as w } from "../URLManagerTools/index.js";
7
+ class n extends w {
8
+ constructor(t, s) {
9
+ super();
10
+ o(this, "id");
11
+ o(this, "disableUrlManager");
12
+ o(this, "hashLength");
13
+ o(this, "hash");
14
+ o(this, "events");
15
+ o(this, "urlManagerComponentId");
16
+ this.id = t.id, this.disableUrlManager = !!s, this.hashLength = 6, this.hash = n.generateHash(this.id, t.hashChain), this.events = new u(), this.urlManagerComponentId = t.urlManagerComponentId;
17
+ }
18
+ setNewHashChain(t) {
19
+ const s = this.hash;
20
+ this.hash = n.generateHash(this.id, t), s != this.hash && this.events.emit("hashChange", this.hash);
21
+ }
22
+ updateKey(t, s, i) {
23
+ if (this.disableUrlManager)
24
+ return;
25
+ const d = { [t]: s };
26
+ let r = this.getJSONFromComponent(this.hash);
27
+ r = { ...r, ...d }, console.log(r);
28
+ const a = new URL(window.location.href);
29
+ a.searchParams.set(this.hash, n.getEncodedStrFromJSON(r)), i ? window.history.pushState({}, "", a) : window.history.pushState({}, "", a);
30
+ }
31
+ getKeyFromComponent(t) {
32
+ if (window.location) {
33
+ const i = m.parse(window.location.search)[this.hash];
34
+ if (typeof i == "string")
35
+ return n.getJSONFromEncodedStr(i)[t];
36
+ }
37
+ }
38
+ getJSONFromComponent(t) {
39
+ if (window.location)
40
+ return n.getJSONFromHash(t, window.location.search);
41
+ }
42
+ }
43
+ export {
44
+ n as URLManager
45
+ };
@@ -0,0 +1,18 @@
1
+ export interface StringHM {
2
+ [k: string]: any;
3
+ }
4
+ export interface URLManagerRequest<T = StringHM> {
5
+ id: string;
6
+ json: T;
7
+ hashChain?: StringHM;
8
+ }
9
+ export declare class URLManagerTools {
10
+ static getJSONFromHash(hash: string, parameters: string): any;
11
+ static getJSONFromId(id: string, parameters: string, hashChain?: StringHM): any;
12
+ static getJSONFromEncodedStr(encodedStr: string): any;
13
+ static getUrlParameterForId(id: string, json: StringHM, hashChain?: StringHM): string;
14
+ static getUrlParameterForHash(hash: string, json: StringHM): string;
15
+ static generateURLParameters(requests: URLManagerRequest[]): string | undefined;
16
+ static getEncodedStrFromJSON(json: StringHM): string;
17
+ static generateHash(id: string, hashChain?: StringHM): string;
18
+ }
@@ -0,0 +1,47 @@
1
+ import c from "query-string";
2
+ import h from "object-hash";
3
+ class d {
4
+ static getJSONFromHash(t, r) {
5
+ const e = c.parse(r)[t];
6
+ if (typeof e == "string")
7
+ return this.getJSONFromEncodedStr(e);
8
+ }
9
+ static getJSONFromId(t, r, s) {
10
+ const e = this.generateHash(t, s);
11
+ return this.getJSONFromHash(e, r);
12
+ }
13
+ static getJSONFromEncodedStr(t) {
14
+ const r = decodeURIComponent(t);
15
+ return JSON.parse(r);
16
+ }
17
+ static getUrlParameterForId(t, r, s) {
18
+ const e = this.generateHash(t, s);
19
+ return this.getUrlParameterForHash(e, r);
20
+ }
21
+ static getUrlParameterForHash(t, r) {
22
+ const s = this.getEncodedStrFromJSON(r);
23
+ return t + "=" + s;
24
+ }
25
+ static generateURLParameters(t) {
26
+ if (Array.isArray(t)) {
27
+ const r = [];
28
+ return t.forEach((s) => {
29
+ const { id: e, json: a, hashChain: o } = s, n = this.getUrlParameterForId(e, a, o);
30
+ r.push(n);
31
+ }), r.join("&");
32
+ }
33
+ }
34
+ //static generateJSONFromUrlParamet
35
+ static getEncodedStrFromJSON(t) {
36
+ const r = JSON.stringify(t);
37
+ return encodeURIComponent(r);
38
+ }
39
+ static generateHash(t, r) {
40
+ const e = { id: t, ...r };
41
+ let a = h(e);
42
+ return a = a.substring(0, 6), a;
43
+ }
44
+ }
45
+ export {
46
+ d as URLManagerTools
47
+ };
package/dist/main.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { URLManager } from './URLManager';
2
+ export type { URLManagerProps } from './URLManager';
3
+ export { URLManagerTools } from './URLManagerTools';
4
+ export type { URLManagerRequest, StringHM } from './URLManagerTools';
package/dist/main.js ADDED
@@ -0,0 +1,6 @@
1
+ import { URLManager as a } from "./URLManager/index.js";
2
+ import { URLManagerTools as f } from "./URLManagerTools/index.js";
3
+ export {
4
+ a as URLManager,
5
+ f as URLManagerTools
6
+ };
@@ -0,0 +1,2 @@
1
+ import { CSSProperties } from 'react';
2
+ export declare function getBorderStyle(): CSSProperties;
package/dist/method.js ADDED
@@ -0,0 +1,6 @@
1
+ function r() {
2
+ return { border: "1px solid red" };
3
+ }
4
+ export {
5
+ r as getBorderStyle
6
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@unparallel/url-manager",
3
+ "private": false,
4
+ "version": "0.0.1",
5
+ "type": "module",
6
+ "main": "dist/main.js",
7
+ "types": "dist/main.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "dev": "vite",
13
+ "build": "tsc --p ./tsconfig.build.json && vite build",
14
+ "prepublishOnly": "npm run build",
15
+ "lint": "eslint .",
16
+ "preview": "vite preview"
17
+ },
18
+ "sideEffects": [
19
+ "**/*.css"
20
+ ],
21
+ "dependencies": {
22
+ "events": "^3.3.0",
23
+ "object-hash": "^3.0.0",
24
+ "query-string": "^9.3.1"
25
+ },
26
+ "devDependencies": {
27
+ "@eslint/js": "^9.17.0",
28
+ "@release-it/keep-a-changelog": "^7.0.1",
29
+ "@types/events": "^3.0.3",
30
+ "@types/object-hash": "^3.0.6",
31
+ "@types/react": "^18.3.18",
32
+ "@types/react-dom": "^18.3.5",
33
+ "@vitejs/plugin-react": "^4.3.4",
34
+ "eslint": "^9.17.0",
35
+ "eslint-plugin-react-hooks": "^5.0.0",
36
+ "eslint-plugin-react-refresh": "^0.4.16",
37
+ "glob": "^11.0.1",
38
+ "globals": "^15.14.0",
39
+ "react": "^19.2.4",
40
+ "react-dom": "^19.2.4",
41
+ "release-it": "^19.2.4",
42
+ "typescript": "~5.6.2",
43
+ "typescript-eslint": "^8.18.2",
44
+ "vite": "^6.0.5",
45
+ "vite-plugin-dts": "^4.5.0",
46
+ "vite-plugin-lib-inject-css": "^2.2.1"
47
+ }
48
+ }