@cocreate/utils 1.24.2 → 1.25.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/.github/workflows/automated.yml +0 -26
- package/CHANGELOG.md +13 -0
- package/CoCreate.config.js +24 -24
- package/docs/index.html +0 -1
- package/package.json +1 -1
- package/src/index.js +39 -3
|
@@ -41,30 +41,4 @@ jobs:
|
|
|
41
41
|
outputs:
|
|
42
42
|
new_release_published: "${{ steps.semantic.outputs.new_release_published }}"
|
|
43
43
|
new_release_version: "${{ steps.semantic.outputs.new_release_version }}"
|
|
44
|
-
upload:
|
|
45
|
-
runs-on: ubuntu-latest
|
|
46
|
-
needs: release
|
|
47
|
-
if: needs.release.outputs.new_release_published == 'true'
|
|
48
|
-
env:
|
|
49
|
-
VERSION: "${{ needs.release.outputs.new_release_version }}"
|
|
50
|
-
steps:
|
|
51
|
-
- name: Checkout
|
|
52
|
-
uses: actions/checkout@v3
|
|
53
|
-
- name: Setup Node.js
|
|
54
|
-
uses: actions/setup-node@v3
|
|
55
|
-
with:
|
|
56
|
-
node-version: 16
|
|
57
|
-
- name: Set npm registry auth
|
|
58
|
-
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
|
|
59
|
-
- name: Install dependencies
|
|
60
|
-
run: yarn install
|
|
61
|
-
- name: Build
|
|
62
|
-
run: yarn build
|
|
63
|
-
- name: Set Environment Variables
|
|
64
|
-
run: |
|
|
65
|
-
echo "organization_id=${{ secrets.COCREATE_ORGANIZATION_ID }}" >> $GITHUB_ENV
|
|
66
|
-
echo "key=${{ secrets.COCREATE_KEY }}" >> $GITHUB_ENV
|
|
67
|
-
echo "host=${{ secrets.COCREATE_HOST }}" >> $GITHUB_ENV
|
|
68
|
-
- name: CoCreate Upload
|
|
69
|
-
run: coc upload
|
|
70
44
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# [1.25.0](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.24.2...v1.25.0) (2023-10-09)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* improved validating dates from strings ([a0d6fa1](https://github.com/CoCreate-app/CoCreate-utils/commit/a0d6fa198ee0d5642bc1a51d356216f840aa7aae))
|
|
7
|
+
* ObjectId() retuns an _id string, ObjectId(some_id) will validate and thorw an error if not valid ([cb50091](https://github.com/CoCreate-app/CoCreate-utils/commit/cb500913969cfcfd2b71c7d730b8358601ebcc2b))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* isValidDate() - validates the string and returns a date object or the original value ([780574b](https://github.com/CoCreate-app/CoCreate-utils/commit/780574be515926896d3c621a0745a1f750cd7487))
|
|
13
|
+
|
|
1
14
|
## [1.24.2](https://github.com/CoCreate-app/CoCreate-utils/compare/v1.24.1...v1.24.2) (2023-09-18)
|
|
2
15
|
|
|
3
16
|
|
package/CoCreate.config.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
"organization_id": "",
|
|
3
|
-
"key": "",
|
|
4
|
-
"host": "",
|
|
5
|
-
"sources": [
|
|
6
|
-
{
|
|
7
|
-
"array": "files",
|
|
8
|
-
"object": {
|
|
9
|
-
"_id": "6143fc94829b690010a5f339",
|
|
10
|
-
"name": "index.html",
|
|
11
|
-
"path": "/docs/utils",
|
|
12
|
-
"pathname": "/docs/utils/index.html",
|
|
13
|
-
"src": "{{./docs/index.html}}",
|
|
14
|
-
"host": [
|
|
15
|
-
"*",
|
|
16
|
-
"general.cocreate.app"
|
|
17
|
-
],
|
|
18
|
-
"directory": "utils",
|
|
19
|
-
"content-type": "{{content-type}}",
|
|
20
|
-
"public": "true"
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
}
|
|
1
|
+
module.exports = {
|
|
2
|
+
"organization_id": "",
|
|
3
|
+
"key": "",
|
|
4
|
+
"host": "",
|
|
5
|
+
"sources": [
|
|
6
|
+
{
|
|
7
|
+
"array": "files",
|
|
8
|
+
"object": {
|
|
9
|
+
"_id": "6143fc94829b690010a5f339",
|
|
10
|
+
"name": "index.html",
|
|
11
|
+
"path": "/docs/utils",
|
|
12
|
+
"pathname": "/docs/utils/index.html",
|
|
13
|
+
"src": "{{./docs/index.html}}",
|
|
14
|
+
"host": [
|
|
15
|
+
"*",
|
|
16
|
+
"general.cocreate.app"
|
|
17
|
+
],
|
|
18
|
+
"directory": "utils",
|
|
19
|
+
"content-type": "{{content-type}}",
|
|
20
|
+
"public": "true"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
};
|
package/docs/index.html
CHANGED
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -39,8 +39,25 @@
|
|
|
39
39
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Generates an ObjectId
|
|
44
|
+
*/
|
|
45
|
+
const ObjectId = (id) => {
|
|
46
|
+
// Define the rnd function
|
|
47
|
+
const rnd = (r16) => Math.floor(r16).toString(16);
|
|
48
|
+
|
|
49
|
+
if (id === undefined) {
|
|
50
|
+
// If id is undefined, generate a new ObjectId
|
|
51
|
+
return rnd(Date.now() / 1000) + '0'.repeat(16).replace(/./g, () => rnd(Math.random() * 16));
|
|
52
|
+
} else {
|
|
53
|
+
// Check if the provided id is a valid ObjectId
|
|
54
|
+
const validIdRegex = /^[0-9a-fA-F]{24}$/;
|
|
55
|
+
if (!validIdRegex.test(id)) {
|
|
56
|
+
throw new Error('Invalid ObjectId');
|
|
57
|
+
}
|
|
58
|
+
return id; // Return the valid ObjectId as a string
|
|
59
|
+
}
|
|
60
|
+
};
|
|
44
61
|
|
|
45
62
|
function checkValue(value) {
|
|
46
63
|
if (/{{\s*([\w\W]+)\s*}}/g.test(value))
|
|
@@ -49,10 +66,28 @@
|
|
|
49
66
|
return true
|
|
50
67
|
}
|
|
51
68
|
|
|
69
|
+
function isValidDate(value) {
|
|
70
|
+
// Check if the value is a string and can be converted to a Date object
|
|
71
|
+
if (typeof value === 'string'
|
|
72
|
+
&& !isNaN(value)
|
|
73
|
+
&& !(/^[0-9a-fA-F]{24}$/.test(value))
|
|
74
|
+
&& !(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z|Mon|Tue|Wed|Thu|Fri|Sat|Sun [A-Za-z]{3} \d{2} \d{4} \d{2}:\d{2}:\d{2} [A-Za-z]{3} \+\d{4}|\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}(\.\d{1,3})?|\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d{1,3})?|\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}(\.\d{1,3})?|Sun|Mon|Tue|Wed|Thu|Fri|Sat),? .+$/.test(value))
|
|
75
|
+
) {
|
|
76
|
+
const dateObject = new Date(value);
|
|
77
|
+
|
|
78
|
+
// Check if the result of the Date constructor is a valid Date object
|
|
79
|
+
if (!isNaN(dateObject) && dateObject.toString() !== 'Invalid Date') {
|
|
80
|
+
return dateObject; // It's a valid Date object
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return value; // It's not a valid Date object
|
|
85
|
+
}
|
|
86
|
+
|
|
52
87
|
function dotNotationToObject(data, obj = {}) {
|
|
53
88
|
try {
|
|
54
89
|
for (const key of Object.keys(data)) {
|
|
55
|
-
let value = data[key]
|
|
90
|
+
let value = isValidDate(data[key])
|
|
56
91
|
let newObject = obj
|
|
57
92
|
let oldObject = new Object(obj)
|
|
58
93
|
let keys = key.split('.');
|
|
@@ -602,6 +637,7 @@
|
|
|
602
637
|
return {
|
|
603
638
|
ObjectId,
|
|
604
639
|
checkValue,
|
|
640
|
+
isValidDate,
|
|
605
641
|
dotNotationToObject,
|
|
606
642
|
getValueFromObject,
|
|
607
643
|
isObjectEmpty,
|