@aiursoft/utctime.js 1.0.15 → 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.
Files changed (3) hide show
  1. package/.gitlab-ci.yml +38 -6
  2. package/README.md +117 -3
  3. package/package.json +1 -1
package/.gitlab-ci.yml CHANGED
@@ -17,13 +17,14 @@ workflow:
17
17
  variables:
18
18
  S360_PURPOSE: review
19
19
  S360_CHECK_KEY: ''
20
+ npm_config_registry: 'https://nopkg.aiursoft.com/npm/'
20
21
 
21
22
  s360:
22
23
  stage: s360
23
24
  script:
24
25
  - export PATH="$PATH:$HOME/.dotnet/tools"
25
- - dotnet tool update Aiursoft.S360.Client --global --add-source https://nuget.aiursoft.com/v3/index.json
26
- - s360 check --path . --ecosystem npm --npm-lockfile-only --purpose "$S360_PURPOSE"
26
+ - dotnet tool update --global Aiursoft.S360.Client --source https://nupkg.aiursoft.com/v3/index.json
27
+ - s360 check --path . --ecosystem npm --npm-lockfile-only --npm-registry "$npm_config_registry" --purpose "$S360_PURPOSE"
27
28
  retry:
28
29
  max: 2
29
30
  when: runner_system_failure
@@ -39,27 +40,58 @@ check:
39
40
  paths:
40
41
  - '*.tgz'
41
42
 
42
- publish:
43
+ publish_local_npm:
43
44
  stage: publish
44
45
  needs:
45
46
  - job: check
46
47
  artifacts: true
47
- resource_group: npm-publish
48
+ resource_group: npm-publish-local
48
49
  script:
49
50
  - |
50
51
  set -- *.tgz
51
52
  test "$#" -eq 1
52
53
  test -f "$1"
54
+ : "${NOPKG_API_KEY:?npm publishing credential is required}"
53
55
  package_name=$(node -p 'encodeURIComponent(require("./package.json").name)')
54
56
  package_version=$(node -p 'require("./package.json").version')
55
57
  status=$(curl --silent --show-error --location --output /dev/null --write-out '%{http_code}' \
56
- "https://registry.npmjs.org/$package_name/$package_version")
58
+ "https://nopkg.aiursoft.com/npm/$package_name/$package_version")
57
59
  case "$status" in
58
60
  200) echo "Version $package_version is already published; skipping."; exit 0 ;;
59
- 404) ;;
61
+ # A new local package may be denied by mirror policy before publication.
62
+ 403|404) ;;
60
63
  *) echo "Cannot check published versions (HTTP $status)." >&2; exit 1 ;;
61
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"
62
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
63
95
  npm_config_userconfig=$(mktemp)
64
96
  export npm_config_userconfig
65
97
  trap 'rm -f "$npm_config_userconfig"' EXIT
package/README.md CHANGED
@@ -1,17 +1,50 @@
1
- # UtcTime.js
1
+ <a name="utctimejs"></a>
2
+
3
+ # Aiursoft UtcTime.js
2
4
 
3
5
  [![Pipeline](https://badge-proxy.aiursoft.com/aiursoft/utctime.js/badges/master/pipeline.svg)](https://gitlab.aiursoft.com/aiursoft/utctime.js/-/pipelines) [![npm](https://img.shields.io/npm/v/@aiursoft/utctime.js)](https://www.npmjs.com/package/@aiursoft/utctime.js)
4
6
 
5
7
  Convert UTC timestamps to local time in browser pages.
6
8
 
7
- ## Install
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).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiursoft/utctime.js",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "description": "Auto utc time",
5
5
  "main": "dist/cjs/utctime.js",
6
6
  "module": "dist/esm/utctime.js",