@kuroson/sydneydayjs 0.1.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.
@@ -0,0 +1,5 @@
1
+ dist
2
+ .turbo
3
+ node_modules
4
+ coverage
5
+ logs
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Alvin Cherk
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,74 @@
1
+ # @kuroson/sydneydayjs
2
+
3
+ A pre-configured [dayjs](https://day.js.org/) wrapper with Sydney (Australia/Sydney) timezone as the default.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @kuroson/sydneydayjs
9
+ # or
10
+ pnpm add @kuroson/sydneydayjs
11
+ # or
12
+ yarn add @kuroson/sydneydayjs
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import { sydneyDayjs } from '@kuroson/sydneydayjs';
19
+
20
+ // Get current time in Sydney timezone
21
+ const now = sydneyDayjs.now();
22
+ console.log(now.format('YYYY-MM-DD HH:mm:ss')); // e.g., "2024-01-15 14:30:00"
23
+
24
+ // Create a date in Sydney timezone
25
+ const date = sydneyDayjs.create('2024-06-15');
26
+ console.log(date.format('YYYY-MM-DD HH:mm:ss Z')); // "2024-06-15 00:00:00 +10:00"
27
+
28
+ // All standard dayjs methods are available
29
+ console.log(now.add(1, 'day').format('dddd')); // e.g., "Tuesday"
30
+ console.log(now.startOf('month').format('YYYY-MM-DD')); // e.g., "2024-01-01"
31
+ ```
32
+
33
+ ## API
34
+
35
+ ### `sydneyDayjs.now()`
36
+
37
+ Returns a dayjs instance representing the current time in Sydney timezone.
38
+
39
+ ```typescript
40
+ const now = sydneyDayjs.now();
41
+ ```
42
+
43
+ ### `sydneyDayjs.create(date)`
44
+
45
+ Creates a dayjs instance from the given date input, interpreted in Sydney timezone.
46
+
47
+ ```typescript
48
+ // From string
49
+ const date1 = sydneyDayjs.create('2024-06-15');
50
+
51
+ // From Date object
52
+ const date2 = sydneyDayjs.create(new Date());
53
+
54
+ // From timestamp
55
+ const date3 = sydneyDayjs.create(1718409600000);
56
+ ```
57
+
58
+ ## Why?
59
+
60
+ When working with dates in Australia, you often need to ensure times are correctly handled in the `Australia/Sydney` timezone (AEST/AEDT). This package pre-configures dayjs with:
61
+
62
+ - The `utc` plugin
63
+ - The `timezone` plugin
64
+ - Default timezone set to `Australia/Sydney`
65
+
66
+ This means you don't have to remember to configure timezone handling every time - just import and use.
67
+
68
+ ## Requirements
69
+
70
+ - Node.js >= 22
71
+
72
+ ## License
73
+
74
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var dayjs = require('dayjs');
4
+ var timezone = require('dayjs/plugin/timezone');
5
+ var utc = require('dayjs/plugin/utc');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var dayjs__default = /*#__PURE__*/_interopDefault(dayjs);
10
+ var timezone__default = /*#__PURE__*/_interopDefault(timezone);
11
+ var utc__default = /*#__PURE__*/_interopDefault(utc);
12
+
13
+ // src/index.ts
14
+ var TIME_ZONE = "Australia/Sydney";
15
+ dayjs__default.default.extend(utc__default.default);
16
+ dayjs__default.default.extend(timezone__default.default);
17
+ dayjs__default.default.tz.setDefault(TIME_ZONE);
18
+ var sydneyDayjs = {
19
+ now: () => dayjs__default.default.tz(/* @__PURE__ */ new Date(), TIME_ZONE).tz(TIME_ZONE),
20
+ create: (date) => dayjs__default.default.tz(date, TIME_ZONE)
21
+ };
22
+
23
+ exports.sydneyDayjs = sydneyDayjs;
24
+ //# sourceMappingURL=index.cjs.map
25
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["dayjs","utc","timezone"],"mappings":";;;;;;;;;;;;;AAIA,IAAM,SAAA,GAAY,kBAAA;AAElBA,sBAAA,CAAM,OAAOC,oBAAG,CAAA;AAChBD,sBAAA,CAAM,OAAOE,yBAAQ,CAAA;AACrBF,sBAAA,CAAM,EAAA,CAAG,WAAW,SAAS,CAAA;AAEtB,IAAM,WAAA,GAAc;AAAA,EACzB,GAAA,EAAK,MAAMA,sBAAA,CAAM,EAAA,iBAAG,IAAI,MAAK,EAAG,SAAS,CAAA,CAAE,EAAA,CAAG,SAAS,CAAA;AAAA,EACvD,QAAQ,CAAC,IAAA,KAAsCA,sBAAA,CAAM,EAAA,CAAG,MAAM,SAAS;AACzE","file":"index.cjs","sourcesContent":["import dayjs from 'dayjs';\nimport timezone from 'dayjs/plugin/timezone';\nimport utc from 'dayjs/plugin/utc';\n\nconst TIME_ZONE = 'Australia/Sydney';\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\ndayjs.tz.setDefault(TIME_ZONE);\n\nexport const sydneyDayjs = {\n now: () => dayjs.tz(new Date(), TIME_ZONE).tz(TIME_ZONE),\n create: (date: Parameters<typeof dayjs>[0]) => dayjs.tz(date, TIME_ZONE),\n};\n"]}
@@ -0,0 +1,8 @@
1
+ import dayjs from 'dayjs';
2
+
3
+ declare const sydneyDayjs: {
4
+ now: () => dayjs.Dayjs;
5
+ create: (date: Parameters<typeof dayjs>[0]) => dayjs.Dayjs;
6
+ };
7
+
8
+ export { sydneyDayjs };
@@ -0,0 +1,8 @@
1
+ import dayjs from 'dayjs';
2
+
3
+ declare const sydneyDayjs: {
4
+ now: () => dayjs.Dayjs;
5
+ create: (date: Parameters<typeof dayjs>[0]) => dayjs.Dayjs;
6
+ };
7
+
8
+ export { sydneyDayjs };
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ import dayjs from 'dayjs';
2
+ import timezone from 'dayjs/plugin/timezone';
3
+ import utc from 'dayjs/plugin/utc';
4
+
5
+ // src/index.ts
6
+ var TIME_ZONE = "Australia/Sydney";
7
+ dayjs.extend(utc);
8
+ dayjs.extend(timezone);
9
+ dayjs.tz.setDefault(TIME_ZONE);
10
+ var sydneyDayjs = {
11
+ now: () => dayjs.tz(/* @__PURE__ */ new Date(), TIME_ZONE).tz(TIME_ZONE),
12
+ create: (date) => dayjs.tz(date, TIME_ZONE)
13
+ };
14
+
15
+ export { sydneyDayjs };
16
+ //# sourceMappingURL=index.js.map
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAIA,IAAM,SAAA,GAAY,kBAAA;AAElB,KAAA,CAAM,OAAO,GAAG,CAAA;AAChB,KAAA,CAAM,OAAO,QAAQ,CAAA;AACrB,KAAA,CAAM,EAAA,CAAG,WAAW,SAAS,CAAA;AAEtB,IAAM,WAAA,GAAc;AAAA,EACzB,GAAA,EAAK,MAAM,KAAA,CAAM,EAAA,iBAAG,IAAI,MAAK,EAAG,SAAS,CAAA,CAAE,EAAA,CAAG,SAAS,CAAA;AAAA,EACvD,QAAQ,CAAC,IAAA,KAAsC,KAAA,CAAM,EAAA,CAAG,MAAM,SAAS;AACzE","file":"index.js","sourcesContent":["import dayjs from 'dayjs';\nimport timezone from 'dayjs/plugin/timezone';\nimport utc from 'dayjs/plugin/utc';\n\nconst TIME_ZONE = 'Australia/Sydney';\n\ndayjs.extend(utc);\ndayjs.extend(timezone);\ndayjs.tz.setDefault(TIME_ZONE);\n\nexport const sydneyDayjs = {\n now: () => dayjs.tz(new Date(), TIME_ZONE).tz(TIME_ZONE),\n create: (date: Parameters<typeof dayjs>[0]) => dayjs.tz(date, TIME_ZONE),\n};\n"]}
@@ -0,0 +1,97 @@
1
+ import { fileURLToPath } from 'url';
2
+ import { dirname } from 'path';
3
+ import js from '@eslint/js';
4
+ import tseslint from 'typescript-eslint';
5
+ import unusedImports from 'eslint-plugin-unused-imports';
6
+ import prettier from 'eslint-config-prettier';
7
+ import prettierPlugin from 'eslint-plugin-prettier';
8
+ import { defineConfig } from 'eslint/config';
9
+
10
+ const __dirname = dirname(fileURLToPath(import.meta.url));
11
+
12
+ const config = defineConfig([
13
+ js.configs.recommended,
14
+ ...tseslint.configs.recommendedTypeChecked,
15
+ ...tseslint.configs.stylisticTypeChecked,
16
+ prettier,
17
+ {
18
+ ignores: [
19
+ 'node_modules',
20
+ '**/node_modules',
21
+ '**/.cache',
22
+ 'build',
23
+ 'dist',
24
+ '.yarn',
25
+ '.turbo',
26
+ '**/.turbo',
27
+ '.out',
28
+ ],
29
+ },
30
+ {
31
+ languageOptions: {
32
+ parser: tseslint.parser,
33
+ parserOptions: {
34
+ project: './tsconfig.json',
35
+ tsconfigRootDir: __dirname,
36
+ ecmaVersion: 'latest',
37
+ sourceType: 'module',
38
+ },
39
+ },
40
+ plugins: {
41
+ 'unused-imports': unusedImports,
42
+ prettier: prettierPlugin,
43
+ },
44
+ rules: {
45
+ 'unused-imports/no-unused-imports': 'warn',
46
+ 'prettier/prettier': 'error',
47
+ // Allow both type and interface (prefer type)
48
+ '@typescript-eslint/consistent-type-definitions': 'off',
49
+ // Allow both Array<T> and T[] syntax
50
+ '@typescript-eslint/array-type': 'off',
51
+ // Allow both index signatures and Record types
52
+ '@typescript-eslint/consistent-indexed-object-style': 'off',
53
+ // Allow unused variables
54
+ '@typescript-eslint/no-unused-vars': 'off',
55
+ // Allow template literal expressions with any type
56
+ '@typescript-eslint/restrict-template-expressions': 'off',
57
+ // Allow explicit any types
58
+ '@typescript-eslint/no-explicit-any': 'off',
59
+ // Allow unsafe member access on any types
60
+ '@typescript-eslint/no-unsafe-member-access': 'off',
61
+ // Allow unsafe argument types
62
+ '@typescript-eslint/no-unsafe-argument': 'off',
63
+ // Allow promise rejections with non-Error values
64
+ '@typescript-eslint/prefer-promise-reject-errors': 'off',
65
+ // Strict boolean expressions
66
+ '@typescript-eslint/strict-boolean-expressions': 'warn',
67
+ // Code quality
68
+ '@typescript-eslint/prefer-nullish-coalescing': 'warn',
69
+ '@typescript-eslint/prefer-optional-chain': 'warn',
70
+ 'prefer-const': 'error',
71
+ 'no-var': 'error',
72
+ },
73
+ },
74
+ {
75
+ files: ['*.js', '*.cjs'],
76
+ languageOptions: {
77
+ parserOptions: {
78
+ ecmaVersion: 'latest',
79
+ },
80
+ },
81
+ ...tseslint.configs.disableTypeChecked,
82
+ rules: {
83
+ '@typescript-eslint/no-var-requires': 'off',
84
+ },
85
+ },
86
+ {
87
+ files: ['*.config.ts', '*.config.mjs'],
88
+ languageOptions: {
89
+ parserOptions: {
90
+ project: null,
91
+ },
92
+ },
93
+ ...tseslint.configs.disableTypeChecked,
94
+ },
95
+ ]);
96
+
97
+ export default config;
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@kuroson/sydneydayjs",
3
+ "version": "0.1.0",
4
+ "description": "A pre-configured dayjs wrapper with Sydney (Australia/Sydney) timezone as the default",
5
+ "author": "Alvin Cherk <a.cherk@unsw.edu.au>",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "./src/index.ts",
9
+ "module": "./src/index.ts",
10
+ "types": "./src/index.ts",
11
+ "exports": {
12
+ ".": "./src/index.ts",
13
+ "./package.json": "./package.json"
14
+ },
15
+ "engines": {
16
+ "node": ">=22"
17
+ },
18
+ "scripts": {
19
+ "build": "tsup",
20
+ "build:all": "tsup",
21
+ "lint": "eslint './**/*.{ts,js}'",
22
+ "lint:fix": "eslint './**/*.{ts,js}' --fix",
23
+ "prepublishOnly": "pnpm run build",
24
+ "typecheck": "tsc --noEmit"
25
+ },
26
+ "dependencies": {
27
+ "dayjs": "^1.11.10"
28
+ },
29
+ "devDependencies": {
30
+ "@eslint/js": "catalog:",
31
+ "@types/jest": "catalog:",
32
+ "@types/node": "catalog:",
33
+ "@typescript-eslint/eslint-plugin": "catalog:",
34
+ "@typescript-eslint/parser": "catalog:",
35
+ "eslint": "catalog:",
36
+ "eslint-config-prettier": "catalog:",
37
+ "eslint-plugin-prettier": "catalog:",
38
+ "eslint-plugin-unused-imports": "catalog:",
39
+ "prettier": "catalog:",
40
+ "tslib": "catalog:",
41
+ "tsup": "catalog:",
42
+ "typescript": "catalog:",
43
+ "typescript-eslint": "catalog:"
44
+ },
45
+ "peerDependencies": {
46
+ "typescript": ">=4.7.0"
47
+ },
48
+ "peerDependenciesMeta": {
49
+ "typescript": {
50
+ "optional": true
51
+ }
52
+ },
53
+ "publishConfig": {
54
+ "access": "public",
55
+ "main": "./dist/index.cjs",
56
+ "module": "./dist/index.js",
57
+ "types": "./dist/index.d.ts",
58
+ "exports": {
59
+ ".": {
60
+ "import": {
61
+ "types": "./dist/index.d.ts",
62
+ "default": "./dist/index.js"
63
+ },
64
+ "require": {
65
+ "types": "./dist/index.d.cts",
66
+ "default": "./dist/index.cjs"
67
+ }
68
+ },
69
+ "./package.json": "./package.json"
70
+ }
71
+ }
72
+ }
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ import dayjs from 'dayjs';
2
+ import timezone from 'dayjs/plugin/timezone';
3
+ import utc from 'dayjs/plugin/utc';
4
+
5
+ const TIME_ZONE = 'Australia/Sydney';
6
+
7
+ dayjs.extend(utc);
8
+ dayjs.extend(timezone);
9
+ dayjs.tz.setDefault(TIME_ZONE);
10
+
11
+ export const sydneyDayjs = {
12
+ now: () => dayjs.tz(new Date(), TIME_ZONE).tz(TIME_ZONE),
13
+ create: (date: Parameters<typeof dayjs>[0]) => dayjs.tz(date, TIME_ZONE),
14
+ };
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.json",
4
+ "compilerOptions": {
5
+ "baseUrl": "./src",
6
+ "target": "ESNext",
7
+ "verbatimModuleSyntax": true,
8
+ "module": "ESNext",
9
+ "moduleResolution": "bundler",
10
+ "outDir": "./dist",
11
+ "rootDir": "./src",
12
+ "declarationDir": "./dist",
13
+ "noEmit": false,
14
+ "incremental": true,
15
+ "tsBuildInfoFile": "./tsconfig.build.tsbuildinfo"
16
+ },
17
+ "exclude": ["dist", "**/__tests__/*", "node_modules"]
18
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "../../../tsconfig.base.json",
4
+ "compilerOptions": {
5
+ "module": "ESNext",
6
+ "moduleResolution": "bundler",
7
+ "target": "ESNext",
8
+ "lib": ["ESNext"],
9
+ "esModuleInterop": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "baseUrl": "./src",
12
+ "outDir": "./dist",
13
+ "rootDir": "./src",
14
+ "noEmit": true,
15
+ "incremental": true,
16
+ "resolveJsonModule": true,
17
+ "strict": true,
18
+ "skipLibCheck": true,
19
+ "declaration": true,
20
+ "declarationMap": true
21
+ },
22
+ "exclude": ["**/node_modules", "**/.*/*", "dist", "tsup.config.ts"],
23
+ "include": ["src/**/*.ts"]
24
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig(() => ({
4
+ entry: ['src/index.ts'],
5
+ format: ['esm', 'cjs'],
6
+ splitting: false,
7
+ clean: true,
8
+ dts: true,
9
+ platform: 'node',
10
+ target: 'node22',
11
+ tsconfig: new URL('tsconfig.build.json', import.meta.url).pathname,
12
+ sourcemap: true,
13
+ minify: false,
14
+ treeshake: true,
15
+ outDir: 'dist',
16
+ }));