Last active
May 21, 2019 08:01
-
-
Save lackneets/38caaf7329965f220773c990ea76b5cf to your computer and use it in GitHub Desktop.
混淆數值
This file contains hidden or 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
function shuffle(obj, key){ | |
if(['order', 'type', 'sector_1_id', 'sector_2_id', 'id'].includes(key)){ | |
return obj | |
} | |
if(['name'].includes(key)){ | |
return '明天無限美好' | |
} | |
if(['sub_funds', 'score_rating_intervals'].includes(key)){ | |
return [] | |
} | |
if(['months_volatility', 'months_performance', 'event_performances', 'event_volatilities'].includes(key)){ | |
return {} | |
} | |
if([ | |
'report_url', | |
'annual_report_url', | |
'notice_url', | |
'prospectus_url', | |
'download_reports_url', | |
].includes(key)){ | |
return null | |
} | |
if(obj instanceof Array){ | |
return obj.map(e => shuffle(e)) | |
} | |
if(obj instanceof Object){ | |
return Object.entries(obj).reduce((obj, [key, value]) => ({...obj, [key]: shuffle(value, key)}), {}) | |
} | |
if(typeof obj == 'number'){ | |
// Year | |
if(String(obj).match(/^(19|20)\d{2}$/)){ | |
return obj | |
} | |
const digits = Math.max(0, String(obj).length - String(Math.round(obj)).length -1) | |
return +(Math.random()*obj).toFixed(Math.min(6, digits)) * (Math.random() < 0.5 ? -1 : 1) | |
} | |
if(typeof obj == 'string'){ | |
return obj.replace(/[\n\r\t]/g, '') | |
} | |
return obj | |
} |
This file contains hidden or 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
function shuffle(obj){ | |
if(obj instanceof Array){ | |
return obj.map(e => shuffle(e)) | |
} | |
if(obj instanceof Object){ | |
return Object.entries(obj).reduce((obj, [key, value]) => ({...obj, [key]: shuffle(value)}), {}) | |
} | |
if(typeof obj == 'number'){ | |
// Year | |
if(String(obj).match(/^(19|20)\d{2}$/)){ | |
return obj | |
} | |
return +(Math.random()*obj).toFixed(6) | |
} | |
if(typeof obj == 'string'){ | |
return obj.replace(/[\n\r\t]/g, '') | |
} | |
return obj | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment