@httptoolkit/util 0.1.6 → 0.1.7
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/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/text.d.ts +7 -0
- package/dist/text.js +33 -0
- package/dist/text.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/text.ts +33 -0
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./promises"), exports);
|
|
18
18
|
__exportStar(require("./errors"), exports);
|
|
19
|
+
__exportStar(require("./text"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,2CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,2CAAyB;AACzB,yCAAuB"}
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function truncateWithEllipsis(str: string, length: number): string;
|
|
2
|
+
export declare function joinAnd(val: string[], options?: {
|
|
3
|
+
separator?: string;
|
|
4
|
+
finalSeparator?: string;
|
|
5
|
+
oxfordComma?: boolean;
|
|
6
|
+
}): string;
|
|
7
|
+
export declare function aOrAn(value: string): "a" | "an";
|
package/dist/text.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.aOrAn = exports.joinAnd = exports.truncateWithEllipsis = void 0;
|
|
4
|
+
function truncateWithEllipsis(str, length) {
|
|
5
|
+
if (str.length <= length) {
|
|
6
|
+
return str;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
return str.slice(0, length - 3) + "...";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.truncateWithEllipsis = truncateWithEllipsis;
|
|
13
|
+
function joinAnd(val, options = {}) {
|
|
14
|
+
if (val.length === 1)
|
|
15
|
+
return val[0];
|
|
16
|
+
const separator = options.separator ?? ', ';
|
|
17
|
+
const finalSeparator = options.finalSeparator ?? 'and ';
|
|
18
|
+
const oxfordComma = options.oxfordComma ?? false;
|
|
19
|
+
return val.slice(0, -1).join(separator) +
|
|
20
|
+
(oxfordComma ? separator : ' ') +
|
|
21
|
+
finalSeparator +
|
|
22
|
+
val[val.length - 1];
|
|
23
|
+
}
|
|
24
|
+
exports.joinAnd = joinAnd;
|
|
25
|
+
const VOWEL_ISH = ['a', 'e', 'i', 'o', 'u', 'y'];
|
|
26
|
+
function aOrAn(value) {
|
|
27
|
+
if (VOWEL_ISH.includes(value[0].toLowerCase()))
|
|
28
|
+
return 'an';
|
|
29
|
+
else
|
|
30
|
+
return 'a';
|
|
31
|
+
}
|
|
32
|
+
exports.aOrAn = aOrAn;
|
|
33
|
+
//# sourceMappingURL=text.js.map
|
package/dist/text.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":";;;AAAA,SAAgB,oBAAoB,CAAC,GAAW,EAAE,MAAc;IAC5D,IAAI,GAAG,CAAC,MAAM,IAAI,MAAM,EAAE;QACtB,OAAO,GAAG,CAAC;KACd;SAAM;QACH,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;KAC3C;AACL,CAAC;AAND,oDAMC;AAED,SAAgB,OAAO,CAAC,GAAa,EAAE,UAOnC,EAAE;IACF,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;IAEpC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;IAC5C,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,MAAM,CAAC;IACxD,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,KAAK,CAAC;IAEjD,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;QACnC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC;QAC/B,cAAc;QACd,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC5B,CAAC;AAlBD,0BAkBC;AAED,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AACjD,SAAgB,KAAK,CAAC,KAAa;IAC/B,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QAAE,OAAO,IAAI,CAAC;;QACvD,OAAO,GAAG,CAAC;AACpB,CAAC;AAHD,sBAGC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/text.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function truncateWithEllipsis(str: string, length: number) {
|
|
2
|
+
if (str.length <= length) {
|
|
3
|
+
return str;
|
|
4
|
+
} else {
|
|
5
|
+
return str.slice(0, length - 3) + "...";
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function joinAnd(val: string[], options: {
|
|
10
|
+
// Separator between all but the last value
|
|
11
|
+
separator?: string,
|
|
12
|
+
// Separator before last value (preceeded with space or `separator` if oxfordComma is true)
|
|
13
|
+
finalSeparator?: string,
|
|
14
|
+
// Should there be a separator between the penultimate value & finalSeparator?
|
|
15
|
+
oxfordComma?: boolean
|
|
16
|
+
} = {}) {
|
|
17
|
+
if (val.length === 1) return val[0];
|
|
18
|
+
|
|
19
|
+
const separator = options.separator ?? ', ';
|
|
20
|
+
const finalSeparator = options.finalSeparator ?? 'and ';
|
|
21
|
+
const oxfordComma = options.oxfordComma ?? false;
|
|
22
|
+
|
|
23
|
+
return val.slice(0, -1).join(separator) +
|
|
24
|
+
(oxfordComma ? separator : ' ') +
|
|
25
|
+
finalSeparator +
|
|
26
|
+
val[val.length - 1];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const VOWEL_ISH = ['a', 'e', 'i', 'o', 'u', 'y'];
|
|
30
|
+
export function aOrAn(value: string) {
|
|
31
|
+
if (VOWEL_ISH.includes(value[0].toLowerCase())) return 'an';
|
|
32
|
+
else return 'a';
|
|
33
|
+
}
|