In this lesson we'll use a handful of Ramda's utility functions to take a queryString full of name/value pairs and covert it into a JavaScript object so we can access those properties in a more useful way. Along the way, we'll build up a composition and look at the tailsplitmap and fromPairs functions, along with the crucial composefunction.

const {compose, fromPairs, map, split, tail} = R

const queryString = '?page=2&pageSize=10&total=203'

const parseQs = compose(
fromPairs, // {"page":"2","pageSize":"10","total":"203"}
map(split('=')), // [["page","2"],["pageSize","10"],["total","203"]]
split('&'), // ["page=2","pageSize=10","total=203"]
tail // "page=2&pageSize=10&total=203"
) const result = parseQs(queryString)
console.log(result)

[Ramda] Convert a QueryString to an Object using Function Composition in Ramda的更多相关文章

  1. [Ramda] Refactor a Promise Chain to Function Composition using Ramda

    Promise chains can be a powerful way to handle a series of transformations to the results of an asyn ...

  2. How to convert a QString to unicode object in python 2?

    How to convert a QString to unicode object in python 2? I had this problem to solve, and I tried to ...

  3. Jpa自定义查询报错(Failed to convert from type [java.lang.Object[]] to type)

    Jpa自定义查询报错 问题背景 今天遇到一个奇怪的报错"Failed to convert from type [java.lang.Object[]] to type",这个报错 ...

  4. convert URL Query String to Object All In One

    convert URL Query String to Object All In One URL / query string / paramas query string to object le ...

  5. javascript的 Object 和 Function

    一. javascript 的 内置对象: Object 和 Function javascript所有东西,包括 Function 都是对象 . Array  其实是一个 Function 类型的对 ...

  6. JS原型的问题Object和Function到底是什么关系

    var F = function(){}; Objcert.prototype.a = function(){}; Function.prototype.b = function(){}; F 既能访 ...

  7. Js中Prototype、__proto__、Constructor、Object、Function关系介绍

    一. Prototype.__proto__与Object.Function关系介绍 Function.Object:都是Js自带的函数对象.prototype,每一个函数对象都有一个显式的proto ...

  8. Object、Function、String、Array原生对象扩展方法

    JavaScript原生对象的api有些情况下使用并不方便,考虑扩展基于Object.Function.String.Array扩展,参考了prototype.js的部分实现,做了提取和修改,分享下: ...

  9. Object instanceof Function和Function instanceof Object

    首先需要确定的是,instanceof是根据原型链来判断是否为某引用类型的实例.所以需要明白Object和Function之间的关系,以下为引用某博客的图片,阐述了javascript对象体系的关系 ...

随机推荐

  1. Vue router的query对象里的值的问题

    在使用 $router.push() 时,如果使用了query,则可以在跳转后从query中获取到对应的参数.如果传的是字符串自然没问题,但是如果传的其他类型的数据,在跳转之后是正常的,而跳转之后再刷 ...

  2. sqlite3-查看数据库

    在做android开发的时候,有时候我们需要查看系统下的数据库,这时候我们可以使用下面的方法 1.数据库存放位置 data/data/package/databases/abc.db 2.导出数据库 ...

  3. 循环体(for/while)循环变量的设置

    1. 求滑动(移动)平均(moving average) double partialSum = 0; for (int i = 0; i < M-1; ++i) partialSum += A ...

  4. WP8日历(含农历)APP

    WP8日历(含农历)APP WP8日历(含农历)APP UI XAML(部分) <phone:PhoneApplicationPage xmlns:CustomControl="clr ...

  5. Altium Designer 在pcb下导入的原件引脚是绿的

    当然也可能是其他规则原因导致的

  6. 通过Rman catalog 创建及管理Oracle数据库备份

    基本环境信息target DB (需备份数据库) 192.168.199.67 ORACLE_SID=zgw HOSTNAME=Oracle11 catlog DB (备份管理数据库) 192.168 ...

  7. 安装后,挂载c盘失败

    现象: 安装后,window C盘mount失败 错误内容如下: Error mounting: mount exited with exit code 13: ntfs_attr_pread_i: ...

  8. 11995 - I Can Guess the Data

    大意:猜数据结构是栈.队列或者优先队列,可能为两种以上,也可能都不是. 水题.. STL 记得判断是否为空 #include<iostream> #include<cstdio> ...

  9. 总览:SpringCloud基础结构

    客户端: 1.连接 配置中心2.连接 服务中心3.连接 链路跟踪3.feign调用4.熔断机制5.连接 熔断监控6.swagger2 生成的RESTful-API7.消息总线-rabbitMQ实现 基 ...

  10. 126邮件POP3,SMTP服务器与端口设置