es-toolkit 1.37.2-dev.1274 → 1.37.2-dev.1276

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.
@@ -186,6 +186,7 @@ export { update } from './object/update.mjs';
186
186
  export { updateWith } from './object/updateWith.mjs';
187
187
  export { values } from './object/values.mjs';
188
188
  export { valuesIn } from './object/valuesIn.mjs';
189
+ export { bindAll } from './util/bindAll.mjs';
189
190
  export { capitalize } from '../string/capitalize.mjs';
190
191
  export { conforms } from './predicate/conforms.mjs';
191
192
  export { conformsTo } from './predicate/conformsTo.mjs';
@@ -186,6 +186,7 @@ export { update } from './object/update.js';
186
186
  export { updateWith } from './object/updateWith.js';
187
187
  export { values } from './object/values.js';
188
188
  export { valuesIn } from './object/valuesIn.js';
189
+ export { bindAll } from './util/bindAll.js';
189
190
  export { capitalize } from '../string/capitalize.js';
190
191
  export { conforms } from './predicate/conforms.js';
191
192
  export { conformsTo } from './predicate/conformsTo.js';
@@ -186,6 +186,7 @@ export { update } from './object/update.mjs';
186
186
  export { updateWith } from './object/updateWith.mjs';
187
187
  export { values } from './object/values.mjs';
188
188
  export { valuesIn } from './object/valuesIn.mjs';
189
+ export { bindAll } from './util/bindAll.mjs';
189
190
  export { capitalize } from '../string/capitalize.mjs';
190
191
  export { conforms } from './predicate/conforms.mjs';
191
192
  export { conformsTo } from './predicate/conformsTo.mjs';
@@ -186,6 +186,7 @@ export { update } from './object/update.mjs';
186
186
  export { updateWith } from './object/updateWith.mjs';
187
187
  export { values } from './object/values.mjs';
188
188
  export { valuesIn } from './object/valuesIn.mjs';
189
+ export { bindAll } from './util/bindAll.mjs';
189
190
  export { capitalize } from '../string/capitalize.mjs';
190
191
  export { conforms } from './predicate/conforms.mjs';
191
192
  export { conformsTo } from './predicate/conformsTo.mjs';
@@ -186,6 +186,7 @@ export { update } from './object/update.js';
186
186
  export { updateWith } from './object/updateWith.js';
187
187
  export { values } from './object/values.js';
188
188
  export { valuesIn } from './object/valuesIn.js';
189
+ export { bindAll } from './util/bindAll.js';
189
190
  export { capitalize } from '../string/capitalize.js';
190
191
  export { conforms } from './predicate/conforms.js';
191
192
  export { conformsTo } from './predicate/conformsTo.js';
@@ -3798,6 +3798,43 @@ function valuesIn(object) {
3798
3798
  return result;
3799
3799
  }
3800
3800
 
