-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change mock files to commonjs (#3246)
- Loading branch information
1 parent
e773715
commit 6831120
Showing
9 changed files
with
74 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @param {string} url | ||
* @returns {Object} | ||
*/ | ||
function param2Obj(url) { | ||
const search = url.split('?')[1] | ||
if (!search) { | ||
return {} | ||
} | ||
return JSON.parse( | ||
'{"' + | ||
decodeURIComponent(search) | ||
.replace(/"/g, '\\"') | ||
.replace(/&/g, '","') | ||
.replace(/=/g, '":"') | ||
.replace(/\+/g, ' ') + | ||
'"}' | ||
) | ||
} | ||
|
||
/** | ||
* This is just a simple version of deep copy | ||
* Has a lot of edge cases bug | ||
* If you want to use a perfect deep copy, use lodash's _.cloneDeep | ||
* @param {Object} source | ||
* @returns {Object} | ||
*/ | ||
function deepClone(source) { | ||
if (!source && typeof source !== 'object') { | ||
throw new Error('error arguments', 'deepClone') | ||
} | ||
const targetObj = source.constructor === Array ? [] : {} | ||
Object.keys(source).forEach(keys => { | ||
if (source[keys] && typeof source[keys] === 'object') { | ||
targetObj[keys] = deepClone(source[keys]) | ||
} else { | ||
targetObj[keys] = source[keys] | ||
} | ||
}) | ||
return targetObj | ||
} | ||
|
||
module.exports = { | ||
param2Obj, | ||
deepClone | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters