@valkyriestudios/utils 6.3.0 → 7.0.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/CHANGELOG.md +17 -0
- package/README.md +15 -2
- package/array/mapPrimitive.js +1 -6
- package/date/startOfUTC.js +29 -0
- package/package.json +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic
|
|
6
6
|
Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [7.0.0] - 2023-05-07
|
|
9
|
+
### Added
|
|
10
|
+
- Dep: @babel/cli
|
|
11
|
+
- .babelrc
|
|
12
|
+
- Switch to using babel-cli for transpiling build
|
|
13
|
+
- date/startOfUTC (1.000.000 ops in ~500ms)
|
|
14
|
+
|
|
15
|
+
### Improved
|
|
16
|
+
- Dep: Upgrade @babel/core to 7.21.8
|
|
17
|
+
- Dep: Upgrade eslint to 8.40.0
|
|
18
|
+
|
|
19
|
+
### Removed
|
|
20
|
+
- Dep: gulp
|
|
21
|
+
- Dep: gulp-babel
|
|
22
|
+
- gulpfile
|
|
23
|
+
- array/mapPrimitive: keytrim option
|
|
24
|
+
|
|
8
25
|
## [6.3.0] - 2023-05-01
|
|
9
26
|
### Added
|
|
10
27
|
- date/toUTC (benchmark 1.000.000 opts in ~500ms)
|
package/README.md
CHANGED
|
@@ -117,12 +117,12 @@ output:
|
|
|
117
117
|
|
|
118
118
|
options are the same as the mapKey function
|
|
119
119
|
|
|
120
|
-
- **mapPrimitive(val:any, opts:object={
|
|
120
|
+
- **mapPrimitive(val:any, opts:object={valtrim:false,keyround:false,valround:false})**
|
|
121
121
|
Map an array of primitives (number/string)
|
|
122
122
|
```js
|
|
123
123
|
mapPrimitive([1,2,3]); // {1: 1, 2: 2, 3: 3}
|
|
124
124
|
mapPrimitive(['hello', 'hello', 'foo', 'bar']); // {hello: 'hello', foo: 'foo', bar: 'bar'}
|
|
125
|
-
mapPrimitive(['hello', ' hello', 'foo', ' foo'], {
|
|
125
|
+
mapPrimitive(['hello', ' hello', 'foo', ' foo'], {valtrim: true}); // {hello: 'hello', foo: 'foo'}
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
- **dedupe(val:Array)**
|
|
@@ -287,6 +287,19 @@ Returns the current unix timestamp in seconds
|
|
|
287
287
|
- **nowUnixMs()**
|
|
288
288
|
Returns the current unix timestamp in milliseconds
|
|
289
289
|
|
|
290
|
+
- **startOfUTC(val:Date, key:String)**
|
|
291
|
+
Take the incoming date and return a date set to the start of passed key. Possible key options(year,month,day,hour,minute,second).
|
|
292
|
+
|
|
293
|
+
Note: Does not touch the date object passed
|
|
294
|
+
```js
|
|
295
|
+
startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'year'); // new Date("2023-01-01T00:00:00.000Z")
|
|
296
|
+
startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'month'); // new Date("2023-05-01T00:00:00.000Z")
|
|
297
|
+
startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'day'); // new Date("2023-05-04T00:00:00.000Z")
|
|
298
|
+
startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'hour'); // new Date("2023-05-04T10:00:00.000Z")
|
|
299
|
+
startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'minute'); // new Date("2023-05-04T10:04:00.000Z")
|
|
300
|
+
startOfUTC(new Date("2023-05-04T12:04:27.043+02:00"), 'second'); // new Date("2023-05-04T10:04:27.000Z")
|
|
301
|
+
```
|
|
302
|
+
|
|
290
303
|
### deep
|
|
291
304
|
- **deepFreeze(val:Object)**
|
|
292
305
|
Recursively freezes all properties of an object
|
package/array/mapPrimitive.js
CHANGED
|
@@ -16,7 +16,6 @@ function mapPrimitive(arr) {
|
|
|
16
16
|
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
17
17
|
if (!(0, _isNotEmpty2["default"])(arr)) return {};
|
|
18
18
|
var OPTS = Object.assign({
|
|
19
|
-
keytrim: !0,
|
|
20
19
|
valtrim: !1,
|
|
21
20
|
keyround: !1,
|
|
22
21
|
valround: !1
|
|
@@ -34,11 +33,7 @@ function mapPrimitive(arr) {
|
|
|
34
33
|
map[el] = OPTS.valround ? Math.round(el) : el;
|
|
35
34
|
}
|
|
36
35
|
} else if ((0, _isNotEmpty["default"])(el)) {
|
|
37
|
-
|
|
38
|
-
map[el.trim()] = OPTS.valtrim ? el.trim() : el;
|
|
39
|
-
} else {
|
|
40
|
-
map[el] = OPTS.valtrim ? el.trim() : el;
|
|
41
|
-
}
|
|
36
|
+
map[el.trim()] = OPTS.valtrim ? el.trim() : el;
|
|
42
37
|
}
|
|
43
38
|
}
|
|
44
39
|
} catch (err) {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = startOfUTC;
|
|
7
|
+
var _is = _interopRequireDefault(require("./is"));
|
|
8
|
+
var _isNotEmpty = _interopRequireDefault(require("../string/isNotEmpty"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
+
function startOfUTC(val, key) {
|
|
11
|
+
if (!(0, _is["default"])(val)) throw new Error('Date To UTC requires a date object');
|
|
12
|
+
if (!(0, _isNotEmpty["default"])(key)) throw new Error('Key needs to be a string with content');
|
|
13
|
+
switch (key) {
|
|
14
|
+
case 'year':
|
|
15
|
+
return new Date(Date.UTC(val.getUTCFullYear(), 0, 1, 0, 0, 0, 0));
|
|
16
|
+
case 'month':
|
|
17
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), 1, 0, 0, 0, 0));
|
|
18
|
+
case 'day':
|
|
19
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), 0, 0, 0, 0));
|
|
20
|
+
case 'hour':
|
|
21
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), 0, 0, 0));
|
|
22
|
+
case 'minute':
|
|
23
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), 0, 0));
|
|
24
|
+
case 'second':
|
|
25
|
+
return new Date(Date.UTC(val.getUTCFullYear(), val.getUTCMonth(), val.getUTCDate(), val.getUTCHours(), val.getUTCMinutes(), val.getUTCSeconds(), 0));
|
|
26
|
+
default:
|
|
27
|
+
return val;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@valkyriestudios/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "A collection of single-function utilities for common tasks",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"test": "nyc --reporter=lcov --reporter=text-summary mocha --colors --require @babel/register ./test/**/*.test.js",
|
|
21
21
|
"test_ci": "nyc --reporter=lcov mocha --colors --require @babel/register ./test/**/*.test.js",
|
|
22
22
|
"lint": "./node_modules/.bin/eslint ./src",
|
|
23
|
-
"build": "
|
|
23
|
+
"build": "npx babel src --out-dir ./ && npm run lint",
|
|
24
24
|
"codecov": "codecov"
|
|
25
25
|
},
|
|
26
26
|
"repository": {
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/ValkyrieStudios/utils#readme",
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@babel/
|
|
35
|
+
"@babel/cli": "^7.21.5",
|
|
36
|
+
"@babel/core": "^7.21.8",
|
|
36
37
|
"@babel/preset-env": "^7.21.5",
|
|
37
38
|
"@babel/register": "^7.21.0",
|
|
38
39
|
"babel-plugin-check-es2015-constants": "^6.22.0",
|
|
@@ -43,9 +44,7 @@
|
|
|
43
44
|
"chai": "^4.3.7",
|
|
44
45
|
"chai-as-promised": "^7.1.1",
|
|
45
46
|
"chai-spies": "^1.0.0",
|
|
46
|
-
"eslint": "^8.
|
|
47
|
-
"gulp": "^4.0.2",
|
|
48
|
-
"gulp-babel": "^8.0.0",
|
|
47
|
+
"eslint": "^8.40.0",
|
|
49
48
|
"mocha": "^10.2.0",
|
|
50
49
|
"nyc": "^15.1.0"
|
|
51
50
|
}
|