extra-utils 3.6.0 → 4.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/README.md +17 -7
- package/lib/json/index.d.ts +2 -2
- package/lib/json/index.js +2 -2
- package/lib/json/index.js.map +1 -1
- package/lib/json/is-json-serializable.d.ts +3 -0
- package/lib/json/is-json-serializable.js +16 -0
- package/lib/json/is-json-serializable.js.map +1 -0
- package/lib/json/is-json-value.d.ts +3 -0
- package/lib/json/{is-json.js → is-json-value.js} +9 -9
- package/lib/json/is-json-value.js.map +1 -0
- package/lib/string/remove-leading-blank-lines.d.ts +1 -1
- package/lib/string/remove-leading-blank-lines.js +6 -2
- package/lib/string/remove-leading-blank-lines.js.map +1 -1
- package/lib/string/remove-trailing-blank-lines.d.ts +1 -1
- package/lib/string/remove-trailing-blank-lines.js +6 -2
- package/lib/string/remove-trailing-blank-lines.js.map +1 -1
- package/package.json +11 -12
- package/lib/json/is-json.d.ts +0 -3
- package/lib/json/is-json.js.map +0 -1
- package/lib/json/is-jsonable.d.ts +0 -3
- package/lib/json/is-jsonable.js +0 -16
- package/lib/json/is-jsonable.js.map +0 -1
package/README.md
CHANGED
|
@@ -29,11 +29,15 @@ function isntFalsy<T>(val: T): val is Exclude<T, Falsy>
|
|
|
29
29
|
|
|
30
30
|
### JSON
|
|
31
31
|
```ts
|
|
32
|
-
function
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
function
|
|
36
|
-
|
|
32
|
+
function isJSONValue(val: unknown): val is JSONValue
|
|
33
|
+
function isntJSONValue<T>(val: T): val is Exclude<T, JSONValue>
|
|
34
|
+
|
|
35
|
+
function isJSONSerializable<T extends
|
|
36
|
+
| JSONValue
|
|
37
|
+
| Record<string, JSONValue | JSONSerializable<any>>
|
|
38
|
+
| Array<JSONValue | JSONSerializable<any>>
|
|
39
|
+
>(val: unknown): val is JSONSerializable<T>
|
|
40
|
+
function isntJSONSerializable<T>(val: T): val is Exclude<T, JSONSerializable<any>>
|
|
37
41
|
```
|
|
38
42
|
|
|
39
43
|
### Nullish
|
|
@@ -137,7 +141,10 @@ removeBlankLines(
|
|
|
137
141
|
|
|
138
142
|
#### removeLeadingBlankLines
|
|
139
143
|
```ts
|
|
140
|
-
function removeLeadingBlankLines(
|
|
144
|
+
function removeLeadingBlankLines(
|
|
145
|
+
text: string
|
|
146
|
+
, maxRemovals: number = Infinity
|
|
147
|
+
): string
|
|
141
148
|
```
|
|
142
149
|
|
|
143
150
|
Example:
|
|
@@ -153,7 +160,10 @@ removeLeadingBlankLines(
|
|
|
153
160
|
|
|
154
161
|
#### removeTrailingBlankLines
|
|
155
162
|
```ts
|
|
156
|
-
function removeTrailingBlankLines(
|
|
163
|
+
function removeTrailingBlankLines(
|
|
164
|
+
text: string
|
|
165
|
+
, maxRemovals: number = Infinity
|
|
166
|
+
): string
|
|
157
167
|
```
|
|
158
168
|
|
|
159
169
|
Example:
|
package/lib/json/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './is-json';
|
|
2
|
-
export * from './is-
|
|
1
|
+
export * from './is-json-value';
|
|
2
|
+
export * from './is-json-serializable';
|
package/lib/json/index.js
CHANGED
|
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./is-json"), exports);
|
|
18
|
-
__exportStar(require("./is-
|
|
17
|
+
__exportStar(require("./is-json-value"), exports);
|
|
18
|
+
__exportStar(require("./is-json-serializable"), exports);
|
|
19
19
|
//# sourceMappingURL=index.js.map
|
package/lib/json/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/json/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA+B;AAC/B,yDAAsC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { JSONValue, JSONSerializable } from 'justypes';
|
|
2
|
+
export declare function isJSONSerializable<T extends JSONValue | Record<string, JSONValue | JSONSerializable<any>> | Array<JSONValue | JSONSerializable<any>>>(val: unknown): val is JSONSerializable<T>;
|
|
3
|
+
export declare function isntJSONSerializable<T>(val: T): val is Exclude<T, JSONSerializable<any>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isntJSONSerializable = exports.isJSONSerializable = void 0;
|
|
4
|
+
const object_1 = require("../object");
|
|
5
|
+
const is_function_1 = require("../is-function");
|
|
6
|
+
function isJSONSerializable(val) {
|
|
7
|
+
return (0, object_1.isObject)(val)
|
|
8
|
+
&& 'toJSON' in val
|
|
9
|
+
&& (0, is_function_1.isFunction)(val.toJSON);
|
|
10
|
+
}
|
|
11
|
+
exports.isJSONSerializable = isJSONSerializable;
|
|
12
|
+
function isntJSONSerializable(val) {
|
|
13
|
+
return !isJSONSerializable(val);
|
|
14
|
+
}
|
|
15
|
+
exports.isntJSONSerializable = isntJSONSerializable;
|
|
16
|
+
//# sourceMappingURL=is-json-serializable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-json-serializable.js","sourceRoot":"","sources":["../../src/json/is-json-serializable.ts"],"names":[],"mappings":";;;AACA,wCAAsC;AACtC,kDAA6C;AAE7C,SAAgB,kBAAkB,CAIhC,GAAY;IACZ,OAAO,IAAA,iBAAQ,EAAC,GAAG,CAAC;WACb,QAAQ,IAAI,GAAG;WACf,IAAA,wBAAU,EAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC/B,CAAC;AARD,gDAQC;AAED,SAAgB,oBAAoB,CAAI,GAAM;IAC5C,OAAO,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAA;AACjC,CAAC;AAFD,oDAEC"}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isntJSONValue = exports.isJSONValue = void 0;
|
|
4
4
|
const nullish_1 = require("../nullish");
|
|
5
5
|
const boolean_1 = require("../boolean");
|
|
6
6
|
const string_1 = require("../string");
|
|
7
7
|
const number_1 = require("../number");
|
|
8
8
|
const array_1 = require("../array");
|
|
9
9
|
const object_1 = require("../object");
|
|
10
|
-
function
|
|
10
|
+
function isJSONValue(val) {
|
|
11
11
|
return (0, nullish_1.isNull)(val)
|
|
12
12
|
|| (0, boolean_1.isBoolean)(val)
|
|
13
13
|
|| (0, string_1.isString)(val)
|
|
14
14
|
|| (0, number_1.isNumber)(val)
|
|
15
|
-
|| ((0, array_1.isArray)(val) && val.every(
|
|
16
|
-
|| ((0, object_1.isPlainObject)(val) && Object.values(val).every(
|
|
15
|
+
|| ((0, array_1.isArray)(val) && val.every(isJSONValue))
|
|
16
|
+
|| ((0, object_1.isPlainObject)(val) && Object.values(val).every(isJSONValue));
|
|
17
17
|
}
|
|
18
|
-
exports.
|
|
19
|
-
function
|
|
20
|
-
return !
|
|
18
|
+
exports.isJSONValue = isJSONValue;
|
|
19
|
+
function isntJSONValue(val) {
|
|
20
|
+
return !isJSONValue(val);
|
|
21
21
|
}
|
|
22
|
-
exports.
|
|
23
|
-
//# sourceMappingURL=is-json.js.map
|
|
22
|
+
exports.isntJSONValue = isntJSONValue;
|
|
23
|
+
//# sourceMappingURL=is-json-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-json-value.js","sourceRoot":"","sources":["../../src/json/is-json-value.ts"],"names":[],"mappings":";;;AACA,0CAAqC;AACrC,0CAAwC;AACxC,wCAAsC;AACtC,wCAAsC;AACtC,sCAAoC;AACpC,wCAA2C;AAE3C,SAAgB,WAAW,CAAC,GAAY;IACtC,OAAO,IAAA,gBAAM,EAAC,GAAG,CAAC;WACX,IAAA,mBAAS,EAAC,GAAG,CAAC;WACd,IAAA,iBAAQ,EAAC,GAAG,CAAC;WACb,IAAA,iBAAQ,EAAC,GAAG,CAAC;WACb,CAAC,IAAA,eAAO,EAAC,GAAG,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;WACxC,CAAC,IAAA,sBAAa,EAAC,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;AACtE,CAAC;AAPD,kCAOC;AAED,SAAgB,aAAa,CAAI,GAAM;IACrC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;AAC1B,CAAC;AAFD,sCAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function removeLeadingBlankLines(text: string): string;
|
|
1
|
+
export declare function removeLeadingBlankLines(text: string, maxRemovals?: number): string;
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeLeadingBlankLines = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
|
-
function removeLeadingBlankLines(text) {
|
|
5
|
+
function removeLeadingBlankLines(text, maxRemovals = Infinity) {
|
|
6
6
|
const lines = text.split('\n');
|
|
7
|
-
|
|
7
|
+
let removals = 0;
|
|
8
|
+
while (removals < maxRemovals &&
|
|
9
|
+
lines.length > 0 &&
|
|
10
|
+
(0, utils_1.isBlankLine)(lines[0])) {
|
|
8
11
|
lines.shift();
|
|
12
|
+
removals++;
|
|
9
13
|
}
|
|
10
14
|
return lines.join('\n');
|
|
11
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-leading-blank-lines.js","sourceRoot":"","sources":["../../src/string/remove-leading-blank-lines.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAErC,SAAgB,uBAAuB,
|
|
1
|
+
{"version":3,"file":"remove-leading-blank-lines.js","sourceRoot":"","sources":["../../src/string/remove-leading-blank-lines.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAErC,SAAgB,uBAAuB,CACrC,IAAY,EACZ,cAAsB,QAAQ;IAE9B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAE9B,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,OACE,QAAQ,GAAG,WAAW;QACtB,KAAK,CAAC,MAAM,GAAG,CAAC;QAChB,IAAA,mBAAW,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EACrB;QACA,KAAK,CAAC,KAAK,EAAE,CAAA;QACb,QAAQ,EAAE,CAAA;KACX;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAjBD,0DAiBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function removeTrailingBlankLines(text: string): string;
|
|
1
|
+
export declare function removeTrailingBlankLines(text: string, maxRemovals?: number): string;
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.removeTrailingBlankLines = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
|
5
|
-
function removeTrailingBlankLines(text) {
|
|
5
|
+
function removeTrailingBlankLines(text, maxRemovals = Infinity) {
|
|
6
6
|
const lines = text.split('\n');
|
|
7
|
-
|
|
7
|
+
let removals = 0;
|
|
8
|
+
while (removals < maxRemovals &&
|
|
9
|
+
lines.length > 0 &&
|
|
10
|
+
(0, utils_1.isBlankLine)(lines[lines.length - 1])) {
|
|
8
11
|
lines.pop();
|
|
12
|
+
removals++;
|
|
9
13
|
}
|
|
10
14
|
return lines.join('\n');
|
|
11
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-trailing-blank-lines.js","sourceRoot":"","sources":["../../src/string/remove-trailing-blank-lines.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAErC,SAAgB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"remove-trailing-blank-lines.js","sourceRoot":"","sources":["../../src/string/remove-trailing-blank-lines.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAErC,SAAgB,wBAAwB,CACtC,IAAY,EACZ,cAAsB,QAAQ;IAE9B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAE9B,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,OACE,QAAQ,GAAG,WAAW;QACtB,KAAK,CAAC,MAAM,GAAG,CAAC;QAChB,IAAA,mBAAW,EAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EACpC;QACA,KAAK,CAAC,GAAG,EAAE,CAAA;QACX,QAAQ,EAAE,CAAA;KACX;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAjBD,4DAiBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Utilities for JavaScript and Typescript",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib"
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"repository": "git@github.com:BlackGlory/extra-utils.git",
|
|
12
12
|
"author": "BlackGlory <woshenmedoubuzhidao@blackglory.me>",
|
|
13
13
|
"license": "MIT",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=12"
|
|
16
|
+
},
|
|
14
17
|
"scripts": {
|
|
15
18
|
"lint": "eslint --ext .js,.jsx,.ts,.tsx --quiet src __tests__",
|
|
16
19
|
"test": "jest --runInBand --config jest.config.js",
|
|
@@ -29,33 +32,29 @@
|
|
|
29
32
|
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
|
30
33
|
}
|
|
31
34
|
},
|
|
32
|
-
"engines": {
|
|
33
|
-
"node": ">=12"
|
|
34
|
-
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@blackglory/pass": "^1.1.0",
|
|
37
37
|
"@commitlint/cli": "^17.3.0",
|
|
38
38
|
"@commitlint/config-conventional": "^17.3.0",
|
|
39
|
-
"@types/jest": "^29.2.
|
|
39
|
+
"@types/jest": "^29.2.4",
|
|
40
40
|
"@types/jsdom": "^20.0.1",
|
|
41
|
-
"@types/lodash": "^4.14.
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
43
|
-
"@typescript-eslint/parser": "^5.
|
|
44
|
-
"eslint": "^8.
|
|
41
|
+
"@types/lodash": "^4.14.191",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
|
43
|
+
"@typescript-eslint/parser": "^5.46.1",
|
|
44
|
+
"eslint": "^8.30.0",
|
|
45
45
|
"husky": "^4.3.8",
|
|
46
46
|
"jest": "^29.3.1",
|
|
47
|
-
"jest-extended": "^3.2.0",
|
|
48
47
|
"npm-run-all": "^4.1.5",
|
|
49
48
|
"rimraf": "^3.0.2",
|
|
50
49
|
"standard-version": "^9.5.0",
|
|
51
50
|
"ts-jest": "^29.0.3",
|
|
52
51
|
"tscpaths": "^0.0.9",
|
|
53
|
-
"tsd": "^0.
|
|
52
|
+
"tsd": "^0.25.0",
|
|
54
53
|
"tslib": "^2.4.1",
|
|
55
54
|
"typescript": "4.9.3"
|
|
56
55
|
},
|
|
57
56
|
"dependencies": {
|
|
58
|
-
"justypes": "^
|
|
57
|
+
"justypes": "^4.0.0",
|
|
59
58
|
"lodash": "^4.17.21"
|
|
60
59
|
}
|
|
61
60
|
}
|
package/lib/json/is-json.d.ts
DELETED
package/lib/json/is-json.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-json.js","sourceRoot":"","sources":["../../src/json/is-json.ts"],"names":[],"mappings":";;;AACA,0CAAqC;AACrC,0CAAwC;AACxC,wCAAsC;AACtC,wCAAsC;AACtC,sCAAoC;AACpC,wCAA2C;AAE3C,SAAgB,MAAM,CAAC,GAAY;IACjC,OAAO,IAAA,gBAAM,EAAC,GAAG,CAAC;WACX,IAAA,mBAAS,EAAC,GAAG,CAAC;WACd,IAAA,iBAAQ,EAAC,GAAG,CAAC;WACb,IAAA,iBAAQ,EAAC,GAAG,CAAC;WACb,CAAC,IAAA,eAAO,EAAC,GAAG,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;WACnC,CAAC,IAAA,sBAAa,EAAC,GAAG,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;AACjE,CAAC;AAPD,wBAOC;AAED,SAAgB,QAAQ,CAAI,GAAM;IAChC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACrB,CAAC;AAFD,4BAEC"}
|
package/lib/json/is-jsonable.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isntJsonable = exports.isJsonable = void 0;
|
|
4
|
-
const object_1 = require("../object");
|
|
5
|
-
const is_function_1 = require("../is-function");
|
|
6
|
-
function isJsonable(val) {
|
|
7
|
-
return (0, object_1.isObject)(val)
|
|
8
|
-
&& 'toJSON' in val
|
|
9
|
-
&& (0, is_function_1.isFunction)(val.toJSON);
|
|
10
|
-
}
|
|
11
|
-
exports.isJsonable = isJsonable;
|
|
12
|
-
function isntJsonable(val) {
|
|
13
|
-
return !isJsonable(val);
|
|
14
|
-
}
|
|
15
|
-
exports.isntJsonable = isntJsonable;
|
|
16
|
-
//# sourceMappingURL=is-jsonable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"is-jsonable.js","sourceRoot":"","sources":["../../src/json/is-jsonable.ts"],"names":[],"mappings":";;;AACA,wCAAsC;AACtC,kDAA6C;AAE7C,SAAgB,UAAU,CAAiB,GAAY;IACrD,OAAO,IAAA,iBAAQ,EAAC,GAAG,CAAC;WACb,QAAQ,IAAI,GAAG;WACf,IAAA,wBAAU,EAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AAC/B,CAAC;AAJD,gCAIC;AAED,SAAgB,YAAY,CAAI,GAAM;IACpC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;AACzB,CAAC;AAFD,oCAEC"}
|