tool-snippets 0.0.9 → 0.0.11

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/README.md CHANGED
@@ -1,5 +1,3 @@
1
- Для WebStorm и VS Code:
2
-
3
1
  ```markdown
4
2
  # ToolSnippets
5
3
 
@@ -38,7 +36,7 @@ npm run SNIPPETS:vscode
38
36
 
39
37
  ## Использование
40
38
 
41
- В редакторе начните вводить префикс сниппета (например `tool_deb`, `tool#forEach`, `tool___subscribe`) — IntelliSense предложит подстановку.
39
+ В редакторе начните вводить префикс сниппета (например `tool-ts-debugger`, `tool-global-forEach`, `tool-ng-subscribe`) — IntelliSense предложит подстановку.
42
40
 
43
41
  ## Структура пакета
44
42
 
@@ -69,64 +67,57 @@ npm publish
69
67
 
70
68
  - Node.js (для скриптов установки)
71
69
 
72
- ### Группы:
73
-
74
- **1. Массивы / циклы**
75
- - `tool#forEach`, `tool#switch`, `tool#switch_NEVER`
76
-
77
- **2. Angular хуки**
78
- - `tool_comp_1_ngOnChanges`, `tool_comp_2_ngOnInit`, `tool_comp_3_ngAfterViewInit`, `tool_comp_4_ngOnDestroy`
79
-
80
- **3. Angular подписки / DI / ViewChild**
81
- - `tool___subscribe`, `tool___Injector`, `tool____ViewChild_Child`, `tool____ViewChild_Element`
82
-
83
- **4. Angular getter/setter**
84
- - `tool____get_set`, `tool____get_set@Input()`
85
-
86
- **5. TypeScript типы**
87
- - `tool--typePickPartialOmit`, `tool--type_keyof`, `tool--typeTNullable`, `tool--typePartial`, `tool#type_never`, `tool--Interface with readonly`
88
-
89
- **6. TypeScript const / Record**
90
- - `tool-as_const_1`, `tool-as_const_2_Record`, `tool-as_const_3_satisfies_Record`
91
-
92
- **7. try/catch**
93
- - `tool__tryCatch`, `tool__tryCatch.await`
94
-
95
- **8. Отладка**
96
- - `tool_deb`, `tool---globalErrorListeners`, `tool---Proxy_Логирование`
97
-
98
- **9. Глобальные объекты**
99
- - `tool----windowГлобальный_объект`
100
-
101
- ### Примеры сниппетов
102
-
103
- | Префикс | Описание |
104
- |---|---|
105
- | `tool#forEach` | forEach по массиву |
106
- | `tool_deb` | `debugger;` |
107
- | `tool_comp_1_ngOnChanges` | хук `ngOnChanges` |
108
- | `tool_comp_2_ngOnInit` | хук `ngOnInit` |
109
- | `tool_comp_3_ngAfterViewInit` | хук `ngAfterViewInit` |
110
- | `tool_comp_4_ngOnDestroy` | хук `ngOnDestroy` |
111
- | `tool___subscribe` | подписка на Observable с `takeUntil` |
112
- | `tool__tryCatch` | блок `try-catch-finally` |
113
- | `tool__tryCatch.await` | tryCatch для promise |
114
- | `tool-as_const_1` | объект `as const` |
115
- | `tool-as_const_2_Record` | `Record<K, V>` + `as const` |
116
- | `tool-as_const_3_satisfies_Record` | `as const satisfies Record` |
117
- | `tool--typePickPartialOmit` | `Pick & Partial<Omit>` |
118
- | `tool--type_keyof` | `keyof` |
119
- | `tool--typeTNullable` | `TNullable<T>` |
120
- | `tool--typePartial` | `Partial<T>` |
121
- | `tool--Interface with readonly` | interface с `readonly` |
122
- | `tool___Injector` | сервис через `Injector` |
123
- | `tool____ViewChild_Child` | `@ViewChild` (компонент) |
124
- | `tool____ViewChild_Element` | `@ViewChild` (ElementRef) |
125
- | `tool____get_set` | getter/setter |
126
- | `tool____get_set@Input()` | getter/setter с `@Input()` |
127
- | `tool---Proxy_Логирование` | Proxy-логирование изменений |
128
- | `tool#type_never` | `switch` + `never` (exhaustive check) |
129
- | `tool#switch` | `switch` блок |
130
- | `tool#switch_NEVER` | `switch` + `never` |
131
- | `tool----windowГлобальный_объект` | declare global window |
132
- | `tool---globalErrorListeners` | global error listeners |
70
+ ## Схема префиксов
71
+
72
+ Префикс = `tool-<группа>-<действие>`.
73
+
74
+ ### Группы
75
+
76
+ **1. `tool-hook-*` — хуки жизненного цикла Angular**
77
+ - `tool-hook-onChanges`, `tool-hook-onInit`, `tool-hook-afterViewInit`, `tool-hook-onDestroy`
78
+
79
+ **2. `tool-ng-*` — Angular (DI, подписки, ViewChild, get/set)**
80
+ - `tool-ng-subscribe`, `tool-ng-injector`, `tool-ng-viewChild`, `tool-ng-viewChildEl`, `tool-ng-getset`, `tool-ng-getset-input`
81
+
82
+ **3. `tool-type-*` — объявления типов (`type`, `interface`)**
83
+ - `tool-type-pickPartialOmit`, `tool-type-keyof`, `tool-type-nullable`, `tool-type-partial`, `tool-type-never`, `tool-type-readonly`
84
+
85
+ **4. `tool-ts-*` — значения/выражения TS (`as const`, `Record`, `satisfies`, try, отладка)**
86
+ - `tool-ts-asConst`, `tool-ts-record`, `tool-ts-recordSatisfies`, `tool-ts-try`, `tool-ts-try-await`, `tool-ts-debugger`, `tool-ts-proxy-log`
87
+
88
+ **5. `tool-global-*` — общее (массивы, ветвления, глобальные объекты, глобальные ошибки)**
89
+ - `tool-global-forEach`, `tool-global-switch`, `tool-global-switch-never`, `tool-global-window`, `tool-global-errors`
90
+
91
+ ## Примеры сниппетов
92
+
93
+ | Префикс | Описание |
94
+ |-----------------------------|---|
95
+ | `tool-hook-onChanges` | хук `ngOnChanges` |
96
+ | `tool-hook-onInit` | хук `ngOnInit` |
97
+ | `tool-hook-afterViewInit` | хук `ngAfterViewInit` |
98
+ | `tool-hook-onDestroy` | хук `ngOnDestroy` |
99
+ | `tool-ng-subscribe` | подписка на Observable с `takeUntil` |
100
+ | `tool-ng-injector` | сервис через `Injector` |
101
+ | `tool-ng-viewChild` | `@ViewChild` (компонент) |
102
+ | `tool-ng-viewChildEl` | `@ViewChild` (ElementRef) |
103
+ | `tool-ng-getset` | getter/setter |
104
+ | `tool-ng-getset-input` | getter/setter с `@Input()` |
105
+ | `tool-type-pickPartialOmit` | `Pick & Partial<Omit>` |
106
+ | `tool-type-keyof` | `keyof` |
107
+ | `tool-type-nullable` | `TNullable<T>` |
108
+ | `tool-type-partial` | `Partial<T>` |
109
+ | `tool-type-never` | `switch` + `never` (exhaustive check) |
110
+ | `tool-type-readonly` | interface с `readonly` |
111
+ | `tool-ts-asConst` | объект `as const` |
112
+ | `tool-ts-record` | `Record<K, V>` + `as const` |
113
+ | `tool-ts-recordSatisfies` | `as const satisfies Record` |
114
+ | `tool-ts-try` | блок `try-catch-finally` |
115
+ | `tool-ts-try-await` | tryCatch для promise |
116
+ | `tool-ts-proxy-log` | Proxy-логирование изменений |
117
+ | `tool-global-forEach` | forEach по массиву |
118
+ | `tool-global-switch` | `switch` блок |
119
+ | `tool-global-switch-never` | `switch` + `never` |
120
+ | `tool-global-window` | declare global window |
121
+ | `tool-global-errors` | global error listeners |
122
+ | `tool-global-debugger` | `debugger;` |
123
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tool-snippets",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "peerDependencies": {},
5
5
  "dependencies": {
6
6
  "tslib": "^2.3.0"
@@ -291,12 +291,6 @@
291
291
  "description": "tryCatch для promise",
292
292
  "scope": "javascript,typescript"
293
293
  },
294
- "tool-ts-debugger": {
295
- "prefix": "tool-ts-debugger",
296
- "body": ["debugger;"],
297
- "description": "debugger",
298
- "scope": "javascript,typescript"
299
- },
300
294
  "tool-ts-proxy-log": {
301
295
  "prefix": "tool-ts-proxy-log",
302
296
  "body": [
@@ -431,5 +425,11 @@
431
425
  ],
432
426
  "description": "Debug: global error & promise rejection listeners",
433
427
  "scope": "javascript,typescript"
428
+ },
429
+ "tool-global-debugger": {
430
+ "prefix": "tool-global-debugger",
431
+ "body": ["debugger;"],
432
+ "description": "debugger",
433
+ "scope": "javascript,typescript"
434
434
  }
435
435
  }
@@ -153,12 +153,6 @@
153
153
  <option name="TypeScript" value="true" />
154
154
  </context>
155
155
  </template>
156
- <template name="tool-ts-debugger" value="debugger;" description="debugger" toReformat="true" toShortenFQNames="true">
157
- <context>
158
- <option name="JAVA_SCRIPT" value="true" />
159
- <option name="TypeScript" value="true" />
160
- </context>
161
- </template>
162
156
  <template name="tool-ts-proxy-log" value="public createProxyLog(target, onChange) {&#10; // Обработка null и примитивов&#10; if (target === null || typeof target !== 'object') {&#10; return target;&#10; }&#10; &#10; return new Proxy(target, {&#10; set(obj, prop, value) {&#10; const oldValue = obj[prop];&#10; &#10; // Рекурсивно обрабатываем новые объекты&#10; const newValue = this.createProxyLog(value, onChange);&#10; &#10; obj[prop] = newValue;&#10; &#10; // Проверяем реальное изменение (учитываем NaN)&#10; if (oldValue !== value &amp;&amp; !(Number.isNaN(oldValue) &amp;&amp; Number.isNaN(value))) {&#10; onChange(prop, newValue, oldValue);&#10; }&#10; &#10; return true;&#10; },&#10; &#10; get(obj, prop) {&#10; const value = obj[prop];&#10; &#10; // Рекурсивно создаем прокси для вложенных объектов&#10; if (value !== null &amp;&amp; typeof value === 'object') {&#10; return this.createProxyLog(value, onChange);&#10; }&#10; &#10; return value;&#10; },&#10; &#10; deleteProperty(obj, prop) {&#10; const oldValue = obj[prop];&#10; const deleted = delete obj[prop];&#10; &#10; if (deleted) { onChange(prop, undefined, oldValue); }&#10; &#10; return deleted;&#10; }&#10; });&#10;}&#10;&#10;&#10;// Использование:&#10;//let state = this.createProxyLog(&#10;//{ user: { name: 'Alice', age: 30 } settings: { theme: 'dark', notifications: true } }, &#10;//(prop, value, oldValue) =&gt; { console.log(`Property &quot;${prop}&quot; changed: ${oldValue} → ${value}`); });&#10;//&#10;// delete state.user.email; // Property &quot;email&quot; changed: alice@example.com → undefined" description="Функция создания Proxy Логирование" toReformat="false" toShortenFQNames="true">
163
157
  <context>
164
158
  <option name="JAVA_SCRIPT" value="true" />
@@ -208,4 +202,10 @@
208
202
  <option name="TypeScript" value="true" />
209
203
  </context>
210
204
  </template>
205
+ <template name="tool-global-debugger" value="debugger;" description="debugger" toReformat="true" toShortenFQNames="true">
206
+ <context>
207
+ <option name="JAVA_SCRIPT" value="true" />
208
+ <option name="TypeScript" value="true" />
209
+ </context>
210
+ </template>
211
211
  </templateSet>