@nirsgv/a-lert 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Nir Segev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # @nirsgv/a-lert
2
+
3
+ Tiny helper that lets you call `alert` with `a('message')`. Falls back to `console.log` when `alert` is not available (for example in Node during server-side rendering).
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @nirsgv/a-lert
9
+ # or
10
+ yarn add @nirsgv/a-lert
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ESM:
16
+
17
+ ```js
18
+ import a from '@nirsgv/a-lert';
19
+ // or: import { a } from '@nirsgv/a-lert';
20
+
21
+ a('Hello, world!');
22
+ ```
23
+
24
+ CommonJS:
25
+
26
+ ```js
27
+ const a = require('@nirsgv/a-lert');
28
+ // or: const { a } = require('@nirsgv/a-lert');
29
+
30
+ a('Hello, world!');
31
+ ```
32
+
33
+ ## Notes
34
+
35
+ - Works in browsers where `alert` is present.
36
+ - In environments without `alert`, it safely logs the message to the console instead.
package/index.cjs ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Show a message via alert and fall back to console.log when alert is unavailable.
3
+ * @param {unknown} message
4
+ */
5
+ function a(message) {
6
+ const text = typeof message === 'undefined' ? '' : String(message);
7
+
8
+ const maybeGlobal = typeof globalThis !== 'undefined' ? globalThis : undefined;
9
+ const maybeWindow = typeof window !== 'undefined' ? window : undefined;
10
+ const maybeAlert = maybeGlobal && typeof maybeGlobal.alert === 'function'
11
+ ? maybeGlobal.alert
12
+ : maybeWindow && typeof maybeWindow.alert === 'function'
13
+ ? maybeWindow.alert
14
+ : undefined;
15
+
16
+ if (typeof maybeAlert === 'function') {
17
+ maybeAlert(text);
18
+ return;
19
+ }
20
+
21
+ if (typeof console !== 'undefined' && typeof console.log === 'function') {
22
+ console.log(text);
23
+ }
24
+ }
25
+
26
+ module.exports = a;
27
+ module.exports.a = a;
28
+ module.exports.default = a;
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare function a(message: unknown): void;
2
+
3
+ export { a };
4
+ export default a;
package/index.js ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Show a message via alert and fall back to console.log when alert is unavailable.
3
+ * @param {unknown} message
4
+ */
5
+ export function a(message) {
6
+ const text = typeof message === 'undefined' ? '' : String(message);
7
+
8
+ const maybeGlobal = typeof globalThis !== 'undefined' ? globalThis : undefined;
9
+ const maybeWindow = typeof window !== 'undefined' ? window : undefined;
10
+ const maybeAlert = maybeGlobal && typeof maybeGlobal.alert === 'function'
11
+ ? maybeGlobal.alert
12
+ : maybeWindow && typeof maybeWindow.alert === 'function'
13
+ ? maybeWindow.alert
14
+ : undefined;
15
+
16
+ if (typeof maybeAlert === 'function') {
17
+ maybeAlert(text);
18
+ return;
19
+ }
20
+
21
+ if (typeof console !== 'undefined' && typeof console.log === 'function') {
22
+ console.log(text);
23
+ }
24
+ }
25
+
26
+ export default a;
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@nirsgv/a-lert",
3
+ "version": "1.0.0",
4
+ "description": "Call alert via a('message') with a tiny helper.",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "types": "index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./index.js",
11
+ "require": "./index.cjs",
12
+ "types": "./index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "index.js",
17
+ "index.cjs",
18
+ "index.d.ts",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "keywords": [
26
+ "alert",
27
+ "browser",
28
+ "helper",
29
+ "tiny"
30
+ ],
31
+ "author": "Nir Segev",
32
+ "license": "MIT",
33
+ "sideEffects": false,
34
+ "engines": {
35
+ "node": ">=14"
36
+ }
37
+ }