您好,登錄后才能下訂單哦!
前言
最近在做一個(gè)項(xiàng)目,發(fā)現(xiàn)后端返回的數(shù)據(jù)鍵值全部都是大寫的,有時(shí)候前端用起來很不方便,所以寫了一個(gè)深度轉(zhuǎn)換的小工具,分享給大家,也就不用重復(fù)造輪子了,不喜勿噴,下面話不多說了,來一起看看詳細(xì)的介紹吧。
start
npm i deep-lu-trans --save
json example
import t from 'deep-lu-trans'; const obj = { AS_DD_S: 123213, AND_SAJ_JDK_JSAKD_: { DJK_ASJ: { SA_DSA_DSA: 123123, ASDA_SDH_KAS: { ASD_SAD: [{ ASD_SAD_SA: 123123, III_ASDA: [1, 23, { ASD_SAD: 123 }] }] } } }, KIO: [{ OP: 1, OOP: 2 }, { OL: 1, OP: 2 }] }; t.objKeysToLower(obj).then((res) => { console.log(JSON.stringify(res)); }); t.objKeysToLower(obj).then((res) => { console.log(JSON.stringify(res)); /* {"as_dd_s":123213,"and_saj_jdk_jsakd_":{"djk_asj":{"sa_dsa_dsa":123123,"asda_sdh_kas":{"asd_sad":[{"asd_sad_sa":123123,"iii_asda":[1,23,{"asd_sad":123}]}]}}},"kio":[{"op":1,"oop":2},{"ol":1,"op":2}]} */ t.objKeysToUpper(res).then((_s) => { console.log(JSON.stringify(_s)); /* {"AS_DD_S":123213,"AND_SAJ_JDK_JSAKD_":{"DJK_ASJ":{"SA_DSA_DSA":123123,"ASDA_SDH_KAS":{"ASD_SAD":[{"ASD_SAD_SA":123123,"III_ASDA":[1,23,{"ASD_SAD":123}]}]}}},"KIO":[{"OP":1,"OOP":2},{"OL":1,"OP":2}]} */ }); });
array example
import t from 'deep-lu-trans'; const arr = [{ A_B: 1, B_C: 2 }, 3, 4, 'abc', [{ A_B: 1, B_C: { C_D: [0, { CK: 1, KL: 2 }] } }]] t.arrKeysToLower(arr).then((res) => { console.log(JSON.stringify(res)); /* [{"a_b":1,"b_c":2},3,4,"abc",[{"a_b":1,"b_c":{"c_d":[0,{"ck":1,"kl":2}]}}]] */ t.arrKeysToUpper(res).then((_s) => { console.log(JSON.stringify(_s)); [{"A_B":1,"B_C":2},3,4,"abc",[{"A_B":1,"B_C":{"C_D":[0,{"CK":1,"KL":2}]}}]] }); })
git地址:https://github.com/burning0xb/deep-lu-trans
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對(duì)億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。