Cleanup & Improvements
- Rename `getByProps()` to `getByKeys()` and deprecated *byProps methods & filters. - Fix a couple string errors - Rename `getByPrototypes()` to `getByPrototypeFields()` - Rename `getMangled()` to `getWithKey()`
This commit is contained in:
parent
68c6b81ed7
commit
83c0c81079
|
@ -32,12 +32,17 @@ const Webpack = {
|
|||
* @memberof Webpack
|
||||
*/
|
||||
Filters: {
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
byProps(...props) {return Filters.byKeys(props);},
|
||||
|
||||
/**
|
||||
* Generates a function that filters by a set of properties.
|
||||
* @param {...string} props List of property names
|
||||
* @param {...string} keys List of property names
|
||||
* @returns {function} A filter that checks for a set of properties
|
||||
*/
|
||||
byProps(...props) {return Filters.byProps(props);},
|
||||
byKeys(...keys) {return Filters.byKeys(keys);},
|
||||
|
||||
/**
|
||||
* Generates a function that filters by a set of properties on the object's prototype.
|
||||
|
@ -85,11 +90,11 @@ const Webpack = {
|
|||
* @param {Boolean} [options.searchExports=false] Whether to execute the filter on webpack export getters.
|
||||
* @return {[Any, string]}
|
||||
*/
|
||||
getMangled(filter, options = {}) {
|
||||
if (("first" in options)) return Logger.error("BdApi.Webpack~getModule", "Unsupported option first.");
|
||||
if (("defaultExport" in options) && typeof(options.defaultExport) !== "boolean") return Logger.error("BdApi.Webpack~getModule", "Unsupported type used for options.defaultExport", options.defaultExport, "boolean expected.");
|
||||
if (("searchExports" in options) && typeof(options.searchExports) !== "boolean") return Logger.error("BdApi.Webpack~getModule", "Unsupported type used for options.searchExports", options.searchExports, "boolean expected.");
|
||||
return WebpackModules.getMangled(filter, options);
|
||||
getWithKey(filter, options = {}) {
|
||||
if (("first" in options)) return Logger.error("BdApi.Webpack~getWithKey", "Unsupported option first.");
|
||||
if (("defaultExport" in options) && typeof(options.defaultExport) !== "boolean") return Logger.error("BdApi.Webpack~getWithKey", "Unsupported type used for options.defaultExport", options.defaultExport, "boolean expected.");
|
||||
if (("searchExports" in options) && typeof(options.searchExports) !== "boolean") return Logger.error("BdApi.Webpack~getWithKey", "Unsupported type used for options.searchExports", options.searchExports, "boolean expected.");
|
||||
return WebpackModules.getWithKey(filter, options);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -102,13 +107,18 @@ const Webpack = {
|
|||
* @param {Boolean} [options.searchExports=false] Whether to execute the filter on webpack exports
|
||||
* @return {any}
|
||||
*/
|
||||
getModule(filter, options = {}) {
|
||||
if (("first" in options) && typeof(options.first) !== "boolean") return Logger.error("BdApi.Webpack~getModule", "Unsupported type used for options.first", options.first, "boolean expected.");
|
||||
if (("defaultExport" in options) && typeof(options.defaultExport) !== "boolean") return Logger.error("BdApi.Webpack~getModule", "Unsupported type used for options.defaultExport", options.defaultExport, "boolean expected.");
|
||||
if (("searchExports" in options) && typeof(options.searchExports) !== "boolean") return Logger.error("BdApi.Webpack~getModule", "Unsupported type used for options.searchExports", options.searchExports, "boolean expected.");
|
||||
get(filter, options = {}) {
|
||||
if (("first" in options) && typeof(options.first) !== "boolean") return Logger.error("BdApi.Webpack~get", "Unsupported type used for options.first", options.first, "boolean expected.");
|
||||
if (("defaultExport" in options) && typeof(options.defaultExport) !== "boolean") return Logger.error("BdApi.Webpack~get", "Unsupported type used for options.defaultExport", options.defaultExport, "boolean expected.");
|
||||
if (("searchExports" in options) && typeof(options.searchExports) !== "boolean") return Logger.error("BdApi.Webpack~get", "Unsupported type used for options.searchExports", options.searchExports, "boolean expected.");
|
||||
return WebpackModules.getModule(filter, options);
|
||||
},
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
getModule() {return this.get.apply(this, arguments);},
|
||||
|
||||
/**
|
||||
* Finds multiple modules using multiple filters.
|
||||
* @memberof Webpack
|
||||
|
@ -134,7 +144,7 @@ const Webpack = {
|
|||
waitForModule(filter, options = {}) {
|
||||
if (("defaultExport" in options) && typeof(options.defaultExport) !== "boolean") return Logger.error("BdApi.Webpack~waitForModule", "Unsupported type used for options.defaultExport", options.defaultExport, "boolean expected.");
|
||||
if (("signal" in options) && !(options.signal instanceof AbortSignal)) return Logger.error("BdApi.Webpack~waitForModule", "Unsupported type used for options.signal", options.signal, "AbortSignal expected.");
|
||||
if (("searchExports" in options) && typeof(options.searchExports) !== "boolean") return Logger.error("BdApi.Webpack~getModule", "Unsupported type used for options.searchExports", options.searchExports, "boolean expected.");
|
||||
if (("searchExports" in options) && typeof(options.searchExports) !== "boolean") return Logger.error("BdApi.Webpack~waitForModule", "Unsupported type used for options.searchExports", options.searchExports, "boolean expected.");
|
||||
return WebpackModules.getLazy(filter, options);
|
||||
},
|
||||
|
||||
|
@ -184,7 +194,7 @@ const Webpack = {
|
|||
* @param {...string} prototypes Properties to use to filter modules
|
||||
* @return {Any[]}
|
||||
*/
|
||||
getAllByPrototypes(...prototypes) {
|
||||
getAllByPrototypeFields(...prototypes) {
|
||||
const options = getOptions(prototypes, {first: false});
|
||||
|
||||
return WebpackModules.getModule(Filters.byPrototypeFields(prototypes), options);
|
||||
|
@ -195,10 +205,10 @@ const Webpack = {
|
|||
* @param {...string} props Properties to use to filter modules
|
||||
* @return {Any}
|
||||
*/
|
||||
getByProps(...props) {
|
||||
getByKeys(...props) {
|
||||
const options = getOptions(props);
|
||||
|
||||
return this.getModule(Filters.byProps(props), options);
|
||||
return WebpackModules.getModule(Filters.byKeys(props), options);
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -206,10 +216,10 @@ const Webpack = {
|
|||
* @param {...string} props Properties to use to filter modules
|
||||
* @return {Any[]}
|
||||
*/
|
||||
getAllByProps(...props) {
|
||||
getAllByKeys(...props) {
|
||||
const options = getOptions(props, {first: false});
|
||||
|
||||
return WebpackModules.getModule(Filters.byProps(props), options);
|
||||
return WebpackModules.getModule(Filters.byKeys(props), options);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,7 @@ export class Filters {
|
|||
* @param {module:WebpackModules.Filters~filter} filter - Additional filter
|
||||
* @returns {module:WebpackModules.Filters~filter} - A filter that checks for a set of properties
|
||||
*/
|
||||
static byProps(props, filter = m => m) {
|
||||
static byKeys(props, filter = m => m) {
|
||||
return module => {
|
||||
if (!module) return false;
|
||||
if (typeof(module) !== "object" && typeof(module) !== "function") return false;
|
||||
|
@ -275,7 +275,7 @@ export default class WebpackModules {
|
|||
* @param {Boolean} [options.searchExports=false] Whether to execute the filter on webpack export getters.
|
||||
* @return {[Any, string]}
|
||||
*/
|
||||
static *getMangled(filter, {target = null, ...rest} = {}) {
|
||||
static *getWithKey(filter, {target = null, ...rest} = {}) {
|
||||
yield target ??= this.getModule(exports =>
|
||||
Object.values(exports).some(filter),
|
||||
rest
|
||||
|
@ -333,7 +333,7 @@ export default class WebpackModules {
|
|||
* @return {Any}
|
||||
*/
|
||||
static getByProps(...props) {
|
||||
return this.getModule(Filters.byProps(props));
|
||||
return this.getModule(Filters.byKeys(props));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -342,7 +342,7 @@ export default class WebpackModules {
|
|||
* @return {Any}
|
||||
*/
|
||||
static getAllByProps(...props) {
|
||||
return this.getModule(Filters.byProps(props), {first: false});
|
||||
return this.getModule(Filters.byKeys(props), {first: false});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue