@esmate/utils 1.0.0

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,16 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Vien Dinh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
7
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ persons to whom the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11
+ Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @esmate/react
2
+
3
+ ## React Hooks
4
+
5
+ ### useSearchParam
6
+
7
+ React sensor hook that tracks browser's location search param.
8
+
9
+ ```tsx
10
+ import { useSearchParam } from "@esmate/react/hooks/use-search-param";
11
+
12
+ export function Search() {
13
+ const searchParam = useSearchParam();
14
+
15
+ return <div>{searchParam.get("q")}</div>;
16
+ }
17
+ ```
18
+
19
+ #### Caveats/Gotchas
20
+
21
+ When using a hash router, like `react-router`'s
22
+ [`<HashRouter>`](https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/docs/api/HashRouter.md),
23
+ this hook won't be able to read the search parameters as they are considered part of the hash of the URL by browsers.
@@ -0,0 +1,6 @@
1
+ export interface TimeZone {
2
+ name: string;
3
+ value: string;
4
+ offset: string;
5
+ }
6
+ export declare function getTimeZoneList(): TimeZone[];
package/dist/locale.js ADDED
@@ -0,0 +1,20 @@
1
+ function getTimeZoneList() {
2
+ const timeZones = Intl.supportedValuesOf("timeZone");
3
+ const getOffset = (timeZone)=>{
4
+ const offset = new Intl.DateTimeFormat("en-US", {
5
+ timeZone,
6
+ timeZoneName: "longOffset"
7
+ }).formatToParts(new Date()).find((part)=>"timeZoneName" === part.type)?.value || "GMT";
8
+ return "GMT" === offset ? "+00:00" : offset.replace("GMT", "");
9
+ };
10
+ return timeZones.map((value)=>{
11
+ const offset = getOffset(value);
12
+ const place = (value.split("/").pop() || value).replaceAll("_", " ");
13
+ return {
14
+ name: `${offset} ${place}`,
15
+ value,
16
+ offset
17
+ };
18
+ }).sort((a, b)=>a.offset.localeCompare(b.offset) || a.name.localeCompare(b.name));
19
+ }
20
+ export { getTimeZoneList };
@@ -0,0 +1,2 @@
1
+ export * from "iso-639-1";
2
+ export { default } from "iso-639-1";
@@ -0,0 +1,4 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_iso_639_1_39eb3c8b__ from "iso-639-1";
2
+ export * from "iso-639-1";
3
+ var __webpack_exports__default = __WEBPACK_EXTERNAL_MODULE_iso_639_1_39eb3c8b__["default"];
4
+ export { __webpack_exports__default as default };
@@ -0,0 +1,2 @@
1
+ export * from "tiny-invariant";
2
+ export { default } from "tiny-invariant";
@@ -0,0 +1,4 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_tiny_invariant_25fdef25__ from "tiny-invariant";
2
+ export * from "tiny-invariant";
3
+ var __webpack_exports__default = __WEBPACK_EXTERNAL_MODULE_tiny_invariant_25fdef25__["default"];
4
+ export { __webpack_exports__default as default };
@@ -0,0 +1,2 @@
1
+ export * from "title";
2
+ export { default } from "title";
@@ -0,0 +1,4 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_title__ from "title";
2
+ export * from "title";
3
+ var __webpack_exports__default = __WEBPACK_EXTERNAL_MODULE_title__["default"];
4
+ export { __webpack_exports__default as default };
@@ -0,0 +1 @@
1
+ export * from "typopo";
@@ -0,0 +1 @@
1
+ export * from "typopo";
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@esmate/utils",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "description": "JavaScript/TypeScript utils, functions, and classes in one package.",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/viendinhcom/esmate.git"
10
+ },
11
+ "keywords": [
12
+ "esmate",
13
+ "utils",
14
+ "tools",
15
+ "classes",
16
+ "functions",
17
+ "javascript",
18
+ "typescript"
19
+ ],
20
+ "exports": {
21
+ "./lib/*": {
22
+ "types": "./dist/lib/*.d.ts",
23
+ "import": "./dist/lib/*.js"
24
+ },
25
+ "./pkgs/*": {
26
+ "types": "./dist/pkgs/*.d.ts",
27
+ "import": "./dist/pkgs/*.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "dependencies": {
34
+ "@types/typopo": "^2.5.4",
35
+ "iso-639-1": "^3.1.5",
36
+ "tiny-invariant": "^1.3.3",
37
+ "title": "^4.0.1",
38
+ "typopo": "^2.7.1"
39
+ },
40
+ "devDependencies": {
41
+ "@esmate/eslint": "^1.1.2",
42
+ "@esmate/prettier": "^1.0.5",
43
+ "@rslib/core": "^0.7.1",
44
+ "@types/fs-extra": "^11.0.4",
45
+ "@types/node": "^22.18.7",
46
+ "@types/react": "^18.3.24",
47
+ "@types/react-dom": "^18.3.7",
48
+ "eslint": "^9.36.0",
49
+ "fs-extra": "^11.3.2",
50
+ "globby": "^14.1.0",
51
+ "prettier": "^3.6.2",
52
+ "react": "^18.3.1",
53
+ "react-dom": "^18.3.1",
54
+ "tsx": "^4.20.6",
55
+ "typescript": "^5.9.2"
56
+ },
57
+ "scripts": {
58
+ "build": "tsx export.ts && rslib build",
59
+ "dev": "rslib build --watch",
60
+ "start": "astro preview",
61
+ "fix": "prettier --write . && eslint --fix .",
62
+ "check": "tsc && prettier --check . && eslint ."
63
+ }
64
+ }