Get data from Server
Match regex and get data from server
by Riderman Sousa
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.23.0/ramda.min.js"></script>
JavaScript
const fetchByMAC = MACAddress => ({
classroom_unique_code: 'data',
mac: MACAddress,
});
const topicWithRobotMACPattern = /^robot\/([a-zA-Z0-9]{2}:.+)/mi;
const matchRobotMAC = R.match(topicWithRobotMACPattern);
const extractMACAddress = R.pipe(matchRobotMAC, R.nth(1));
const topicProp = R.lensProp('topic');
const viewTopic = R.view(topicProp);
const getDataFromServer = R.pipe(viewTopic, extractMACAddress, fetchByMAC);
const obj = {
topic: 'robot/30:20:AD:12'
};
const data = getDataFromServer(obj);
console.debug(data);