@mikitasazan/notify 1.5.0 → 1.6.1

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 CHANGED
@@ -2,4 +2,5 @@ export type { EventType, NotifyEvent, Project } from './events.ts';
2
2
  export { severity } from './events.ts';
3
3
  export { notify, sendReport } from './send.ts';
4
4
  export { render } from './render.ts';
5
+ export { trend } from './trend.ts';
5
6
  export type { SendResult } from './send.ts';
package/dist/index.js CHANGED
@@ -1,6 +1,10 @@
1
1
  export { severity } from "./events.js";
2
2
  export { notify, sendReport } from "./send.js";
3
- // `render` наружу чтобы отправитель мог положить на диск РОВНО ту карточку,
4
- // которая уехала, а не свою вторую версию текста. Сборка копии вручную уже
5
- // расходилась с отправленным.
3
+ // `render` is exported so a sender can put on disk EXACTLY the card that was
4
+ // sent rather than its own second version of the text. A hand-built copy had
5
+ // already drifted from what went out.
6
6
  export { render } from "./render.js";
7
+ // `trend` is exported for the same reason one floor down: the shape of a
8
+ // number is the package's, not each sender's. Two report senders had grown two
9
+ // dialects for one thing.
10
+ export { trend } from "./trend.js";
package/dist/render.js CHANGED
@@ -199,7 +199,14 @@ const note = (text) => {
199
199
  * стоит отдельной строкой, потому что сам текст в поле не помещается: поле
200
200
  * держит одну строку и обрезает.
201
201
  */
202
- const quoted = (label, text) => text ? `<b>${esc(cap(label))}</b>\n${note(text)}` : null;
202
+ /**
203
+ * A quote that needs saying what it is. The heading is a GROUP heading — the
204
+ * same italic-underline every other card uses over a block — not a bold field
205
+ * label: a bold label means `label: value` on one line, and using it here made
206
+ * the session card the only one whose block was titled a third way. The owner
207
+ * read the card and asked where its group was.
208
+ */
209
+ const quoted = (label, text) => text ? `${group(label)}\n${note(text)}` : null;
203
210
  /**
204
211
  * Склейка карточки. Пустая строка здесь — знак смены блока, а не отступ:
205
212
  * две подряд означают пустой блок, ведущая — блок, которого нет. Обе
@@ -525,7 +532,9 @@ const renderIncident = (e) => join([
525
532
  // one place it is of any use.
526
533
  const renderSession = (e) => join([
527
534
  typeLine(iconFor(e), 'Session', e.action),
528
- '',
535
+ // No blank line under the type line: a blank means a new block, and here it
536
+ // opened a block that had no heading. Facts about the session touch the
537
+ // line that names it, the way they do on every job card.
529
538
  field('Project', e.workdir),
530
539
  field('Reason', e.reason),
531
540
  e.opened ? '' : null,
@@ -0,0 +1,23 @@
1
+ /**
2
+ * One number, written the one way every card writes a number.
3
+ *
4
+ * Two report senders each grew their own dialect: one printed `485 ▲207` and
5
+ * `0 =`, the other printed `210 +3` for a real comparison and `+37` for a
6
+ * plain count of what happened today — a plus sign in front of a number that
7
+ * was never compared to anything. Inside a single group `Removed: 3` stood
8
+ * next to `Added: +6`, the same kind of fact in two shapes.
9
+ *
10
+ * So the shape is not a sender's business any more. It lives here, one
11
+ * implementation, and every report calls it:
12
+ *
13
+ * trend(210, 207) → '210 ▲3'
14
+ * trend(202, 207) → '202 ▼5'
15
+ * trend(0, 0) → '0 ='
16
+ * trend(37) → '37' nothing to compare to, so no mark
17
+ * trend(4.4, 3.6, '%') → '4.4% ▲0.8' the mark is in the unit left of it
18
+ *
19
+ * The rule the owner asked for, in one line: where there is data to compare
20
+ * against, the arrow is printed; where there is none, nothing is printed —
21
+ * never a sign that only looks like a comparison.
22
+ */
23
+ export declare const trend: (now: number, was?: number, unit?: string) => string;
package/dist/trend.js ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * One number, written the one way every card writes a number.
3
+ *
4
+ * Two report senders each grew their own dialect: one printed `485 ▲207` and
5
+ * `0 =`, the other printed `210 +3` for a real comparison and `+37` for a
6
+ * plain count of what happened today — a plus sign in front of a number that
7
+ * was never compared to anything. Inside a single group `Removed: 3` stood
8
+ * next to `Added: +6`, the same kind of fact in two shapes.
9
+ *
10
+ * So the shape is not a sender's business any more. It lives here, one
11
+ * implementation, and every report calls it:
12
+ *
13
+ * trend(210, 207) → '210 ▲3'
14
+ * trend(202, 207) → '202 ▼5'
15
+ * trend(0, 0) → '0 ='
16
+ * trend(37) → '37' nothing to compare to, so no mark
17
+ * trend(4.4, 3.6, '%') → '4.4% ▲0.8' the mark is in the unit left of it
18
+ *
19
+ * The rule the owner asked for, in one line: where there is data to compare
20
+ * against, the arrow is printed; where there is none, nothing is printed —
21
+ * never a sign that only looks like a comparison.
22
+ */
23
+ /** Integers stay integers; anything else keeps one decimal. */
24
+ const fmt = (n) => (Number.isInteger(n) ? String(n) : n.toFixed(1));
25
+ /**
26
+ * Two values that round to the same first decimal are equal: `4.42%` against
27
+ * `4.44%` is not movement, it is noise, and `▲0.0` reads as a lie.
28
+ */
29
+ const same = (a, b) => Math.abs(a - b) < 0.05;
30
+ export const trend = (now, was, unit = '') => {
31
+ const head = `${fmt(now)}${unit}`;
32
+ if (was === undefined || !Number.isFinite(was)) {
33
+ return head;
34
+ }
35
+ if (same(now, was)) {
36
+ return `${head} =`;
37
+ }
38
+ return now > was ? `${head} ▲${fmt(now - was)}` : `${head} ▼${fmt(was - now)}`;
39
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikitasazan/notify",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "Единая типизированная отправка Telegram-уведомлений (форум-темы, маршрутизация, ретраи) для всех проектов",
5
5
  "type": "module",
6
6
  "license": "MIT",