zoukankan      html  css  js  c++  java
  • [Ramda] Convert a QueryString to an Object using Function Composition in Ramda

    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)
  • 相关阅读:
    hdu 4577 X-Boxes 大数
    hdu 4576 Robot 概率DP
    将IP地址转化为整数
    MyISAM压缩表
    yii2 模态框
    MySQL数据库设计
    foreach循环赋值问题
    实用的网站
    判断链接地址是否有效
    tp5获取配置文件信息
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6323273.html
Copyright © 2011-2022 走看看