mirror of
https://github.com/flarum/framework.git
synced 2025-03-04 14:09:28 +08:00
convert: common/utils/extract
This commit is contained in:
parent
443fdfd515
commit
77d315585c
@ -1,15 +0,0 @@
|
|||||||
/**
|
|
||||||
* The `extract` utility deletes a property from an object and returns its
|
|
||||||
* value.
|
|
||||||
*
|
|
||||||
* @param {Object} object The object that owns the property
|
|
||||||
* @param {String} property The name of the property to extract
|
|
||||||
* @return {*} The value of the property
|
|
||||||
*/
|
|
||||||
export default function extract(object, property) {
|
|
||||||
const value = object[property];
|
|
||||||
|
|
||||||
delete object[property];
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
15
framework/core/js/src/common/utils/extract.ts
Normal file
15
framework/core/js/src/common/utils/extract.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/**
|
||||||
|
* The `extract` utility deletes a property from an object and returns its
|
||||||
|
* value.
|
||||||
|
*
|
||||||
|
* @param object The object that owns the property
|
||||||
|
* @param property The name of the property to extract
|
||||||
|
* @return The value of the property
|
||||||
|
*/
|
||||||
|
export default function extract<T, K extends keyof T>(object: T, property: K): T[K] {
|
||||||
|
const value = object[property];
|
||||||
|
|
||||||
|
delete object[property];
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user