@massimo-cassandro/minimo 1.7.0 → 1.7.2

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/index.js CHANGED
@@ -3,11 +3,14 @@
3
3
  export { betterText } from './src/utilities/better-text.js';
4
4
  export { classnames, classnamesNull } from './src/utilities/classnames.js';
5
5
  export { createId } from './src/utilities/create-id.js';
6
+ export { disableBtnsOnSubmit } from './src/utilities/disable-btns-on-submit.js';
6
7
  export { domBuilder } from './src/utilities/dom-builder/dom-builder.js';
7
8
  export { enableSubmitBtns } from './src/utilities/enable-submit-btns.js';
8
9
  export { escapeHTML, unescapeHTML } from './src/utilities/escape-html.js';
10
+ export { generatePwd } from './src/utilities/generate-pwd.js';
9
11
  export { getCookie, setCookie } from './src/utilities/cookies.js';
10
12
  export { linkedDates } from './src/utilities/linked-dates.js';
13
+ export { randomId } from './src/utilities/random-id.js';
11
14
  export { relativeDate } from './src/utilities/relative-date.js';
12
15
  export { sentenceCase } from './src/utilities/sentence-case.js';
13
16
  export { stripTags } from './src/utilities/strip-tags.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@massimo-cassandro/minimo",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Light css framework & utilities",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Disables all `[type=submit]` and `[type=button]` buttons on form submit.
3
+ *
4
+ * Applies to all `<form>` elements in the document except those with
5
+ * `data-disable-submit="false"`.
6
+ *
7
+ * @returns {void}
8
+ */
9
+ export function disableBtnsOnSubmit() {
10
+ document.querySelectorAll('form:not([data-disable-submit=false])').forEach( el => {
11
+ el.addEventListener('submit', () => {
12
+ /** @type {NodeListOf<HTMLButtonElement|HTMLInputElement>} */
13
+ const btns = el.querySelectorAll('[type=submit], [type=button]');
14
+ btns.forEach(btn => {
15
+ btn.disabled = true;
16
+ });
17
+ });
18
+ });
19
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Generates a random password using uppercase letters and digits,
3
+ * excluding visually ambiguous characters (O, I, 0).
4
+ *
5
+ * @param {number} [min_length=8] - Minimum password length (matches `minlength` attribute).
6
+ * @returns {string} The generated password.
7
+ */
8
+ export function generatePwd(min_length = 8) {
9
+
10
+ let chars='ABCDEFGHJKLMNPQRSTUVWXYZ123456789',
11
+ charsNum = chars.length,
12
+ min_lenght = min_length || 8,
13
+ pwd = '', i, x;
14
+
15
+ for( x = 0; x < min_lenght; x++ ) {
16
+ i = Math.floor(Math.random() * charsNum);
17
+ pwd += chars.charAt(i);
18
+ }
19
+
20
+ return pwd;
21
+
22
+ }
@@ -0,0 +1,13 @@
1
+ // @ts-check
2
+
3
+ /**
4
+ * Generates a random ID string.
5
+ * @returns {string} Base64-encoded random string
6
+ */
7
+ export function randomId() {
8
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_';
9
+ const bytes = crypto.getRandomValues(new Uint8Array(12));
10
+ return chars[bytes[0] % 52] // first item is from first 52 chars (A-Za-z)
11
+ + Array.from(bytes.slice(1), b => chars[b % 63]).join('');
12
+ }
13
+