How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • self.getBody(id, (error, bodyContent) => {
            if (error) {
              
              //...
    } else if (!bodyContent) {
              
              //...
    } else {
              
              //...
    try {
                
                //...
    if (charsetMatch && charsetMatch.length) {
                  
                  //...
    if (currentCharset !== 'utf-8' && iconv.encodingExists(currentCharset)) {
                    bodyContent = iconv.decode(bodyContent, currentCharset);
                  }
    
                  
    
                  //...
    } else if (contentType && /image/i.test(contentType)) {
                  
                  //...
    } else {
                  
                  //...
    }
                
                //...
    } catch (e) {
                
                //...
    }
              
              //...
    }
          })
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">const</span> self<span class="token operator">:</span> <span class="token keyword">this</span></code></pre>
    /alibaba/anyproxy apache-2.0
    0
  • function createDecoder(encoding) {
      if (!encoding) {
        return defaultDecoder;
      }
      if (!iconv.encodingExists(encoding)) {
        if (encoding.length > 5 && iconv.encodingExists(encoding.slice(5))) {
          encoding = encoding.slice(5);
        } else {
          return defaultDecoder;
        }
      }
      return decoder;
      
      //...
    }
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">createDecoder</span><span class="token punctuation">(</span><span class="token parameter">encoding<span class="token operator">:</span> any</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">data<span class="token operator">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token builtin">string</span></code></pre>
    /calvinmetcalf/parseDBF mit
    0
  • const validateExisting = function ({ charset }) {
      if (iconvLite.encodingExists(charset)) {
        return
      }
    
      throw new Error(`Unsupported charset: '${charset}'`)
    }
    
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">const</span> <span class="token function-variable function">validateExisting</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span> charset <span class="token punctuation">}</span><span class="token operator">:</span> <span class="token punctuation">{</span> charset<span class="token operator">:</span> any<span class="token punctuation">;</span> <span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token keyword">void</span></code></pre>
    /ehmicky/autoserver apache-2.0
    0
  • self.getDecodedBody = function (id, cb) {
        
        //...
    global.recorder.getSingleRecord(id, (err, doc) => {
          
          //...
    self.getBody(id, (error, bodyContent) => {
            if (error) {
              
              //...
    } else if (!bodyContent) {
              
              //...
    } else {
              
              //...
    try {
                
                //...
    if (charsetMatch && charsetMatch.length) {
                  
                  //...
    if (currentCharset !== 'utf-8' && iconv.encodingExists(currentCharset)) {
                    bodyContent = iconv.decode(bodyContent, currentCharset);
                  }
                }
    
                
    
                //...
    } catch (e) {}
              
              //...
    }
          });
        });
      }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>property<span class="token punctuation">)</span> Recorder<span class="token punctuation">.</span><span class="token function-variable function">getDecodedBody</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">id<span class="token operator">:</span> any<span class="token punctuation">,</span> cb<span class="token operator">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token keyword">void</span></code></pre>
    /fwon/electron-anyproxy MIT
    0
  • const custom = Joi.extend(joi => {
      return {
        
        //...
    ,
        rules: {
          encoding: {
            validate (value, helpers, args, options) {
              
              //...
    for (const url in value) {
                
                //...
    if (!iconv.encodingExists(encoding)) {
                  invalids.add(encoding)
                }
              }
              
              //...
    }
          }
        }
      }
    })
    
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">const</span> custom<span class="token operator">:</span> <span class="token builtin">any</span></code></pre>
    /synzen/MonitoRSS mit
    0
  • module.exports = function() {
      return async function OutputCharset(ctx, next) {
        
        //...
    if (typeof body === 'string') {
          debug('encode to %s', charset);
          const iconv = require('iconv-lite');
          ctx.body = iconv.encode(body, charset);
    
          const ctype = ctx.response.headers['content-type'];
          if (ctype) {
            const newCtype = ctype.replace(rCharset, '') + '; charset=' + charset;
            debug('set content-type: %s', newCtype);
            ctx.set('content-type', newCtype);
          }
        }
      };
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> <span class="token keyword">export</span><span class="token operator">=</span> <span class="token punctuation">(</span>property<span class="token punctuation">)</span> <span class="token keyword">export</span><span class="token operator">=</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">(</span><span class="token parameter">ctx<span class="token operator">:</span> any<span class="token punctuation">,</span> next<span class="token operator">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">></span></code></pre>
    /alibaba/plover apache-2.0
    0
  • encodings.LATIN1 = {
    	match: function(value) {
    		return value === iconv.decode(iconv.encode(value, 'latin1'), 'latin1');
    	},
    	encode: function(value) {
    		return iconv.encode(value, 'latin1');
    	},
    	decode: function(value) {
    		return iconv.decode(value, 'latin1');
    	}
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> encodings <span class="token keyword">var</span> encodings<span class="token operator">:</span> <span class="token keyword">typeof</span> encodings</code></pre>
    /farhadi/node-smpp mit
    0
  • function buildHeader(puz) {
        const i = puz_common.PUZ_HEADER_CONSTANTS.offsets;
        const header = new Uint8Array(puz_common.PUZ_HEADER_CONSTANTS.lengths.HEADER);
    
        // metadata
        header.set(iconv.encode("ACROSS&DOWN", "utf-8"), i.MAGIC);
        header.set(iconv.encode("1.3", "utf-8"), i.VERSION);
    
        // dimensions
        header[i.WIDTH] = puz.width;
        header[i.HEIGHT] = puz.height;
        puz_common.writeUInt16LE(header, i.NUM_CLUES, puz.clues.length);
    
        
    
        //...
    }
    
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">buildHeader</span><span class="token punctuation">(</span><span class="token parameter">puz<span class="token operator">:</span> any</span><span class="token punctuation">)</span><span class="token operator">:</span> Uint8Array</code></pre>
    /rjkat/confuzzle MIT
    0
  • module.exports = function (options) {
      
      //...
    return async function charset(ctx, next) {
        
        //...
    if (Buffer.isBuffer(ctx.body) || typeof ctx.body === 'string') {
          ctx.body = iconv.encode(ctx.body, charset);
          return;
        }
    
        // stream body
        if (typeof ctx.body.pipe === 'function') {
          ctx.body = ctx.body.pipe(iconv.decodeStream('utf8'));
          ctx.body = ctx.body.pipe(iconv.encodeStream(charset));
          return;
        }
    
        
    
        //...
    };
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> <span class="token keyword">export</span><span class="token operator">=</span> <span class="token punctuation">(</span>property<span class="token punctuation">)</span> <span class="token keyword">export</span><span class="token operator">=</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">options<span class="token operator">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">(</span><span class="token parameter">ctx<span class="token operator">:</span> any<span class="token punctuation">,</span> next<span class="token operator">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">></span></code></pre>
    /koajs/charset MIT
    0
  • var iconv = require('iconv-lite');
    
    // Convert from an encoded buffer to a js string.
    str = iconv.decode(Buffer.from([0x68, 0x65, 0x6c, 0x6c, 0x6f]), 'win1251');
    
    // Convert from a js string to an encoded buffer.
    buf = iconv.encode("Sample input string", 'win1251');
    
    // Check if encoding is supported
    iconv.encodingExists("us-ascii")
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">import</span> iconv</code></pre>
    Docs
    0
  • // Decode stream (from binary data stream to js strings)
    http.createServer(function(req, res) {
        var converterStream = iconv.decodeStream('win1251');
        req.pipe(converterStream);
    
        converterStream.on('data', function(str) {
            console.log(str); // Do something with decoded strings, chunk-by-chunk.
        });
    });
    
    // Convert encoding streaming example
    fs.createReadStream('file-in-win1251.txt')
        .pipe(iconv.decodeStream('win1251'))
        .pipe(iconv.encodeStream('ucs2'))
        .pipe(fs.createWriteStream('file-in-ucs2.txt'));
    
    // Sugar: all encode/decode streams have .collect(cb) method to accumulate data.
    http.createServer(function(req, res) {
        req.pipe(iconv.decodeStream('win1251')).collect(function(err, body) {
            assert(typeof body == 'string');
            console.log(body); // full request body string
        });
    });
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • module.exports = async (ctx) => {
        
        //...
    const response = await got.get(url, {
            responseType: 'buffer',
        });
    
        const data = response.data;
        const $ = cheerio.load(iconv.decode(data, 'gb2312'));
        const list = $('#body > div.M > div.AboutUsDetail > ul > li');
    
        
    
        //...
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> <span class="token keyword">export</span><span class="token operator">=</span> <span class="token punctuation">(</span>property<span class="token punctuation">)</span> <span class="token keyword">export</span><span class="token operator">=</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">ctx<span class="token operator">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">></span></code></pre>
    /DIYgod/RSSHub MIT
    0
  • module.exports = async (ctx) => {
        
        //...
    const response = await got({
            method: 'get',
            url: link,
            headers: {
                Referer: baseUrl,
            },
            responseType: 'buffer',
        });
        const responseHtml = iconv.decode(response.data, 'gbk');
        const $ = cheerio.load(responseHtml);
    
        
    
        //...
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> <span class="token keyword">export</span><span class="token operator">=</span> <span class="token punctuation">(</span>property<span class="token punctuation">)</span> <span class="token keyword">export</span><span class="token operator">=</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">ctx<span class="token operator">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">></span></code></pre>
    /DIYgod/RSSHub MIT
    0
  • module.exports = async (ctx) => {
        
        //...
    const $ = cheerio.load(iconv.decode(response.data, 'gbk'));
    
        
    
        //...
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> <span class="token keyword">export</span><span class="token operator">=</span> <span class="token punctuation">(</span>property<span class="token punctuation">)</span> <span class="token keyword">export</span><span class="token operator">=</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">ctx<span class="token operator">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">></span></code></pre>
    /DIYgod/RSSHub MIT
    0
  • module.exports = async (ctx) => {
        
        //...
    const $ = cheerio.load(iconv.decode(response.data, 'gb2312'));
    
        
    
        //...
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> <span class="token keyword">export</span><span class="token operator">=</span> <span class="token punctuation">(</span>property<span class="token punctuation">)</span> <span class="token keyword">export</span><span class="token operator">=</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">ctx<span class="token operator">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">></span></code></pre>
    /DIYgod/RSSHub MIT
    0
  • module.exports = async (ctx) => {
        
        //...
    const response = await got({
            method: 'get',
            url: currentUrl,
            responseType: 'buffer',
        });
    
        const data = iconv.decode(response.data, 'gbk');
    
        let items = {};
    
        const urls = data.match(/url:"(.*)",/g);
    
        
    
        //...
    }
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> <span class="token keyword">export</span><span class="token operator">=</span> <span class="token punctuation">(</span>property<span class="token punctuation">)</span> <span class="token keyword">export</span><span class="token operator">=</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">ctx<span class="token operator">:</span> any</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token builtin">Promise</span><span class="token operator">&lt;</span><span class="token keyword">void</span><span class="token operator">></span></code></pre>
    /DIYgod/RSSHub MIT
    0
  • // Decode stream (from binary data stream to js strings)
    http.createServer(function(req, res) {
        var converterStream = iconv.decodeStream('win1251');
        req.pipe(converterStream);
    
        converterStream.on('data', function(str) {
            console.log(str); // Do something with decoded strings, chunk-by-chunk.
        });
    });
    
    // Convert encoding streaming example
    fs.createReadStream('file-in-win1251.txt')
        .pipe(iconv.decodeStream('win1251'))
        .pipe(iconv.encodeStream('ucs2'))
        .pipe(fs.createWriteStream('file-in-ucs2.txt'));
    
    // Sugar: all encode/decode streams have .collect(cb) method to accumulate data.
    http.createServer(function(req, res) {
        req.pipe(iconv.decodeStream('win1251')).collect(function(err, body) {
            assert(typeof body == 'string');
            console.log(body); // full request body string
        });
    });
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples