ricejs
Version:
Architecture for development of applications with javascript with high capacity of integration to diverse frameworks.
1 lines • 3.31 kB
JavaScript
{"filter":false,"title":"mapping.js","tooltip":"/src/libs/mapping.js","undoManager":{"mark":1,"position":1,"stack":[[{"start":{"row":0,"column":0},"end":{"row":37,"column":0},"action":"remove","lines":["/**"," * Localiza/criar chaves em um objeto, lendo uma rota (em string) separada por pontos."," * Ler: ({\"test\": {\"ok\": \"no\"}}).mapping(\"test.ok\") // no"," * Escreve: ({\"test\": {\"ok\": \"yes\"}}).mapping(\"test.ok\", false) // yes"," */","function mapping(obj, item, value) {"," if (typeof item == \"string\") {"," var item = item.split(\".\")"," var _this = obj;",""," if (!value) {"," for (let i = 0; i < item.length; i++) {"," _this = _this[item[i]]"," }"," }"," else {"," item.reverse();"," var result = {"," [item[0]] : value"," };",""," for (let i = 1; i < (item.length - 1); i++) {"," result = {"," [item[i]] : result"," }"," }",""," var key = item[(item.length - 1)];",""," _this[key] = result[key];"," }",""," return _this;"," }",""," return obj;","}",""],"id":2},{"start":{"row":0,"column":0},"end":{"row":9,"column":0},"action":"insert","lines":["function uuid() {"," function s4() {"," return Math.floor((1 + Math.random()) * 0x10000)"," .toString(16)"," .substring(1);"," }"," return s4() + s4() + '-' + s4() + '-' + s4() + '-' +"," s4() + '-' + s4() + s4() + s4();","}",""]}],[{"start":{"row":0,"column":0},"end":{"row":9,"column":0},"action":"remove","lines":["function uuid() {"," function s4() {"," return Math.floor((1 + Math.random()) * 0x10000)"," .toString(16)"," .substring(1);"," }"," return s4() + s4() + '-' + s4() + '-' + s4() + '-' +"," s4() + '-' + s4() + s4() + s4();","}",""],"id":3},{"start":{"row":0,"column":0},"end":{"row":37,"column":0},"action":"insert","lines":["/**"," * Localiza/criar chaves em um objeto, lendo uma rota (em string) separada por pontos."," * Ler: ({\"test\": {\"ok\": \"no\"}}).mapping(\"test.ok\") // no"," * Escreve: ({\"test\": {\"ok\": \"yes\"}}).mapping(\"test.ok\", false) // yes"," */","function mapping(obj, item, value) {"," if (typeof item == \"string\") {"," var item = item.split(\".\")"," var _this = obj;",""," if (!value) {"," for (let i = 0; i < item.length; i++) {"," _this = _this[item[i]]"," }"," }"," else {"," item.reverse();"," var result = {"," [item[0]] : value"," };",""," for (let i = 1; i < (item.length - 1); i++) {"," result = {"," [item[i]] : result"," }"," }",""," var key = item[(item.length - 1)];",""," _this[key] = result[key];"," }",""," return _this;"," }",""," return obj;","}",""]}]]},"ace":{"folds":[],"scrolltop":93,"scrollleft":0,"selection":{"start":{"row":37,"column":0},"end":{"row":37,"column":0},"isBackwards":false},"options":{"guessTabSize":true,"useWrapMode":false,"wrapToView":true},"firstLineState":0},"timestamp":1491004953452,"hash":"791eb54a21744219153033a2d10703c9caa29f49"}