zoukankan      html  css  js  c++  java
  • [Ramda] Create a Query String from an Object using Ramda's toPairs function

    In this lesson, we'll use Ramda's toPairs function, along with mapjoinconcatand compose to create a reusable function that will convert an object to a querystring.

    const R = require('ramda');
    
    const {map, join, concat, compose, toPairs} = R;
    
    const obj = {
        page: 2,
        limit: 6,
        type: 'movies'
    };
    
    const createQs = compose(
        concat('?'), // ?page=2&limit=6&type=movies
        join('&'), // page=2&limit=6&type=movies
        map(join('=')), // [ 'page=2', 'limit=6', 'type=movies' ]
        toPairs  // [ [ 'page', 2 ], [ 'limit', 6 ], [ 'type', 'movies' ] ]
    );
    const result = createQs(obj);
    
    console.log(result);
  • 相关阅读:
    指针
    day07
    day06
    oracle instr
    动态解析dll及使用类
    客户端调用接口
    Java中调用WebService
    Vs2015智能提示英文
    oracle中varchar(32)转nvarchar(32)
    C#创建XML节点
  • 原文地址:https://www.cnblogs.com/Answer1215/p/6531655.html
Copyright © 2011-2022 走看看