[Ramda] Convert a QueryString to an Object using Function Composition in Ramda
2017-01-20 16:50
459 查看
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
tail,
split,
mapand
fromPairsfunctions, 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)
相关文章推荐
- 通过动态对象(DynamicObject)实现不定数量列的数据存储与展示
- Objective-C:理解Category
- JAVA中对List<Map<String,Object>>中的中文汉字进行排序
- List<Map<String, Object>>是什么意思
- iOS开发中setValue和setObject的区别
- java对List<Object>型列表进行排序(通过内部类对compare(**)方法重写)
- jsonObject Unknown property异常
- 对象图(Object Diagram)
- QObject 的拷贝构造和赋值操作
- 获取JSONObject 中的属性并且转为String
- [置顶] Swift和Objective-C交互
- 仿《雷霆战机》飞行射击手游开发--GameObject
- iOS开发-Objective-C单例在ARC环境下的实现和理解
- Python3基础 object是所有类的基类 issubclass
- objective-c使用代码触发按钮的点击事件
- IE11 - Object doesn't support property or method 'includes'
- A对象GameObject是否面向B对象的判断
- spark core 2.0 DiskBlockObjectWriter
- [Ramda] Declaratively Map Data Transformations to Object Properties Using Ramda evolve
- Java 如何将List<实体类> 转为List<Object>类型