@peter.naydenov/notice 2.4.2 → 2.4.4

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.
Files changed (39) hide show
  1. package/.claude/settings.local.json +10 -0
  2. package/Changelog.md +16 -0
  3. package/coverage/lcov-report/block-navigation.js +1 -1
  4. package/coverage/lcov-report/index.html +20 -20
  5. package/coverage/lcov-report/main.js.html +171 -168
  6. package/coverage/lcov-report/sorter.js +21 -7
  7. package/coverage/lcov.info +136 -218
  8. package/graphify-out/.graphify_ast.json +1003 -0
  9. package/graphify-out/.graphify_detect.json +1 -0
  10. package/graphify-out/.graphify_python +1 -0
  11. package/graphify-out/.graphify_uncached.txt +15 -0
  12. package/graphify-out/GRAPH_REPORT.md +143 -0
  13. package/graphify-out/cache/0851b0e27934e7cb51d3d94f9e4d981e83b80e7047ebea01d717486978255d66.json +1 -0
  14. package/graphify-out/cache/313b49fbec137bd0ec64660ace8991e0ed210d1782fec8e86ca1a131901ff58d.json +1 -0
  15. package/graphify-out/cache/324c4626d3d3315ed33b0eec6c2158c55fcc53bb501ffe6a852f6e17e8164667.json +1 -0
  16. package/graphify-out/cache/3335588971cea52118dc77fccba5c33701442c573224f845a638cabe71c34240.json +1 -0
  17. package/graphify-out/cache/362bc8f53fda674a6b0ef29bda4b1be41833ddda276e0a3262ac101a5b5bba83.json +1 -0
  18. package/graphify-out/cache/3cd7d97905369ba8190edae73532006c760e252754e064ea6d9fffa261b552e6.json +1 -0
  19. package/graphify-out/cache/5d53ce3027d393c8fe8b1763ed54a0262ba10e18988e26cf273bcb179522bf4d.json +1 -0
  20. package/graphify-out/cache/68e13aab864f52d3708a714958556b7e25ff8233ab8173893de892b323e26d1a.json +1 -0
  21. package/graphify-out/cache/6f0048e5fcf58195aa0c14d4bcbcb2193f818dfe56904f151fd5cc8c406e2ffa.json +1 -0
  22. package/graphify-out/cache/8218f61ff570b6f101de672ba486677b4fb579677ce88ef537f21b9a40f9728d.json +1 -0
  23. package/graphify-out/cache/a65de5e681850c06dc779842b61d7468c9816b72a92417e3c6a8c7eaa005ecb6.json +1 -0
  24. package/graphify-out/cache/a97f881a55f97de2392f6fa86d8dd11ff9e0e0d40ec302ab9d240ec175bce333.json +1 -0
  25. package/graphify-out/cache/ab5f5634b51fc23275d76e77db87f37c1fec389b14b0228b0c8dbe70d0683c84.json +1 -0
  26. package/graphify-out/cache/ast/v0.8.39/234d10784603a5cf5a6f44fe83948a6c3a014590660e4ea32e3ef72f7b485a4b.json +1 -0
  27. package/graphify-out/cache/ast/v0.8.39/74c9623e575baefe69331b1ab4d1ad96ac2bc0f6552f04e59ff556f95a6dd2a7.json +1 -0
  28. package/graphify-out/cache/c7df89e129098aa0a6723787757bd7c58c92f7a50d365f16f92b44391a6a3256.json +1 -0
  29. package/graphify-out/cache/eda9833c7da551691f85741b4b2ac73e9eca5578b842c62002cd120c7bc70eb2.json +1 -0
  30. package/graphify-out/cache/stat-index.json +1 -0
  31. package/graphify-out/cost.json +12 -0
  32. package/graphify-out/graph.html +266 -0
  33. package/graphify-out/graph.json +2470 -0
  34. package/graphify-out/manifest.json +17 -0
  35. package/package.json +12 -27
  36. package/src/main.js +18 -15
  37. package/vitest.config.js +12 -0
  38. package/coverage/tmp/coverage-46509-1760816753149-0.json +0 -1
  39. package/coverage/tmp/coverage-46510-1760816753116-0.json +0 -1
