@mikitasazan/notify 1.5.0 → 1.6.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/dist/index.d.ts +1 -0
- package/dist/index.js +7 -3
- package/dist/trend.d.ts +23 -0
- package/dist/trend.js +39 -0
- package/package.json +1 -1
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/trend.d.ts
ADDED
|
@@ -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