yummies 3.2.12 → 3.3.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/common.d.ts +9 -1
- package/common.d.ts.map +1 -1
- package/common.js +9 -3
- package/date-time.d.ts +1 -1
- package/date-time.d.ts.map +1 -1
- package/date-time.js +1 -1
- package/package.json +6 -1
- package/text.d.ts +4 -0
- package/text.d.ts.map +1 -1
- package/text.js +38 -0
package/common.d.ts
CHANGED
|
@@ -3,5 +3,13 @@ import { MaybeFn } from './utils/types.js';
|
|
|
3
3
|
* @deprecated use {MaybeFn} type
|
|
4
4
|
*/
|
|
5
5
|
export type FnValue<TValue, TArgs extends any[] = []> = MaybeFn<TValue, TArgs>;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Calls the provided function with the given arguments if it is a function;
|
|
8
|
+
* otherwise, returns the value directly.
|
|
9
|
+
*/
|
|
10
|
+
export declare const callFunction: <TValue, TArgs extends any[] = []>(fn: MaybeFn<TValue, TArgs>, ...args: TArgs) => TValue;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated use {callFunction}
|
|
13
|
+
*/
|
|
14
|
+
export declare const resolveFnValue: <TValue, TArgs extends any[] = []>(fn: MaybeFn<TValue, TArgs>, ...args: TArgs) => TValue;
|
|
7
15
|
//# sourceMappingURL=common.d.ts.map
|
package/common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,OAAO,CAAC,MAAM,EAAE,KAAK,SAAS,GAAG,EAAE,GAAG,EAAE,IAAI,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE/E,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,OAAO,CAAC,MAAM,EAAE,KAAK,SAAS,GAAG,EAAE,GAAG,EAAE,IAAI,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE/E;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,EAAE,KAAK,SAAS,GAAG,EAAE,GAAG,EAAE,EAC3D,IAAI,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,EAC1B,GAAG,MAAM,KAAK,WAOf,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAdE,MAAM,EAAE,KAAK,SAAS,GAAG,EAAE,WAClD,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,WACjB,KAAK,WAY0B,CAAC"}
|
package/common.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Calls the provided function with the given arguments if it is a function;
|
|
3
|
+
* otherwise, returns the value directly.
|
|
4
|
+
*/
|
|
5
|
+
export const callFunction = (fn, ...args) => {
|
|
4
6
|
if (typeof fn === 'function') {
|
|
5
7
|
return fn(...args);
|
|
6
8
|
}
|
|
7
9
|
return fn;
|
|
8
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated use {callFunction}
|
|
13
|
+
*/
|
|
14
|
+
export const resolveFnValue = callFunction;
|
package/date-time.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dayjs, ManipulateType } from 'dayjs';
|
|
2
2
|
import { Maybe } from './utils/types.js';
|
|
3
|
-
import 'dayjs/locale/ru';
|
|
3
|
+
import 'dayjs/locale/ru.js';
|
|
4
4
|
export declare const formatDate: (value: Maybe<string | number | Dayjs>, settings?: Maybe<{
|
|
5
5
|
format?: "human" | "full" | "short" | "day" | "day-only" | "date" | "month" | "spent-time" | "time" | "time-short";
|
|
6
6
|
pattern?: string;
|
package/date-time.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-time.d.ts","sourceRoot":"","sources":["../src/date-time.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAOrD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,
|
|
1
|
+
{"version":3,"file":"date-time.d.ts","sourceRoot":"","sources":["../src/date-time.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAOrD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,oBAAoB,CAAC;AAwB5B,eAAO,MAAM,UAAU,GACrB,OAAO,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC,EACrC,WAAW,KAAK,CAAC;IACf,MAAM,CAAC,EACH,OAAO,GACP,MAAM,GACN,OAAO,GACP,KAAK,GACL,UAAU,GACV,MAAM,GACN,OAAO,GACP,YAAY,GACZ,MAAM,GACN,YAAY,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC,WA6CH,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM;;;;;;CAwB/C,CAAC;AAEF,KAAK,eAAe,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC,CAAC;AAEtE,eAAO,MAAM,UAAU,GACrB,MAAM,KAAK,CAAC,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,EACnC,GAAG,MAAM,CACP,GAAG,eAAe,EAClB,GAAG,OAAO,CAAC,eAAe,CAAC,EAC3B,GAAG,OAAO,CAAC,eAAe,CAAC,EAC3B,GAAG,OAAO,CAAC,eAAe,CAAC,EAC3B,GAAG,OAAO,CAAC,eAAe,CAAC,EAC3B,GAAG,OAAO,CAAC,eAAe,CAAC,CAC5B,SAaF,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,UAAU,MAAM;;;;;CAU5C,CAAC;AASF,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,IAAI,EACX,KAAK,EAAE,IAAI,EACX,OAAO,CAAC,EAAE,OAAO,GAChB,MAAM,CAAC;AACV,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC"}
|
package/date-time.js
CHANGED
|
@@ -4,7 +4,7 @@ import relativeTime from 'dayjs/plugin/relativeTime.js';
|
|
|
4
4
|
import { unitsToMs } from './ms.js';
|
|
5
5
|
import { declension } from './text.js';
|
|
6
6
|
import { typeGuard } from './type-guard/index.js';
|
|
7
|
-
import 'dayjs/locale/ru';
|
|
7
|
+
import 'dayjs/locale/ru.js';
|
|
8
8
|
dayjs.extend(relativeTime);
|
|
9
9
|
dayjs.extend(duration);
|
|
10
10
|
dayjs.locale('ru');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yummies",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": "js2me",
|
|
6
6
|
"license": "MIT",
|
|
@@ -167,6 +167,11 @@
|
|
|
167
167
|
"default": "./storage.js",
|
|
168
168
|
"types": "./storage.d.ts"
|
|
169
169
|
},
|
|
170
|
+
"./text.test": {
|
|
171
|
+
"import": "./text.test.js",
|
|
172
|
+
"default": "./text.test.js",
|
|
173
|
+
"types": "./text.test.d.ts"
|
|
174
|
+
},
|
|
170
175
|
"./text": {
|
|
171
176
|
"import": "./text.js",
|
|
172
177
|
"default": "./text.js",
|
package/text.d.ts
CHANGED
|
@@ -8,4 +8,8 @@
|
|
|
8
8
|
* declension(5, ['слово', 'слова', 'слов']) // 'слов'
|
|
9
9
|
*/
|
|
10
10
|
export declare const declension: (count: number, txt: readonly [one: string, two: string, five: string], cases?: number[]) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Разбиение текста на линии
|
|
13
|
+
*/
|
|
14
|
+
export declare const splitTextByLines: (text: string, lineLingth?: number) => string[];
|
|
11
15
|
//# sourceMappingURL=text.d.ts.map
|
package/text.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GACrB,OAAO,MAAM,EACb,KAAK,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,EACtD,gBAA0B,WAEmD,CAAC"}
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GACrB,OAAO,MAAM,EACb,KAAK,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,EACtD,gBAA0B,WAEmD,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAC3B,MAAM,MAAM,EACZ,aAAY,MAAW,KACtB,MAAM,EAqCR,CAAC"}
|
package/text.js
CHANGED
|
@@ -8,3 +8,41 @@
|
|
|
8
8
|
* declension(5, ['слово', 'слова', 'слов']) // 'слов'
|
|
9
9
|
*/
|
|
10
10
|
export const declension = (count, txt, cases = [2, 0, 1, 1, 1, 2]) => txt[count % 100 > 4 && count % 100 < 20 ? 2 : cases[Math.min(count % 10, 5)]];
|
|
11
|
+
/**
|
|
12
|
+
* Разбиение текста на линии
|
|
13
|
+
*/
|
|
14
|
+
export const splitTextByLines = (text, lineLingth = 60) => {
|
|
15
|
+
const words = text.split(/\s+/).filter((word) => word !== '');
|
|
16
|
+
const lines = [];
|
|
17
|
+
let currentLine = '';
|
|
18
|
+
for (const word of words) {
|
|
19
|
+
if (word.length > lineLingth) {
|
|
20
|
+
if (currentLine !== '') {
|
|
21
|
+
lines.push(currentLine);
|
|
22
|
+
currentLine = '';
|
|
23
|
+
}
|
|
24
|
+
let start = 0;
|
|
25
|
+
while (start < word.length) {
|
|
26
|
+
const chunk = word.slice(start, start + lineLingth);
|
|
27
|
+
lines.push(chunk);
|
|
28
|
+
start += lineLingth;
|
|
29
|
+
}
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
// Проверка возможности добавления слова в текущую строку
|
|
33
|
+
if (currentLine === '') {
|
|
34
|
+
currentLine = word;
|
|
35
|
+
}
|
|
36
|
+
else if (currentLine.length + 1 + word.length <= lineLingth) {
|
|
37
|
+
currentLine += ' ' + word;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
lines.push(currentLine);
|
|
41
|
+
currentLine = word;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (currentLine !== '' || lines.length === 0) {
|
|
45
|
+
lines.push(currentLine);
|
|
46
|
+
}
|
|
47
|
+
return lines;
|
|
48
|
+
};
|