@@ -0,0 +1,17 @@
1
+ {
2
+ "rollup.config.js": 1707045102.6095035,
3
+ "types/main.d.ts": 1775124398.1611881,
4
+ "types/src/main.d.ts": 1775124370.093825,
5
+ "test/01-notice.js": 1760816734.0085897,
6
+ "coverage/lcov-report/block-navigation.js": 1760816753.1686575,
7
+ "coverage/lcov-report/prettify.js": 1760816753.170141,
8
+ "coverage/lcov-report/sorter.js": 1760816753.1693764,
9
+ "src/main.js": 1760821018.106246,
10
+ "CODE_OF_CONDUCT.md": 1702927582.1023386,
11
+ "Changelog.md": 1775124762.301444,
12
+ "README.md": 1710493604.3297157,
13
+ "SECURITY.md": 1702927582.1027253,
14
+ "notice-desk.png": 1702927582.103096,
15
+ "coverage/lcov-report/favicon.png": 1760816753.168918,
16
+ "coverage/lcov-report/sort-arrow-sprite.png": 1760816753.1690521
17
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peter.naydenov/notice",
3
3
  "description": "Event emmiter - NOTICE",
4
- "version": "2.4.2",
4
+ "version": "2.4.4",
5
5
  "license": "MIT",
6
6
  "author": "Peter Naydenov",
7
7
  "main": "./src/main.js",
@@ -18,8 +18,8 @@
18
18
  "./src/*": "./src/*"
19
19
  },
20
20
  "scripts": {
21
- "test": "mocha test",
22
- "cover": "c8 mocha",
21
+ "test": "vitest run",
22
+ "cover": "vitest run --coverage",
23
23
  "build": "rollup -c",
24
24
  "postbuild": "tsc -p tsconfig.json"
25
25
  },
@@ -28,31 +28,13 @@
28
28
  "url": "git+https://github.com/PeterNaydenov/notice"
29
29
  },
30
30
  "devDependencies": {
31
- "@rollup/plugin-commonjs": "^29.0.2",
31
+ "@rollup/plugin-commonjs": "^29.0.3",
32
32
  "@rollup/plugin-node-resolve": "^16.0.3",
33
33
  "@rollup/plugin-terser": "^1.0.0",
34
- "c8": "^11.0.0",
35
- "chai": "6.2.2",
36
- "mocha": "11.7.5",
37
- "rollup": "^4.60.1",
38
- "typescript": "^6.0.2"
39
- },
40
- "overrides": {
41
- "diff": "^8.0.4",
42
- "serialize-javascript": "^7.0.5"
43
- },
44
- "c8": {
45
- "include": [
46
- "src/**/*.js"
47
- ],
48
- "exclude": [
49
- "node_modules",
50
- "test"
51
- ],
52
- "reporter": [
53
- "lcov",
54
- "text-summary"
55
- ]
34
+ "@vitest/coverage-v8": "^4.1.10",
35
+ "rollup": "^4.62.2",
36
+ "typescript": "^6.0.3",
37
+ "vitest": "^4.1.10"
56
38
  },
57
39
  "keywords": [
58
40
  "events",
@@ -60,5 +42,8 @@
60
42
  "publisher",
61
43
  "subscriber",
62
44
  "pubsub"
63
- ]
45
+ ],
46
+ "allowScripts": {
47
+ "fsevents@2.3.2": true
48
+ }
64
49
  }