3801
+ function bindAll(object, ...methodNames) {
3802
+ if (object == null) {
3803
+ return object;
3804
+ }
3805
+ if (!isObject(object)) {
3806
+ return object;
3807
+ }
3808
+ if (isPlainObject.isArray(object) && methodNames.length === 0) {
3809
+ return object;
3810
+ }
3811
+ const methods = [];
3812
+ for (let i = 0; i < methodNames.length; i++) {
3813
+ const name = methodNames[i];
3814
+ if (isPlainObject.isArray(name)) {
3815
+ methods.push(...name);
3816
+ }
3817
+ else if (name && typeof name === 'object' && 'length' in name) {
3818
+ methods.push(...Array.from(name));
3819
+ }
3820
+ else {
3821
+ methods.push(name);
3822
+ }
3823
+ }
3824
+ if (methods.length === 0) {
3825
+ return object;
3826
+ }
3827
+ for (let i = 0; i < methods.length; i++) {
3828
+ const key = methods[i];
3829
+ const stringKey = toString(key);
3830
+ const func = object[stringKey];
3831
+ if (isWeakSet$1.isFunction(func)) {
3832
+ object[stringKey] = func.bind(object);
3833
+ }
3834
+ }
3835
+ return object;
3836
+ }
3837
+
3801
3838
  function conformsTo(target, source) {
3802
3839
  if (source == null) {
3803
3840
  return true;
@@ -4457,6 +4494,7 @@ const compat = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
4457
4494
  attempt,
4458
4495
  before,
4459
4496
  bind,
4497
+ bindAll,
4460
4498
  bindKey,
4461
4499
  camelCase,
4462
4500
  capitalize: snakeCase$1.capitalize,
@@ -4773,6 +4811,7 @@ exports.at = at;
4773
4811
  exports.attempt = attempt;
4774
4812
  exports.before = before;
4775
4813
  exports.bind = bind;
4814
+ exports.bindAll = bindAll;
4776
4815
  exports.bindKey = bindKey;
4777
4816
  exports.camelCase = camelCase;
4778
4817
  exports.castArray = castArray;
@@ -186,6 +186,7 @@ export { update } from './object/update.mjs';
186
186
  export { updateWith } from './object/updateWith.mjs';
187
187
  export { values } from './object/values.mjs';
188
188
  export { valuesIn } from './object/valuesIn.mjs';
189
+ export { bindAll } from './util/bindAll.mjs';
189
190
  export { capitalize } from '../string/capitalize.mjs';
190
191
  export { conforms } from './predicate/conforms.mjs';
191
192
  export { conformsTo } from './predicate/conformsTo.mjs';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Binds methods of an object to the object itself, overwriting the existing method.
3
+ * Method names may be specified as individual arguments or as arrays of method names.
4
+ *
5
+ * @param {Object} object - The object to bind methods to.
6
+ * @param {...(string|string[]|number|IArguments)} [methodNames] - The method names to bind, specified individually or in arrays.
7
+ * @returns {Object} - Returns the object.
8
+ *
9
+ * @example
10
+ * const view = {
11
+ * 'label': 'docs',
12
+ * 'click': function() {
13
+ * console.log('clicked ' + this.label);
14
+ * }
15
+ * };
16
+ *
17
+ * bindAll(view, ['click']);
18
+ * jQuery(element).on('click', view.click);
19
+ * // => Logs 'clicked docs' when clicked.
20
+ *
21
+ * @example
22
+ * // Using individual method names
23
+ * bindAll(view, 'click');
24
+ * // => Same as above
25
+ */
26
+ declare function bindAll<T>(object: T, ...methodNames: Array<string | string[]>): T;
27
+
28
+ export { bindAll };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Binds methods of an object to the object itself, overwriting the existing method.
3
+ * Method names may be specified as individual arguments or as arrays of method names.
4
+ *
5
+ * @param {Object} object - The object to bind methods to.
6
+ * @param {...(string|string[]|number|IArguments)} [methodNames] - The method names to bind, specified individually or in arrays.
7
+ * @returns {Object} - Returns the object.
8
+ *
9
+ * @example
10
+ * const view = {
11
+ * 'label': 'docs',
12
+ * 'click': function() {
13
+ * console.log('clicked ' + this.label);
14
+ * }
15
+ * };
16
+ *
17
+ * bindAll(view, ['click']);
18
+ * jQuery(element).on('click', view.click);
19
+ * // => Logs 'clicked docs' when clicked.
20
+ *
21
+ * @example
22
+ * // Using individual method names
23
+ * bindAll(view, 'click');
24
+ * // => Same as above
25
+ */
26
+ declare function bindAll<T>(object: T, ...methodNames: Array<string | string[]>): T;
27
+
28
+ export { bindAll };
@@ -0,0 +1,43 @@
1
+ import { isFunction } from '../../predicate/isFunction.mjs';
2
+ import { isArray } from '../predicate/isArray.mjs';
3
+ import { isObject } from '../predicate/isObject.mjs';
4
+ import { toString } from './toString.mjs';
5
+
6
+ function bindAll(object, ...methodNames) {
7
+ if (object == null) {
8
+ return object;
9
+ }
10
+ if (!isObject(object)) {
11
+ return object;
12
+ }
13
+ if (isArray(object) && methodNames.length === 0) {
14
+ return object;
15
+ }
16
+ const methods = [];
17
+ for (let i = 0; i < methodNames.length; i++) {
18
+ const name = methodNames[i];
19
+ if (isArray(name)) {
20
+ methods.push(...name);
21
+ }
22
+ else if (name && typeof name === 'object' && 'length' in name) {
23
+ methods.push(...Array.from(name));
24
+ }
25
+ else {
26
+ methods.push(name);
27
+ }
28
+ }
29
+ if (methods.length === 0) {
30
+ return object;
31
+ }
32
+ for (let i = 0; i < methods.length; i++) {
33
+ const key = methods[i];
34
+ const stringKey = toString(key);
35
+ const func = object[stringKey];
36
+ if (isFunction(func)) {
37
+ object[stringKey] = func.bind(object);
38
+ }
39
+ }
40
+ return object;
41
+ }
42
+
43
+ export { bindAll };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.37.2-dev.1274+adcc5606",
4
+ "version": "1.37.2-dev.1276+50dd3188",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {