@aiursoft/utctime.js 1.0.6 → 1.0.8
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/.editorconfig +11 -0
- package/.gitlab-ci.yml +40 -26
- package/.prettierignore +1 -0
- package/LICENSE +21 -0
- package/README.md +14 -114
- package/dist/cjs/utctime.js +123 -0
- package/dist/cjs/utctime.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/docs/usage.md +128 -0
- package/ninja.yaml +22 -0
- package/package.json +11 -10
package/.editorconfig
ADDED
package/.gitlab-ci.yml
CHANGED
|
@@ -2,35 +2,49 @@ stages:
|
|
|
2
2
|
- check
|
|
3
3
|
- publish
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- 'echo "Available Disk Space: $(df -h --output=avail / | tail -1)"'
|
|
12
|
-
- 'echo "IP Address: $(hostname -I)"'
|
|
13
|
-
- 'npm --version'
|
|
14
|
-
- 'node --version'
|
|
5
|
+
workflow:
|
|
6
|
+
rules:
|
|
7
|
+
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
8
|
+
- if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS'
|
|
9
|
+
when: never
|
|
10
|
+
- if: '$CI_COMMIT_BRANCH'
|
|
15
11
|
|
|
16
|
-
|
|
12
|
+
check:
|
|
17
13
|
stage: check
|
|
18
14
|
script:
|
|
19
|
-
- npm
|
|
20
|
-
- npm run
|
|
21
|
-
- npm
|
|
15
|
+
- npm ci
|
|
16
|
+
- npm run check
|
|
17
|
+
- npm pack
|
|
18
|
+
artifacts:
|
|
19
|
+
expire_in: 1 week
|
|
20
|
+
paths:
|
|
21
|
+
- '*.tgz'
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
needs:
|
|
25
|
-
- build_locally
|
|
23
|
+
publish:
|
|
26
24
|
stage: publish
|
|
27
|
-
|
|
25
|
+
needs:
|
|
26
|
+
- job: check
|
|
27
|
+
artifacts: true
|
|
28
|
+
resource_group: npm-publish
|
|
28
29
|
script:
|
|
29
|
-
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
- |
|
|
31
|
+
set -- *.tgz
|
|
32
|
+
test "$#" -eq 1
|
|
33
|
+
test -f "$1"
|
|
34
|
+
package_name=$(node -p 'encodeURIComponent(require("./package.json").name)')
|
|
35
|
+
package_version=$(node -p 'require("./package.json").version')
|
|
36
|
+
status=$(curl --silent --show-error --location --output /dev/null --write-out '%{http_code}' \
|
|
37
|
+
"https://registry.npmjs.org/$package_name/$package_version")
|
|
38
|
+
case "$status" in
|
|
39
|
+
200) echo "Version $package_version is already published; skipping."; exit 0 ;;
|
|
40
|
+
404) ;;
|
|
41
|
+
*) echo "Cannot check published versions (HTTP $status)." >&2; exit 1 ;;
|
|
42
|
+
esac
|
|
43
|
+
: "${NPM_TOKEN:?npm publishing credential is required}"
|
|
44
|
+
npm_config_userconfig=$(mktemp)
|
|
45
|
+
export npm_config_userconfig
|
|
46
|
+
trap 'rm -f "$npm_config_userconfig"' EXIT
|
|
47
|
+
printf '%s\n' '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > "$npm_config_userconfig"
|
|
48
|
+
npm publish "$1" --registry=https://registry.npmjs.org --access public --ignore-scripts
|
|
49
|
+
rules:
|
|
50
|
+
- if: '$CI_COMMIT_BRANCH == "master"'
|
package/.prettierignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
package-lock.json
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Anduin Xue
|
|
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
CHANGED
|
@@ -1,128 +1,28 @@
|
|
|
1
1
|
# UtcTime.js
|
|
2
2
|
|
|
3
|
-
[](https://gitlab.aiursoft.com/aiursoft/utctime.js/-/pipelines) [](https://www.npmjs.com/package/@aiursoft/utctime.js)
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Convert UTC timestamps to local time in browser pages.
|
|
6
6
|
|
|
7
|
-
##
|
|
8
|
-
|
|
9
|
-
Run the following command to install the most recent version of `@aiursoft/utctime.js` from npm:
|
|
10
|
-
|
|
11
|
-
```sh
|
|
12
|
-
npm install @aiursoft/utctime.js
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Importing
|
|
16
|
-
|
|
17
|
-
## Reference JavaScript
|
|
18
|
-
|
|
19
|
-
You can import the library using the following code:
|
|
20
|
-
|
|
21
|
-
```html
|
|
22
|
-
<script type="module">
|
|
23
|
-
import UtcTime from './node_modules/@aiursoft/utctime.js/dist/esm/utctime.js'
|
|
24
|
-
new UtcTime({})
|
|
25
|
-
</script>
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## How to build locally
|
|
7
|
+
## Install
|
|
29
8
|
|
|
30
9
|
```bash
|
|
31
|
-
npm install
|
|
32
|
-
npm run build
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## How to use
|
|
36
|
-
|
|
37
|
-
Create an element.
|
|
38
|
-
|
|
39
|
-
```html
|
|
40
|
-
<p></p>
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
And change it like this.
|
|
44
|
-
|
|
45
|
-
```html
|
|
46
|
-
<p data-utc-time="9/12/2018 10:12:24 AM"><!-- In your tag the time shall be an UTC time --></p>
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Add init the library.
|
|
50
|
-
|
|
51
|
-
```html
|
|
52
|
-
<script>
|
|
53
|
-
new UtcTime({})
|
|
54
|
-
</script>
|
|
10
|
+
npm install @aiursoft/utctime.js
|
|
55
11
|
```
|
|
56
12
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
## API
|
|
60
|
-
|
|
61
|
-
```javascript
|
|
62
|
-
// Init with loop
|
|
63
|
-
new UtcTime({
|
|
64
|
-
// We will try to select elements using the attr value. Default value is 'data-utc-time'.
|
|
65
|
-
attr: 'data-utc-time',
|
|
66
|
-
|
|
67
|
-
// Localization options. Default is ' days ago'
|
|
68
|
-
daysAgo: '天前',
|
|
69
|
-
|
|
70
|
-
// Localization options. Default is ' hours ago'
|
|
71
|
-
hoursAgo: '小时前',
|
|
72
|
-
|
|
73
|
-
// Localization options. Default is ' mintes ago'
|
|
74
|
-
minutesAgo: '分钟前',
|
|
75
|
-
|
|
76
|
-
// Localization options. Default is ' seconds ago'
|
|
77
|
-
secondsAgo: '秒前',
|
|
78
|
-
|
|
79
|
-
// Always display full local time and date (using toLocaleString()), not `some time` ago.
|
|
80
|
-
disableAgo: false,
|
|
13
|
+
## Usage
|
|
81
14
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
format: undefined,
|
|
86
|
-
|
|
87
|
-
// After the content is replaced.
|
|
88
|
-
onSet: function (element, date) {},
|
|
89
|
-
|
|
90
|
-
// Disable auto update the value by seconds.
|
|
91
|
-
disableAutoUpdate: false,
|
|
92
|
-
})
|
|
15
|
+
```js
|
|
16
|
+
import UtcTime from './node_modules/@aiursoft/utctime.js/dist/esm/utctime.js'
|
|
17
|
+
new UtcTime({})
|
|
93
18
|
```
|
|
94
19
|
|
|
95
|
-
|
|
20
|
+
See [usage and options](docs/usage.md) for timestamp attributes and formatting.
|
|
96
21
|
|
|
97
|
-
|
|
98
|
-
new UtcTime({
|
|
99
|
-
onSet: function (element, date) {
|
|
100
|
-
element.setAttribute('data-toggle', 'tooltip')
|
|
101
|
-
element.setAttribute('data-trigger', 'hover')
|
|
102
|
-
element.setAttribute('data-title', date.toLocaleString())
|
|
103
|
-
$(element).tooltip()
|
|
104
|
-
},
|
|
105
|
-
})
|
|
106
|
-
```
|
|
22
|
+
## Development
|
|
107
23
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
onSet: function (element, date) {
|
|
113
|
-
new bootstrap.Tooltip(element, {
|
|
114
|
-
trigger: 'hover',
|
|
115
|
-
placement: 'top',
|
|
116
|
-
title: date.toLocaleString(),
|
|
117
|
-
})
|
|
118
|
-
},
|
|
119
|
-
})
|
|
24
|
+
```bash
|
|
25
|
+
npm ci
|
|
26
|
+
npm run check
|
|
27
|
+
npm pack
|
|
120
28
|
```
|
|
121
|
-
|
|
122
|
-
## How to contribute
|
|
123
|
-
|
|
124
|
-
There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.
|
|
125
|
-
|
|
126
|
-
Even if you with 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.
|
|
127
|
-
|
|
128
|
-
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.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class UtcTime {
|
|
4
|
+
defaultSettings = {
|
|
5
|
+
attr: 'data-utc-time',
|
|
6
|
+
daysAgo: ' days ago',
|
|
7
|
+
hoursAgo: ' hours ago',
|
|
8
|
+
minutesAgo: ' minutes ago',
|
|
9
|
+
secondsAgo: ' seconds ago',
|
|
10
|
+
disableAgo: false,
|
|
11
|
+
onSet: function (obj) { },
|
|
12
|
+
disableAutoUpdate: false,
|
|
13
|
+
format: undefined,
|
|
14
|
+
};
|
|
15
|
+
constructor(settings) {
|
|
16
|
+
Object.assign(this.defaultSettings, settings);
|
|
17
|
+
const loop = () => {
|
|
18
|
+
this.initTime(this.defaultSettings);
|
|
19
|
+
if (!this.defaultSettings.disableAutoUpdate) {
|
|
20
|
+
setTimeout(loop, 1000);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
loop();
|
|
24
|
+
document
|
|
25
|
+
.querySelectorAll('*[' + this.defaultSettings.attr + ']')
|
|
26
|
+
.forEach((timeField) => {
|
|
27
|
+
const sourceValue = timeField.getAttribute(this.defaultSettings.attr);
|
|
28
|
+
if (sourceValue) {
|
|
29
|
+
const date = this.getDate(sourceValue);
|
|
30
|
+
this.defaultSettings.onSet(timeField, date);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
formatDate(date, format) {
|
|
35
|
+
const pad = (n) => (n < 10 ? '0' + n : n.toString());
|
|
36
|
+
const replacements = {
|
|
37
|
+
YYYY: date.getUTCFullYear().toString(),
|
|
38
|
+
MM: pad(date.getUTCMonth() + 1),
|
|
39
|
+
DD: pad(date.getUTCDate()),
|
|
40
|
+
HH: pad(date.getUTCHours()),
|
|
41
|
+
mm: pad(date.getUTCMinutes()),
|
|
42
|
+
ss: pad(date.getUTCSeconds()),
|
|
43
|
+
};
|
|
44
|
+
return format.replace(/YYYY|MM|DD|HH|mm|ss/g, (match) => replacements[match]);
|
|
45
|
+
}
|
|
46
|
+
timeSince(date, settings) {
|
|
47
|
+
const seconds = Math.floor((new Date().getTime() - date.getTime()) / 1000);
|
|
48
|
+
let interval = Math.floor(seconds / 2592000); // 30 days
|
|
49
|
+
if (interval >= 1) {
|
|
50
|
+
return settings.format
|
|
51
|
+
? this.formatDate(date, settings.format)
|
|
52
|
+
: date.toLocaleString();
|
|
53
|
+
}
|
|
54
|
+
interval = Math.floor(seconds / 86400);
|
|
55
|
+
if (interval >= 1) {
|
|
56
|
+
return interval + settings.daysAgo;
|
|
57
|
+
}
|
|
58
|
+
interval = Math.floor(seconds / 3600);
|
|
59
|
+
if (interval >= 1) {
|
|
60
|
+
return interval + settings.hoursAgo;
|
|
61
|
+
}
|
|
62
|
+
interval = Math.floor(seconds / 60);
|
|
63
|
+
if (interval >= 1) {
|
|
64
|
+
return interval + settings.minutesAgo;
|
|
65
|
+
}
|
|
66
|
+
if (seconds >= 0) {
|
|
67
|
+
return Math.floor(seconds) + settings.secondsAgo;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return settings.format
|
|
71
|
+
? this.formatDate(date, settings.format)
|
|
72
|
+
: date.toLocaleString();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
getDate(inputString) {
|
|
76
|
+
if (inputString.endsWith(' UTC') || inputString.endsWith('Z')) {
|
|
77
|
+
return new Date(inputString);
|
|
78
|
+
}
|
|
79
|
+
if (!inputString.endsWith(' UTC')) {
|
|
80
|
+
const timeValue = inputString + ' UTC';
|
|
81
|
+
const date = new Date(timeValue);
|
|
82
|
+
if (!isNaN(date.getTime())) {
|
|
83
|
+
return date;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!inputString.endsWith('Z')) {
|
|
87
|
+
const timeValue = inputString + 'Z';
|
|
88
|
+
const date = new Date(timeValue);
|
|
89
|
+
if (!isNaN(date.getTime())) {
|
|
90
|
+
return date;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
console.warn(`jquery-utc-time: Input string ${inputString} can not be converted to UTC time and try to parse as typical date string.`);
|
|
94
|
+
return new Date(inputString);
|
|
95
|
+
}
|
|
96
|
+
initTime(settings) {
|
|
97
|
+
document
|
|
98
|
+
.querySelectorAll('*[' + settings.attr + ']')
|
|
99
|
+
.forEach((timeField) => {
|
|
100
|
+
const sourceValue = timeField.getAttribute(settings.attr);
|
|
101
|
+
if (!sourceValue)
|
|
102
|
+
return;
|
|
103
|
+
const date = this.getDate(sourceValue);
|
|
104
|
+
let text;
|
|
105
|
+
// 修改:核心逻辑更新
|
|
106
|
+
if (settings.format) {
|
|
107
|
+
// 1. 如果提供了 format,则拥有最高优先级
|
|
108
|
+
text = this.formatDate(date, settings.format);
|
|
109
|
+
}
|
|
110
|
+
else if (settings.disableAgo) {
|
|
111
|
+
// 2. 如果禁用了相对时间,则使用本地化日期
|
|
112
|
+
text = date.toLocaleString();
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
// 3. 否则,计算相对时间
|
|
116
|
+
text = this.timeSince(date, settings);
|
|
117
|
+
}
|
|
118
|
+
timeField.innerHTML = text;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
exports.default = UtcTime;
|
|
123
|
+
//# sourceMappingURL=utctime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utctime.js","sourceRoot":"","sources":["../../src/utctime.ts"],"names":[],"mappings":";;AAaA,MAAM,OAAO;IACX,eAAe,GAAoB;QACjC,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,WAAW;QACpB,QAAQ,EAAE,YAAY;QACtB,UAAU,EAAE,cAAc;QAC1B,UAAU,EAAE,cAAc;QAC1B,UAA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@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../src/utctime.ts"],"version":"5.9.
|
|
1
|
+
{"root":["../../src/utctime.ts"],"version":"5.9.3"}
|
package/docs/usage.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# UtcTime.js
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/license/mit) [](https://gitlab.aiursoft.com/aiursoft/utctime.js/-/pipelines) [](https://manhours.aiursoft.com/r/github.com/aiursoftweb/utctime.js.html) [](https://www.npmjs.com/package/@aiursoft/utctime.js) [](https://www.npmjs.com/package/@aiursoft/utctime.js)
|
|
4
|
+
|
|
5
|
+
`@aiursoft/utctime.js` is a JavaScript library which converts UTC time to local time easily.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Run the following command to install the most recent version of `@aiursoft/utctime.js` from npm:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @aiursoft/utctime.js
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Importing
|
|
16
|
+
|
|
17
|
+
## Reference JavaScript
|
|
18
|
+
|
|
19
|
+
You can import the library using the following code:
|
|
20
|
+
|
|
21
|
+
```html
|
|
22
|
+
<script type="module">
|
|
23
|
+
import UtcTime from './node_modules/@aiursoft/utctime.js/dist/esm/utctime.js'
|
|
24
|
+
new UtcTime({})
|
|
25
|
+
</script>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## How to build locally
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install
|
|
32
|
+
npm run build
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## How to use
|
|
36
|
+
|
|
37
|
+
Create an element.
|
|
38
|
+
|
|
39
|
+
```html
|
|
40
|
+
<p></p>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
And change it like this.
|
|
44
|
+
|
|
45
|
+
```html
|
|
46
|
+
<p data-utc-time="9/12/2018 10:12:24 AM"><!-- In your tag the time shall be an UTC time --></p>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Add init the library.
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<script>
|
|
53
|
+
new UtcTime({})
|
|
54
|
+
</script>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
And open it now! The time will be converted to local time.
|
|
58
|
+
|
|
59
|
+
## API
|
|
60
|
+
|
|
61
|
+
```javascript
|
|
62
|
+
// Init with loop
|
|
63
|
+
new UtcTime({
|
|
64
|
+
// We will try to select elements using the attr value. Default value is 'data-utc-time'.
|
|
65
|
+
attr: 'data-utc-time',
|
|
66
|
+
|
|
67
|
+
// Localization options. Default is ' days ago'
|
|
68
|
+
daysAgo: '天前',
|
|
69
|
+
|
|
70
|
+
// Localization options. Default is ' hours ago'
|
|
71
|
+
hoursAgo: '小时前',
|
|
72
|
+
|
|
73
|
+
// Localization options. Default is ' mintes ago'
|
|
74
|
+
minutesAgo: '分钟前',
|
|
75
|
+
|
|
76
|
+
// Localization options. Default is ' seconds ago'
|
|
77
|
+
secondsAgo: '秒前',
|
|
78
|
+
|
|
79
|
+
// Always display full local time and date (using toLocaleString()), not `some time` ago.
|
|
80
|
+
disableAgo: false,
|
|
81
|
+
|
|
82
|
+
// Provide a custom format string to display the date and time.
|
|
83
|
+
// This takes the highest priority over `disableAgo` and the relative time logic.
|
|
84
|
+
// Example: 'YYYY-MM-DD HH:mm:ss'.
|
|
85
|
+
format: undefined,
|
|
86
|
+
|
|
87
|
+
// After the content is replaced.
|
|
88
|
+
onSet: function (element, date) {},
|
|
89
|
+
|
|
90
|
+
// Disable auto update the value by seconds.
|
|
91
|
+
disableAutoUpdate: false,
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
For example, to init bootstrap v4 tooltip:
|
|
96
|
+
|
|
97
|
+
```javascript
|
|
98
|
+
new UtcTime({
|
|
99
|
+
onSet: function (element, date) {
|
|
100
|
+
element.setAttribute('data-toggle', 'tooltip')
|
|
101
|
+
element.setAttribute('data-trigger', 'hover')
|
|
102
|
+
element.setAttribute('data-title', date.toLocaleString())
|
|
103
|
+
$(element).tooltip()
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
To init bootstrap v5 tooltip:
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
new UtcTime({
|
|
112
|
+
onSet: function (element, date) {
|
|
113
|
+
new bootstrap.Tooltip(element, {
|
|
114
|
+
trigger: 'hover',
|
|
115
|
+
placement: 'top',
|
|
116
|
+
title: date.toLocaleString(),
|
|
117
|
+
})
|
|
118
|
+
},
|
|
119
|
+
})
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## How to contribute
|
|
123
|
+
|
|
124
|
+
There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.
|
|
125
|
+
|
|
126
|
+
Even if you with 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.
|
|
127
|
+
|
|
128
|
+
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.
|
package/ninja.yaml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
configVersion: 1
|
|
2
|
+
npm:
|
|
3
|
+
updateDependencies: true
|
|
4
|
+
http:
|
|
5
|
+
profiles:
|
|
6
|
+
company-source:
|
|
7
|
+
origin: https://gitlab.aiursoft.com
|
|
8
|
+
headersFromEnv:
|
|
9
|
+
PRIVATE-TOKEN: NINJA_SOURCE_TOKEN
|
|
10
|
+
files:
|
|
11
|
+
- name: .gitlab-ci.yml
|
|
12
|
+
contentUri: https://gitlab.aiursoft.com/api/v4/projects/aiursoft%2FUIStack.js/repository/files/.gitlab-ci.yml/raw?ref=master
|
|
13
|
+
- name: .editorconfig
|
|
14
|
+
contentUri: https://gitlab.aiursoft.com/api/v4/projects/aiursoft%2FUIStack.js/repository/files/.editorconfig/raw?ref=master
|
|
15
|
+
- name: .gitignore
|
|
16
|
+
contentUri: https://gitlab.aiursoft.com/api/v4/projects/aiursoft%2FUIStack.js/repository/files/.gitignore/raw?ref=master
|
|
17
|
+
- name: .npmrc
|
|
18
|
+
contentUri: https://gitlab.aiursoft.com/api/v4/projects/aiursoft%2FUIStack.js/repository/files/.npmrc/raw?ref=master
|
|
19
|
+
- name: ninja.yaml
|
|
20
|
+
contentUri: https://gitlab.aiursoft.com/api/v4/projects/aiursoft%2FUIStack.js/repository/files/ninja.yaml/raw?ref=master
|
|
21
|
+
- name: .prettierignore
|
|
22
|
+
contentUri: https://gitlab.aiursoft.com/api/v4/projects/aiursoft%2FUIStack.js/repository/files/.prettierignore/raw?ref=master
|
package/package.json
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiursoft/utctime.js",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Auto utc time",
|
|
5
5
|
"main": "dist/cjs/utctime.js",
|
|
6
6
|
"module": "dist/esm/utctime.js",
|
|
7
7
|
"types": "dist/types/utctime.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"clean": "rm -rf ./dist",
|
|
10
|
-
"build-js": "tsc -b ./tsconfig.json ./tsconfig.types.json",
|
|
10
|
+
"build-js": "tsc -b ./tsconfig.json ./tsconfig.types.json && tsc -p ./tsconfig.json --module commonjs --outDir ./dist/cjs",
|
|
11
11
|
"build": "npm run build-js",
|
|
12
12
|
"format": "prettier --write .",
|
|
13
13
|
"lint": "eslint src/ --ext .ts && prettier --check .",
|
|
14
|
-
"lint-fix": "eslint src/ --ext .ts --fix && prettier --write ."
|
|
14
|
+
"lint-fix": "eslint src/ --ext .ts --fix && prettier --write .",
|
|
15
|
+
"check": "npm run lint && npm run build"
|
|
15
16
|
},
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
|
18
|
-
"url": "https://
|
|
19
|
+
"url": "https://github.com/AiursoftWeb/utctime.js"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
21
|
-
"esbuild": "^0.19.
|
|
22
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
23
|
-
"@typescript-eslint/parser": "^6.
|
|
24
|
-
"eslint": "^8.
|
|
25
|
-
"prettier": "^3.
|
|
26
|
-
"typescript": "^5.
|
|
22
|
+
"esbuild": "^0.19.12",
|
|
23
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
24
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
25
|
+
"eslint": "^8.57.1",
|
|
26
|
+
"prettier": "^3.9.10",
|
|
27
|
+
"typescript": "^5.9.3"
|
|
27
28
|
},
|
|
28
29
|
"author": "Anduin Xue <anduin@aiursoft.com>",
|
|
29
30
|
"license": "MIT"
|