@aiursoft/utctime.js 1.0.16 → 1.0.17
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/.gitlab-ci.yml +35 -4
- package/README.md +117 -3
- package/package.json +1 -1
package/.gitlab-ci.yml
CHANGED
|
@@ -40,27 +40,58 @@ check:
|
|
|
40
40
|
paths:
|
|
41
41
|
- '*.tgz'
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
publish_local_npm:
|
|
44
44
|
stage: publish
|
|
45
45
|
needs:
|
|
46
46
|
- job: check
|
|
47
47
|
artifacts: true
|
|
48
|
-
resource_group: npm-publish
|
|
48
|
+
resource_group: npm-publish-local
|
|
49
49
|
script:
|
|
50
50
|
- |
|
|
51
51
|
set -- *.tgz
|
|
52
52
|
test "$#" -eq 1
|
|
53
53
|
test -f "$1"
|
|
54
|
+
: "${NOPKG_API_KEY:?npm publishing credential is required}"
|
|
54
55
|
package_name=$(node -p 'encodeURIComponent(require("./package.json").name)')
|
|
55
56
|
package_version=$(node -p 'require("./package.json").version')
|
|
56
57
|
status=$(curl --silent --show-error --location --output /dev/null --write-out '%{http_code}' \
|
|
57
|
-
"https://
|
|
58
|
+
"https://nopkg.aiursoft.com/npm/$package_name/$package_version")
|
|
58
59
|
case "$status" in
|
|
59
60
|
200) echo "Version $package_version is already published; skipping."; exit 0 ;;
|
|
60
|
-
|
|
61
|
+
# A new local package may be denied by mirror policy before publication.
|
|
62
|
+
403|404) ;;
|
|
61
63
|
*) echo "Cannot check published versions (HTTP $status)." >&2; exit 1 ;;
|
|
62
64
|
esac
|
|
65
|
+
npm_config_userconfig=$(mktemp)
|
|
66
|
+
export npm_config_userconfig
|
|
67
|
+
trap 'rm -f "$npm_config_userconfig"' EXIT
|
|
68
|
+
printf '%s\n' '//nopkg.aiursoft.com/npm/:_authToken=${NOPKG_API_KEY}' > "$npm_config_userconfig"
|
|
69
|
+
npm publish "$1" --registry=https://nopkg.aiursoft.com/npm/ --access public --ignore-scripts
|
|
70
|
+
rules:
|
|
71
|
+
- if: '$CI_COMMIT_BRANCH == "master"'
|
|
72
|
+
|
|
73
|
+
publish_public_npm:
|
|
74
|
+
stage: publish
|
|
75
|
+
needs:
|
|
76
|
+
- job: check
|
|
77
|
+
artifacts: true
|
|
78
|
+
resource_group: npm-publish-public
|
|
79
|
+
script:
|
|
80
|
+
- |
|
|
81
|
+
set -- *.tgz
|
|
82
|
+
test "$#" -eq 1
|
|
83
|
+
test -f "$1"
|
|
63
84
|
: "${NPM_TOKEN:?npm publishing credential is required}"
|
|
85
|
+
package_name=$(node -p 'encodeURIComponent(require("./package.json").name)')
|
|
86
|
+
package_version=$(node -p 'require("./package.json").version')
|
|
87
|
+
status=$(curl --silent --show-error --location --output /dev/null --write-out '%{http_code}' \
|
|
88
|
+
"https://registry.npmjs.org/$package_name/$package_version")
|
|
89
|
+
case "$status" in
|
|
90
|
+
200) echo "Version $package_version is already published; skipping."; exit 0 ;;
|
|
91
|
+
# A new local package may be denied by mirror policy before publication.
|
|
92
|
+
403|404) ;;
|
|
93
|
+
*) echo "Cannot check published versions (HTTP $status)." >&2; exit 1 ;;
|
|
94
|
+
esac
|
|
64
95
|
npm_config_userconfig=$(mktemp)
|
|
65
96
|
export npm_config_userconfig
|
|
66
97
|
trap 'rm -f "$npm_config_userconfig"' EXIT
|
package/README.md
CHANGED
|
@@ -1,17 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
<a name="utctimejs"></a>
|
|
2
|
+
|
|
3
|
+
# Aiursoft UtcTime.js
|
|
2
4
|
|
|
3
5
|
[](https://gitlab.aiursoft.com/aiursoft/utctime.js/-/pipelines) [](https://www.npmjs.com/package/@aiursoft/utctime.js)
|
|
4
6
|
|
|
5
7
|
Convert UTC timestamps to local time in browser pages.
|
|
6
8
|
|
|
7
|
-
##
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
### What is UtcTime.js?
|
|
12
|
+
|
|
13
|
+
Convert UTC timestamps to local time in browser pages.
|
|
14
|
+
|
|
15
|
+
<a name="install"></a>
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Install the package in your project:
|
|
8
20
|
|
|
9
21
|
```bash
|
|
10
22
|
npm install @aiursoft/utctime.js
|
|
11
23
|
```
|
|
12
24
|
|
|
25
|
+
Requires a browser with ES modules and the DOM. Node.js is needed to install or build the package, not to run the deployed browser assets.
|
|
26
|
+
|
|
13
27
|
## Usage
|
|
14
28
|
|
|
29
|
+
Save the following as `index.html` beside `node_modules/` and serve that directory over HTTP with your existing static-file server:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<!doctype html>
|
|
33
|
+
<html lang="en">
|
|
34
|
+
<meta charset="utf-8" />
|
|
35
|
+
<title>UtcTime example</title>
|
|
36
|
+
<body>
|
|
37
|
+
<p data-utc-time="2018-09-12T10:12:24Z"></p>
|
|
38
|
+
<script type="module">
|
|
39
|
+
import UtcTime from './node_modules/@aiursoft/utctime.js/dist/esm/utctime.js'
|
|
40
|
+
new UtcTime({})
|
|
41
|
+
</script>
|
|
42
|
+
</body>
|
|
43
|
+
</html>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The timestamp is read as UTC and displayed according to the browser locale.
|
|
47
|
+
|
|
15
48
|
```js
|
|
16
49
|
import UtcTime from './node_modules/@aiursoft/utctime.js/dist/esm/utctime.js'
|
|
17
50
|
new UtcTime({})
|
|
@@ -19,12 +52,93 @@ new UtcTime({})
|
|
|
19
52
|
|
|
20
53
|
See [usage and options](docs/usage.md) for timestamp attributes and formatting.
|
|
21
54
|
|
|
55
|
+
### Timestamp attributes
|
|
56
|
+
|
|
57
|
+
Use `data-utc-time` by default, or select another attribute through `attr`. An ISO UTC value ending in `Z` makes the timezone explicit. Values without a UTC suffix are first tried as UTC; unparseable inputs fall back to normal browser date parsing with a warning. Invalid dates are not validated by a separate error callback.
|
|
58
|
+
|
|
59
|
+
### Tooltip integration
|
|
60
|
+
|
|
61
|
+
Use `onSet` to initialize a tooltip. It runs once for each matching element during construction; periodic text refreshes do not repeat that callback. Bootstrap and its tooltip JavaScript must be supplied by the application.
|
|
62
|
+
|
|
63
|
+
For Bootstrap 4 with jQuery:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
new UtcTime({
|
|
67
|
+
onSet: function (element, date) {
|
|
68
|
+
element.setAttribute('data-toggle', 'tooltip')
|
|
69
|
+
element.setAttribute('data-trigger', 'hover')
|
|
70
|
+
element.setAttribute('data-title', date.toLocaleString())
|
|
71
|
+
$(element).tooltip()
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
For Bootstrap 5:
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
new UtcTime({
|
|
80
|
+
onSet: function (element, date) {
|
|
81
|
+
new bootstrap.Tooltip(element, {
|
|
82
|
+
trigger: 'hover',
|
|
83
|
+
placement: 'top',
|
|
84
|
+
title: date.toLocaleString(),
|
|
85
|
+
})
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Configuration
|
|
91
|
+
|
|
92
|
+
Pass a partial settings object to the constructor. These are the complete defaults:
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
new UtcTime({
|
|
96
|
+
attr: 'data-utc-time',
|
|
97
|
+
daysAgo: ' days ago',
|
|
98
|
+
hoursAgo: ' hours ago',
|
|
99
|
+
minutesAgo: ' minutes ago',
|
|
100
|
+
secondsAgo: ' seconds ago',
|
|
101
|
+
disableAgo: false,
|
|
102
|
+
onSet: function (element, date) {},
|
|
103
|
+
disableAutoUpdate: false,
|
|
104
|
+
format: undefined,
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Formatting and priority**
|
|
109
|
+
|
|
110
|
+
A nonempty `format` has highest priority and supports `YYYY`, `MM`, `DD`, `HH`, `mm` and `ss`. These tokens currently use UTC fields, for example `YYYY-MM-DD HH:mm:ss`; they do not use local timezone fields. Without `format`, `disableAgo: true` uses `date.toLocaleString()`. Otherwise the library shows relative seconds, minutes, hours or days; future timestamps and timestamps at least 30 days old use a full localized date. Override the four suffixes for localization, for example `daysAgo: '天前'`.
|
|
111
|
+
|
|
112
|
+
**Updates and lifecycle**
|
|
113
|
+
|
|
114
|
+
By default the instance rescans matching DOM elements every second. `disableAutoUpdate: true` performs the initial update without scheduling that loop; later refreshes can call `instance.initTime(instance.defaultSettings)`. There is no dispose method for an already-started timer, so avoid creating repeated instances on a long-lived page. Configuration is passed in code, with no configuration file or environment variables.
|
|
115
|
+
|
|
22
116
|
## Development
|
|
23
117
|
|
|
24
|
-
Use Node.js 20 or a newer supported LTS release.
|
|
118
|
+
Use Node.js 20 or a newer supported LTS release. The current build is verified with Node.js 24.
|
|
119
|
+
|
|
120
|
+
From the repository root, install the locked dependencies, run the existing checks and create a package:
|
|
25
121
|
|
|
26
122
|
```bash
|
|
27
123
|
npm ci
|
|
28
124
|
npm run check
|
|
29
125
|
npm pack
|
|
30
126
|
```
|
|
127
|
+
|
|
128
|
+
The existing checks run ESLint, Prettier and the production build. `npm pack` creates a local archive; it does not publish a release.
|
|
129
|
+
|
|
130
|
+
## Documentation
|
|
131
|
+
|
|
132
|
+
See [usage and options](docs/usage.md) for timestamp attributes and formatting.
|
|
133
|
+
|
|
134
|
+
## How to contribute
|
|
135
|
+
|
|
136
|
+
There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.
|
|
137
|
+
|
|
138
|
+
Even if you have push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.
|
|
139
|
+
|
|
140
|
+
We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
Licensed under the [MIT License](LICENSE).
|