package/src/main.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict"
2
2
  function notice () {
3
3
 
4
- let
5
- scroll = {'*':[]} // General events with their subscribers
6
- , scrollOnce = {} // Single events with their subscribers
4
+ let
5
+ scroll = Object.assign ( Object.create(null), {'*':[]} ) // General events with their subscribers. Null prototype - event names like '__proto__' are safe
6
+ , scrollOnce = Object.create ( null ) // Single events with their subscribers
7
7
  , ignore = new Set () // Ignore event names ( general and single )
8
8
  , debugFlag = false
9
9
  , debugHeader = ''
@@ -42,20 +42,21 @@ function notice () {
42
42
  if ( fx ) { // fx is optional
43
43
  if ( scroll[e] ) scroll[e] = scroll[e].filter ( fn => fn !== fx )
44
44
  if ( scrollOnce[e] ) scrollOnce[e] = scrollOnce[e].filter ( fn => fn !== fx )
45
- if ( scroll[e] && scroll[e].length === 0 ) delete scroll[e]
46
- if ( scrollOnce[e] && scrollOnce[e].length === 0 ) delete scroll[e]
45
+ if ( e !== '*' && scroll[e] && scroll[e].length === 0 ) delete scroll[e] // scroll['*'] must always exist - 'emit' relies on it
46
+ if ( scrollOnce[e] && scrollOnce[e].length === 0 ) delete scrollOnce[e]
47
47
  return
48
48
  }
49
49
  if ( scrollOnce[e] ) delete scrollOnce[e]
50
- if ( scroll[e] ) delete scroll[e]
50
+ if ( e === '*' ) scroll['*'] = [] // scroll['*'] must always exist - 'emit' relies on it
51
+ else if ( scroll[e] ) delete scroll[e]
51
52
  } // off func.
52
53
  /**
53
54
  * Resets all event-related data structures.
54
55
  * Clears all general and single event subscriptions, as well as the ignore list.
55
56
  */
56
57
  function reset () {
57
- scroll = {'*':[]}
58
- scrollOnce = {}
58
+ scroll = Object.assign ( Object.create(null), {'*':[]} )
59
+ scrollOnce = Object.create ( null )
59
60
  ignore = new Set ()
60
61
  } // reset func.
61
62
  /**
@@ -80,7 +81,7 @@ function notice () {
80
81
  function emit () {
81
82
  const [ e, ...args ] = arguments
82
83
  if ( debugFlag ) {
83
- console.log ( `${debugHeader} Event "${e}" was triggered.`)
84
+ console.log ( `${debugHeader} Event "${String(e)}" was triggered.`) // String() - event names can be Symbols
84
85
  if ( args.length > 0 ) {
85
86
  console.log ( 'Arguments:')
86
87
  console.log ( ...args )
@@ -105,14 +106,16 @@ function notice () {
105
106
  } // exeCallback func.
106
107
 
107
108
  if ( e === '*' ) { // The wildcard '*' doesn't work for 'once' events
108
- let evNames = Object.keys ( scroll )
109
+ let evNames = Reflect.ownKeys ( scroll ) // Reflect.ownKeys - event names can be Symbols
109
110
  evNames.forEach ( name => exeCallback(name) )
110
111
  return
111
112
  }
112
113
  if ( scrollOnce[e] ) {
113
114
  if ( ignore.has(e) ) return
114
- scrollOnce[e].forEach ( fn => fn(...args) )
115
- delete scrollOnce[e]
115
+ const onceFns = scrollOnce[e]
116
+ delete scrollOnce[e] // Delete before the calls, so handlers can re-register with 'once'
117
+ onceFns.forEach ( fn => fn(...args) )
118
+ if ( !scroll[e] ) scroll['*'].forEach ( fn => fn(e,...args) ) // Notify wildcard listeners; if regular subscribers exist, 'exeCallback' will do it
116
119
  }
117
120
  if ( scroll[e] ) {
118
121
  exeCallback ( e )
@@ -139,9 +142,9 @@ function notice () {
139
142
  */
140
143
  function stop ( e ) {
141
144
  if ( e === '*' ) {
142
- const
143
- evNames = Object.keys ( scroll )
144
- , evOnceNames = Object.keys ( scrollOnce )
145
+ const
146
+ evNames = Reflect.ownKeys ( scroll ) // Reflect.ownKeys - event names can be Symbols
147
+ , evOnceNames = Reflect.ownKeys ( scrollOnce )
145
148
  ;
146
149
  ignore = new Set ([ ...evOnceNames, ...evNames ])
147
150
  return
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ coverage: {
6
+ provider: 'v8',
7
+ include: ['src/**/*.js'],
8
+ exclude: ['node_modules', 'test', 'coverage'],
9
+ reporter: ['lcov', 'text-summary'],
10
+ },
11
+ },
12
+ })