tiny-essentials 1.21.9 β 1.21.10
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/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/libs/TinyHtml.cjs +71 -42
- package/dist/v1/libs/TinyHtml.d.mts +30 -30
- package/dist/v1/libs/TinyHtml.mjs +71 -47
- package/docs/v1/README.md +8 -0
- package/docs/v1/Regex-Helpers.md +72 -0
- package/docs/v1/libs/TinyHtml.md +6 -5
- package/package.json +1 -1
|
@@ -5182,28 +5182,46 @@ class TinyHtml {
|
|
|
5182
5182
|
}
|
|
5183
5183
|
|
|
5184
5184
|
/**
|
|
5185
|
-
* Set
|
|
5185
|
+
* Set one or multiple attributes on an element.
|
|
5186
5186
|
* @template {TinyElement|TinyElement[]} T
|
|
5187
|
-
* @param {T} el
|
|
5188
|
-
* @param {string} name
|
|
5189
|
-
* @param {string|null} [value=null]
|
|
5187
|
+
* @param {T} el - Target element(s).
|
|
5188
|
+
* @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
|
|
5189
|
+
* @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
|
|
5190
5190
|
* @returns {T}
|
|
5191
5191
|
*/
|
|
5192
5192
|
static setAttr(el, name, value = null) {
|
|
5193
|
+
const elems = TinyHtml._preElems(el, 'setAttr');
|
|
5194
|
+
|
|
5195
|
+
// Multiple attributes at once
|
|
5196
|
+
if (typeof name === 'object' && name !== null) {
|
|
5197
|
+
Object.entries(name).forEach(([attr, val]) => {
|
|
5198
|
+
if (val !== null && typeof val !== 'string')
|
|
5199
|
+
throw new TypeError(`The value for "${attr}" must be a string or null.`);
|
|
5200
|
+
elems.forEach((elem) => {
|
|
5201
|
+
if (val === null) elem.removeAttribute(TinyHtml.getAttrName(attr));
|
|
5202
|
+
else elem.setAttribute(TinyHtml.getAttrName(attr), val);
|
|
5203
|
+
});
|
|
5204
|
+
});
|
|
5205
|
+
return el;
|
|
5206
|
+
}
|
|
5207
|
+
|
|
5208
|
+
// Single attribute
|
|
5193
5209
|
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
5194
5210
|
if (value !== null && typeof value !== 'string')
|
|
5195
5211
|
throw new TypeError('The "value" must be a string.');
|
|
5196
|
-
|
|
5212
|
+
|
|
5213
|
+
elems.forEach((elem) => {
|
|
5197
5214
|
if (value === null) elem.removeAttribute(TinyHtml.getAttrName(name));
|
|
5198
5215
|
else elem.setAttribute(TinyHtml.getAttrName(name), value);
|
|
5199
5216
|
});
|
|
5217
|
+
|
|
5200
5218
|
return el;
|
|
5201
5219
|
}
|
|
5202
5220
|
|
|
5203
5221
|
/**
|
|
5204
|
-
* Set
|
|
5205
|
-
* @param {string} name
|
|
5206
|
-
* @param {string|null} [value=null]
|
|
5222
|
+
* Set one or multiple attributes on an element.
|
|
5223
|
+
* @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
|
|
5224
|
+
* @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
|
|
5207
5225
|
* @returns {this}
|
|
5208
5226
|
*/
|
|
5209
5227
|
setAttr(name, value) {
|
|
@@ -5278,81 +5296,92 @@ class TinyHtml {
|
|
|
5278
5296
|
}
|
|
5279
5297
|
|
|
5280
5298
|
/**
|
|
5281
|
-
* Set
|
|
5299
|
+
* Set one or multiple properties on an element.
|
|
5282
5300
|
* @template {TinyElement|TinyElement[]} T
|
|
5283
|
-
* @param {T} el
|
|
5284
|
-
* @param {string} name
|
|
5301
|
+
* @param {T} el - Target element(s).
|
|
5302
|
+
* @param {...string} names - Property name(s).
|
|
5285
5303
|
* @returns {T}
|
|
5286
5304
|
*/
|
|
5287
|
-
static addProp(el,
|
|
5288
|
-
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
5305
|
+
static addProp(el, ...names) {
|
|
5289
5306
|
TinyHtml._preElems(el, 'addProp').forEach((elem) => {
|
|
5290
|
-
|
|
5291
|
-
|
|
5307
|
+
names.forEach((name) => {
|
|
5308
|
+
if (typeof name !== 'string') throw new TypeError('Each "name" must be a string.');
|
|
5309
|
+
// @ts-ignore
|
|
5310
|
+
elem[TinyHtml.getPropName(name)] = true;
|
|
5311
|
+
});
|
|
5292
5312
|
});
|
|
5293
5313
|
return el;
|
|
5294
5314
|
}
|
|
5295
5315
|
|
|
5296
5316
|
/**
|
|
5297
5317
|
* Set a property on an element.
|
|
5298
|
-
* @param {string} name
|
|
5318
|
+
* @param {...string} names - Property name(s).
|
|
5299
5319
|
* @returns {this}
|
|
5300
5320
|
*/
|
|
5301
|
-
addProp(
|
|
5302
|
-
return TinyHtml.addProp(this,
|
|
5321
|
+
addProp(...names) {
|
|
5322
|
+
return TinyHtml.addProp(this, ...names);
|
|
5303
5323
|
}
|
|
5304
5324
|
|
|
5305
5325
|
/**
|
|
5306
|
-
* Remove
|
|
5326
|
+
* Remove one or multiple properties from an element.
|
|
5307
5327
|
* @template {TinyElement|TinyElement[]} T
|
|
5308
|
-
* @param {T} el
|
|
5309
|
-
* @param {string} name
|
|
5328
|
+
* @param {T} el - Target element(s).
|
|
5329
|
+
* @param {...string} names - Property name(s).
|
|
5310
5330
|
* @returns {T}
|
|
5311
5331
|
*/
|
|
5312
|
-
static removeProp(el,
|
|
5313
|
-
if (typeof name !== 'string') throw new TypeError('The "name" must be a string.');
|
|
5332
|
+
static removeProp(el, ...names) {
|
|
5314
5333
|
TinyHtml._preElems(el, 'removeProp').forEach((elem) => {
|
|
5315
|
-
|
|
5316
|
-
|
|
5334
|
+
names.forEach((name) => {
|
|
5335
|
+
if (typeof name !== 'string') throw new TypeError('Each "name" must be a string.');
|
|
5336
|
+
// @ts-ignore
|
|
5337
|
+
elem[TinyHtml.getPropName(name)] = false;
|
|
5338
|
+
});
|
|
5317
5339
|
});
|
|
5318
5340
|
return el;
|
|
5319
5341
|
}
|
|
5320
5342
|
|
|
5321
5343
|
/**
|
|
5322
5344
|
* Remove a property from an element.
|
|
5323
|
-
* @param {string} name
|
|
5345
|
+
* @param {...string} names - Property name(s).
|
|
5324
5346
|
* @returns {this}
|
|
5325
5347
|
*/
|
|
5326
|
-
removeProp(
|
|
5327
|
-
return TinyHtml.removeProp(this,
|
|
5348
|
+
removeProp(...names) {
|
|
5349
|
+
return TinyHtml.removeProp(this, ...names);
|
|
5328
5350
|
}
|
|
5329
5351
|
|
|
5330
5352
|
/**
|
|
5331
|
-
* Toggle
|
|
5353
|
+
* Toggle one or multiple boolean properties.
|
|
5332
5354
|
* @template {TinyElement|TinyElement[]} T
|
|
5333
|
-
* @param {T} el
|
|
5334
|
-
* @param {string} name
|
|
5335
|
-
* @param {boolean} [force]
|
|
5355
|
+
* @param {T} el - Target element(s).
|
|
5356
|
+
* @param {string|string[]} name - Property name or a list of property names.
|
|
5357
|
+
* @param {boolean} [force] - Force true/false instead of toggling.
|
|
5336
5358
|
* @returns {T}
|
|
5337
5359
|
*/
|
|
5338
5360
|
static toggleProp(el, name, force) {
|
|
5339
|
-
|
|
5361
|
+
const elems = TinyHtml._preElems(el, 'toggleProp');
|
|
5340
5362
|
if (typeof force !== 'undefined' && typeof force !== 'boolean')
|
|
5341
5363
|
throw new TypeError('The "force" must be a boolean.');
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5347
|
-
|
|
5364
|
+
|
|
5365
|
+
// Normalize list of properties
|
|
5366
|
+
const props = Array.isArray(name) ? name : [name];
|
|
5367
|
+
|
|
5368
|
+
props.forEach((prop) => {
|
|
5369
|
+
if (typeof prop !== 'string') throw new TypeError('Each property name must be a string.');
|
|
5370
|
+
elems.forEach((elem) => {
|
|
5371
|
+
// @ts-ignore
|
|
5372
|
+
const shouldEnable = force === undefined ? !elem[TinyHtml.getPropName(prop)] : force;
|
|
5373
|
+
if (shouldEnable) TinyHtml.addProp(elem, prop);
|
|
5374
|
+
else TinyHtml.removeProp(elem, prop);
|
|
5375
|
+
});
|
|
5348
5376
|
});
|
|
5377
|
+
|
|
5349
5378
|
return el;
|
|
5350
5379
|
}
|
|
5351
5380
|
|
|
5352
5381
|
/**
|
|
5353
|
-
* Toggle
|
|
5354
|
-
* @param {string} name
|
|
5355
|
-
* @param {boolean} [force]
|
|
5382
|
+
* Toggle one or multiple boolean properties.
|
|
5383
|
+
* @param {string|string[]} name - Property name or a list of property names.
|
|
5384
|
+
* @param {boolean} [force] - Force true/false instead of toggling.
|
|
5356
5385
|
* @returns {this}
|
|
5357
5386
|
*/
|
|
5358
5387
|
toggleProp(name, force) {
|
|
@@ -1911,14 +1911,14 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
1911
1911
|
*/
|
|
1912
1912
|
static attr(el: TinyElement, name: string): string | null;
|
|
1913
1913
|
/**
|
|
1914
|
-
* Set
|
|
1914
|
+
* Set one or multiple attributes on an element.
|
|
1915
1915
|
* @template {TinyElement|TinyElement[]} T
|
|
1916
|
-
* @param {T} el
|
|
1917
|
-
* @param {string} name
|
|
1918
|
-
* @param {string|null} [value=null]
|
|
1916
|
+
* @param {T} el - Target element(s).
|
|
1917
|
+
* @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
|
|
1918
|
+
* @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
|
|
1919
1919
|
* @returns {T}
|
|
1920
1920
|
*/
|
|
1921
|
-
static setAttr<T extends TinyElement | TinyElement[]>(el: T, name: string, value?: string | null): T;
|
|
1921
|
+
static setAttr<T extends TinyElement | TinyElement[]>(el: T, name: string | Record<string, string | null>, value?: string | null): T;
|
|
1922
1922
|
/**
|
|
1923
1923
|
* Remove attribute(s) from an element.
|
|
1924
1924
|
* @template {TinyElement|TinyElement[]} T
|
|
@@ -1942,30 +1942,30 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
1942
1942
|
*/
|
|
1943
1943
|
static hasProp(el: TinyElement, name: string): boolean;
|
|
1944
1944
|
/**
|
|
1945
|
-
* Set
|
|
1945
|
+
* Set one or multiple properties on an element.
|
|
1946
1946
|
* @template {TinyElement|TinyElement[]} T
|
|
1947
|
-
* @param {T} el
|
|
1948
|
-
* @param {string} name
|
|
1947
|
+
* @param {T} el - Target element(s).
|
|
1948
|
+
* @param {...string} names - Property name(s).
|
|
1949
1949
|
* @returns {T}
|
|
1950
1950
|
*/
|
|
1951
|
-
static addProp<T extends TinyElement | TinyElement[]>(el: T,
|
|
1951
|
+
static addProp<T extends TinyElement | TinyElement[]>(el: T, ...names: string[]): T;
|
|
1952
1952
|
/**
|
|
1953
|
-
* Remove
|
|
1953
|
+
* Remove one or multiple properties from an element.
|
|
1954
1954
|
* @template {TinyElement|TinyElement[]} T
|
|
1955
|
-
* @param {T} el
|
|
1956
|
-
* @param {string} name
|
|
1955
|
+
* @param {T} el - Target element(s).
|
|
1956
|
+
* @param {...string} names - Property name(s).
|
|
1957
1957
|
* @returns {T}
|
|
1958
1958
|
*/
|
|
1959
|
-
static removeProp<T extends TinyElement | TinyElement[]>(el: T,
|
|
1959
|
+
static removeProp<T extends TinyElement | TinyElement[]>(el: T, ...names: string[]): T;
|
|
1960
1960
|
/**
|
|
1961
|
-
* Toggle
|
|
1961
|
+
* Toggle one or multiple boolean properties.
|
|
1962
1962
|
* @template {TinyElement|TinyElement[]} T
|
|
1963
|
-
* @param {T} el
|
|
1964
|
-
* @param {string} name
|
|
1965
|
-
* @param {boolean} [force]
|
|
1963
|
+
* @param {T} el - Target element(s).
|
|
1964
|
+
* @param {string|string[]} name - Property name or a list of property names.
|
|
1965
|
+
* @param {boolean} [force] - Force true/false instead of toggling.
|
|
1966
1966
|
* @returns {T}
|
|
1967
1967
|
*/
|
|
1968
|
-
static toggleProp<T extends TinyElement | TinyElement[]>(el: T, name: string, force?: boolean): T;
|
|
1968
|
+
static toggleProp<T extends TinyElement | TinyElement[]>(el: T, name: string | string[], force?: boolean): T;
|
|
1969
1969
|
/**
|
|
1970
1970
|
* Removes an element from the DOM.
|
|
1971
1971
|
* @template {TinyElement|TinyElement[]} T
|
|
@@ -2986,12 +2986,12 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
2986
2986
|
*/
|
|
2987
2987
|
attr(name: string): string | null;
|
|
2988
2988
|
/**
|
|
2989
|
-
* Set
|
|
2990
|
-
* @param {string} name
|
|
2991
|
-
* @param {string|null} [value=null]
|
|
2989
|
+
* Set one or multiple attributes on an element.
|
|
2990
|
+
* @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
|
|
2991
|
+
* @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
|
|
2992
2992
|
* @returns {this}
|
|
2993
2993
|
*/
|
|
2994
|
-
setAttr(name: string, value?: string | null): this;
|
|
2994
|
+
setAttr(name: string | Record<string, string | null>, value?: string | null): this;
|
|
2995
2995
|
/**
|
|
2996
2996
|
* Remove attribute(s) from an element.
|
|
2997
2997
|
* @param {string} name Space-separated list of attributes.
|
|
@@ -3012,23 +3012,23 @@ declare class TinyHtml<TinyHtmlT extends ConstructorElValues | ConstructorElValu
|
|
|
3012
3012
|
hasProp(name: string): boolean;
|
|
3013
3013
|
/**
|
|
3014
3014
|
* Set a property on an element.
|
|
3015
|
-
* @param {string} name
|
|
3015
|
+
* @param {...string} names - Property name(s).
|
|
3016
3016
|
* @returns {this}
|
|
3017
3017
|
*/
|
|
3018
|
-
addProp(
|
|
3018
|
+
addProp(...names: string[]): this;
|
|
3019
3019
|
/**
|
|
3020
3020
|
* Remove a property from an element.
|
|
3021
|
-
* @param {string} name
|
|
3021
|
+
* @param {...string} names - Property name(s).
|
|
3022
3022
|
* @returns {this}
|
|
3023
3023
|
*/
|
|
3024
|
-
removeProp(
|
|
3024
|
+
removeProp(...names: string[]): this;
|
|
3025
3025
|
/**
|
|
3026
|
-
* Toggle
|
|
3027
|
-
* @param {string} name
|
|
3028
|
-
* @param {boolean} [force]
|
|
3026
|
+
* Toggle one or multiple boolean properties.
|
|
3027
|
+
* @param {string|string[]} name - Property name or a list of property names.
|
|
3028
|
+
* @param {boolean} [force] - Force true/false instead of toggling.
|
|
3029
3029
|
* @returns {this}
|
|
3030
3030
|
*/
|
|
3031
|
-
toggleProp(name: string, force?: boolean): this;
|
|
3031
|
+
toggleProp(name: string | string[], force?: boolean): this;
|
|
3032
3032
|
/**
|
|
3033
3033
|
* Removes the element from the DOM.
|
|
3034
3034
|
* @returns {this}
|
|
@@ -4688,19 +4688,35 @@ class TinyHtml {
|
|
|
4688
4688
|
return TinyHtml.attr(this, name);
|
|
4689
4689
|
}
|
|
4690
4690
|
/**
|
|
4691
|
-
* Set
|
|
4691
|
+
* Set one or multiple attributes on an element.
|
|
4692
4692
|
* @template {TinyElement|TinyElement[]} T
|
|
4693
|
-
* @param {T} el
|
|
4694
|
-
* @param {string} name
|
|
4695
|
-
* @param {string|null} [value=null]
|
|
4693
|
+
* @param {T} el - Target element(s).
|
|
4694
|
+
* @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
|
|
4695
|
+
* @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
|
|
4696
4696
|
* @returns {T}
|
|
4697
4697
|
*/
|
|
4698
4698
|
static setAttr(el, name, value = null) {
|
|
4699
|
+
const elems = TinyHtml._preElems(el, 'setAttr');
|
|
4700
|
+
// Multiple attributes at once
|
|
4701
|
+
if (typeof name === 'object' && name !== null) {
|
|
4702
|
+
Object.entries(name).forEach(([attr, val]) => {
|
|
4703
|
+
if (val !== null && typeof val !== 'string')
|
|
4704
|
+
throw new TypeError(`The value for "${attr}" must be a string or null.`);
|
|
4705
|
+
elems.forEach((elem) => {
|
|
4706
|
+
if (val === null)
|
|
4707
|
+
elem.removeAttribute(TinyHtml.getAttrName(attr));
|
|
4708
|
+
else
|
|
4709
|
+
elem.setAttribute(TinyHtml.getAttrName(attr), val);
|
|
4710
|
+
});
|
|
4711
|
+
});
|
|
4712
|
+
return el;
|
|
4713
|
+
}
|
|
4714
|
+
// Single attribute
|
|
4699
4715
|
if (typeof name !== 'string')
|
|
4700
4716
|
throw new TypeError('The "name" must be a string.');
|
|
4701
4717
|
if (value !== null && typeof value !== 'string')
|
|
4702
4718
|
throw new TypeError('The "value" must be a string.');
|
|
4703
|
-
|
|
4719
|
+
elems.forEach((elem) => {
|
|
4704
4720
|
if (value === null)
|
|
4705
4721
|
elem.removeAttribute(TinyHtml.getAttrName(name));
|
|
4706
4722
|
else
|
|
@@ -4709,9 +4725,9 @@ class TinyHtml {
|
|
|
4709
4725
|
return el;
|
|
4710
4726
|
}
|
|
4711
4727
|
/**
|
|
4712
|
-
* Set
|
|
4713
|
-
* @param {string} name
|
|
4714
|
-
* @param {string|null} [value=null]
|
|
4728
|
+
* Set one or multiple attributes on an element.
|
|
4729
|
+
* @param {string|Record<string, string|null>} name - Attribute name or an object of attributes.
|
|
4730
|
+
* @param {string|null} [value=null] - Attribute value (ignored if "name" is an object).
|
|
4715
4731
|
* @returns {this}
|
|
4716
4732
|
*/
|
|
4717
4733
|
setAttr(name, value) {
|
|
@@ -4780,81 +4796,89 @@ class TinyHtml {
|
|
|
4780
4796
|
return TinyHtml.hasProp(this, name);
|
|
4781
4797
|
}
|
|
4782
4798
|
/**
|
|
4783
|
-
* Set
|
|
4799
|
+
* Set one or multiple properties on an element.
|
|
4784
4800
|
* @template {TinyElement|TinyElement[]} T
|
|
4785
|
-
* @param {T} el
|
|
4786
|
-
* @param {string} name
|
|
4801
|
+
* @param {T} el - Target element(s).
|
|
4802
|
+
* @param {...string} names - Property name(s).
|
|
4787
4803
|
* @returns {T}
|
|
4788
4804
|
*/
|
|
4789
|
-
static addProp(el,
|
|
4790
|
-
if (typeof name !== 'string')
|
|
4791
|
-
throw new TypeError('The "name" must be a string.');
|
|
4805
|
+
static addProp(el, ...names) {
|
|
4792
4806
|
TinyHtml._preElems(el, 'addProp').forEach((elem) => {
|
|
4793
|
-
|
|
4794
|
-
|
|
4807
|
+
names.forEach((name) => {
|
|
4808
|
+
if (typeof name !== 'string')
|
|
4809
|
+
throw new TypeError('Each "name" must be a string.');
|
|
4810
|
+
// @ts-ignore
|
|
4811
|
+
elem[TinyHtml.getPropName(name)] = true;
|
|
4812
|
+
});
|
|
4795
4813
|
});
|
|
4796
4814
|
return el;
|
|
4797
4815
|
}
|
|
4798
4816
|
/**
|
|
4799
4817
|
* Set a property on an element.
|
|
4800
|
-
* @param {string} name
|
|
4818
|
+
* @param {...string} names - Property name(s).
|
|
4801
4819
|
* @returns {this}
|
|
4802
4820
|
*/
|
|
4803
|
-
addProp(
|
|
4804
|
-
return TinyHtml.addProp(this,
|
|
4821
|
+
addProp(...names) {
|
|
4822
|
+
return TinyHtml.addProp(this, ...names);
|
|
4805
4823
|
}
|
|
4806
4824
|
/**
|
|
4807
|
-
* Remove
|
|
4825
|
+
* Remove one or multiple properties from an element.
|
|
4808
4826
|
* @template {TinyElement|TinyElement[]} T
|
|
4809
|
-
* @param {T} el
|
|
4810
|
-
* @param {string} name
|
|
4827
|
+
* @param {T} el - Target element(s).
|
|
4828
|
+
* @param {...string} names - Property name(s).
|
|
4811
4829
|
* @returns {T}
|
|
4812
4830
|
*/
|
|
4813
|
-
static removeProp(el,
|
|
4814
|
-
if (typeof name !== 'string')
|
|
4815
|
-
throw new TypeError('The "name" must be a string.');
|
|
4831
|
+
static removeProp(el, ...names) {
|
|
4816
4832
|
TinyHtml._preElems(el, 'removeProp').forEach((elem) => {
|
|
4817
|
-
|
|
4818
|
-
|
|
4833
|
+
names.forEach((name) => {
|
|
4834
|
+
if (typeof name !== 'string')
|
|
4835
|
+
throw new TypeError('Each "name" must be a string.');
|
|
4836
|
+
// @ts-ignore
|
|
4837
|
+
elem[TinyHtml.getPropName(name)] = false;
|
|
4838
|
+
});
|
|
4819
4839
|
});
|
|
4820
4840
|
return el;
|
|
4821
4841
|
}
|
|
4822
4842
|
/**
|
|
4823
4843
|
* Remove a property from an element.
|
|
4824
|
-
* @param {string} name
|
|
4844
|
+
* @param {...string} names - Property name(s).
|
|
4825
4845
|
* @returns {this}
|
|
4826
4846
|
*/
|
|
4827
|
-
removeProp(
|
|
4828
|
-
return TinyHtml.removeProp(this,
|
|
4847
|
+
removeProp(...names) {
|
|
4848
|
+
return TinyHtml.removeProp(this, ...names);
|
|
4829
4849
|
}
|
|
4830
4850
|
/**
|
|
4831
|
-
* Toggle
|
|
4851
|
+
* Toggle one or multiple boolean properties.
|
|
4832
4852
|
* @template {TinyElement|TinyElement[]} T
|
|
4833
|
-
* @param {T} el
|
|
4834
|
-
* @param {string} name
|
|
4835
|
-
* @param {boolean} [force]
|
|
4853
|
+
* @param {T} el - Target element(s).
|
|
4854
|
+
* @param {string|string[]} name - Property name or a list of property names.
|
|
4855
|
+
* @param {boolean} [force] - Force true/false instead of toggling.
|
|
4836
4856
|
* @returns {T}
|
|
4837
4857
|
*/
|
|
4838
4858
|
static toggleProp(el, name, force) {
|
|
4839
|
-
|
|
4840
|
-
throw new TypeError('The "name" must be a string.');
|
|
4859
|
+
const elems = TinyHtml._preElems(el, 'toggleProp');
|
|
4841
4860
|
if (typeof force !== 'undefined' && typeof force !== 'boolean')
|
|
4842
4861
|
throw new TypeError('The "force" must be a boolean.');
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
TinyHtml.
|
|
4862
|
+
// Normalize list of properties
|
|
4863
|
+
const props = Array.isArray(name) ? name : [name];
|
|
4864
|
+
props.forEach((prop) => {
|
|
4865
|
+
if (typeof prop !== 'string')
|
|
4866
|
+
throw new TypeError('Each property name must be a string.');
|
|
4867
|
+
elems.forEach((elem) => {
|
|
4868
|
+
// @ts-ignore
|
|
4869
|
+
const shouldEnable = force === undefined ? !elem[TinyHtml.getPropName(prop)] : force;
|
|
4870
|
+
if (shouldEnable)
|
|
4871
|
+
TinyHtml.addProp(elem, prop);
|
|
4872
|
+
else
|
|
4873
|
+
TinyHtml.removeProp(elem, prop);
|
|
4874
|
+
});
|
|
4851
4875
|
});
|
|
4852
4876
|
return el;
|
|
4853
4877
|
}
|
|
4854
4878
|
/**
|
|
4855
|
-
* Toggle
|
|
4856
|
-
* @param {string} name
|
|
4857
|
-
* @param {boolean} [force]
|
|
4879
|
+
* Toggle one or multiple boolean properties.
|
|
4880
|
+
* @param {string|string[]} name - Property name or a list of property names.
|
|
4881
|
+
* @param {boolean} [force] - Force true/false instead of toggling.
|
|
4858
4882
|
* @returns {this}
|
|
4859
4883
|
*/
|
|
4860
4884
|
toggleProp(name, force) {
|
package/docs/v1/README.md
CHANGED
|
@@ -69,6 +69,14 @@ To get started, navigate to the appropriate directory and explore the files list
|
|
|
69
69
|
|
|
70
70
|
---
|
|
71
71
|
|
|
72
|
+
## π More Regex Goodies
|
|
73
|
+
|
|
74
|
+
Looking for practical regex examples and migration helpers?
|
|
75
|
+
|
|
76
|
+
π Check out the **[`Regex-Helpers`](Regex-Helpers.md)** file for a full collection of ready-to-use regex transformations!
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
72
80
|
## π Contributing
|
|
73
81
|
|
|
74
82
|
Feel free to suggest changes, improvements, or additional features. You can fork the repository and submit a pull request!
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# π Regex Helpers
|
|
2
|
+
|
|
3
|
+
Welcome to the **Regex Helpers** guide! β¨
|
|
4
|
+
This document provides a collection of **ready-to-use regex patterns** to help you **transform JavaScript code** more efficiently.
|
|
5
|
+
Itβs especially useful when **migrating from jQuery to TinyHtml**, making your workflow faster, cleaner, and less error-prone. π
|
|
6
|
+
|
|
7
|
+
π These helpers were tested only in **Visual Studio Code**, so results may vary in other editors.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## β‘ Basic Function Replacements
|
|
12
|
+
|
|
13
|
+
Simplify and streamline JavaScript function transformations.
|
|
14
|
+
|
|
15
|
+
**π Replace `attr`:**
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
attr\(([^,]+),\s*([^)]+)\)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
β‘οΈ with `setAttr`:
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
setAttr($1, $2)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## π οΈ Migrating from jQuery to TinyHtml
|
|
30
|
+
|
|
31
|
+
### π₯ Match jQuery with arguments
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
\$\(\s*['"]<([^'"]+)>['"]\s*,\s*([\s\S]*?)\)
|
|
35
|
+
\$\((?:\s|\n)*['"]<([^'"]+)>['"](?:\s|\n)*,(?:\s|\n)*([\s\S]*?)(?:\s|\n)*\)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
β‘οΈ Replace with:
|
|
39
|
+
|
|
40
|
+
```ruby
|
|
41
|
+
TinyHtml.createFrom('$1', $2)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
### π¦ Match jQuery without arguments
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
\$\(\s*['"]<([^'"]+)>['"]\s*\)
|
|
50
|
+
\$\((?:\s|\n)*['"]<([^'"]+)>['"](?:\s|\n)*\)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
β‘οΈ Replace with:
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
TinyHtml.createFrom('$1')
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
### π Match jQuery queries
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
\$\(\s*['"]([^'"]+)['"]\s*\)
|
|
65
|
+
\$\((?:\s|\n)*['"]([^'"]+)['"](?:\s|\n)*\)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
β‘οΈ Replace with:
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
TinyHtml.query('$1')
|
|
72
|
+
```
|
package/docs/v1/libs/TinyHtml.md
CHANGED
|
@@ -1730,6 +1730,7 @@ Attributes
|
|
|
1730
1730
|
```js
|
|
1731
1731
|
element.attr("href"); // Get
|
|
1732
1732
|
element.setAttr("title", "Cool!"); // Set
|
|
1733
|
+
element.setAttr({ "title": "Cool!" }); // Set
|
|
1733
1734
|
element.removeAttr("data-test"); // Remove
|
|
1734
1735
|
element.hasAttr("id"); // Check
|
|
1735
1736
|
```
|
|
@@ -1744,11 +1745,11 @@ Safe and type-checked β throws if misuse is detected.
|
|
|
1744
1745
|
Properties
|
|
1745
1746
|
|
|
1746
1747
|
```js
|
|
1747
|
-
element.hasProp("disabled");
|
|
1748
|
-
element.addProp("checked");
|
|
1749
|
-
element.removeProp("checked");
|
|
1750
|
-
element.toggleProp("disabled");
|
|
1751
|
-
element.toggleProp("readonly", true); // force enable
|
|
1748
|
+
element.hasProp("disabled"); // true/false
|
|
1749
|
+
element.addProp("checked"); // set true
|
|
1750
|
+
element.removeProp("checked"); // set false
|
|
1751
|
+
element.toggleProp("disabled"); // flip
|
|
1752
|
+
element.toggleProp(["readonly"], true); // force enable
|
|
1752
1753
|
```
|
|
1753
1754
|
|
|
1754
1755
|
These methods interact with real DOM properties (not just attributes).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.10",
|
|
4
4
|
"description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "npm run test:mjs && npm run test:cjs && npm run test:js",
|