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

  • var serialize = require('serialize-javascript');
    
    serialize({
        str  : 'string',
        num  : 0,
        obj  : {foo: 'foo'},
        arr  : [1, 2, 3],
        bool : true,
        nil  : null,
        undef: undefined,
        inf  : Infinity,
        date : new Date("Thu, 28 Apr 2016 22:02:17 GMT"),
        map  : new Map([['hello', 'world']]),
        set  : new Set([123, 456]),
        fn   : function echo(arg) { return arg; },
        re   : /([^\s]+)/g,
        big  : BigInt(10),
    });
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">function</span> <span class="token function">serialize</span><span class="token punctuation">(</span><span class="token parameter">input<span class="token operator">:</span> any<span class="token punctuation">,</span> options<span class="token operator">?</span><span class="token operator">:</span> serializeJavascript<span class="token punctuation">.</span>SerializeJSOptions <span class="token operator">|</span> number <span class="token operator">|</span> string</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token function">string</span> <span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">namespace</span> serialize <span class="token keyword">import</span> serialize</code><div class="typing-tooltip-markup">Serialize JavaScript to a superset of JSON that includes regular expressions and functions.<br><br><em>@param</em> <code>input</code> — data to serialize<br><br><em>@param</em> <code>options</code> — optional object<br><br><em>@returns</em> — serialized data</div></pre>
    Docs
    0
  • serialize(obj, {space: 2});
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • serialize(obj, {ignoreFunction: true});
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token builtin">any</span></code></pre>
    Docs
    0
  • getAsset(name, state) {
        const manifest = this.resource && this.resource.manifest || {};
        const deps = manifest.deps || {};
        const res = deps[name] || {};
        return {
          js: res.js || [],
          css: res.css || [],
          state: serialize(state || {}, { isJSON: true }),
        };
      }
    
      
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>method<span class="token punctuation">)</span> Engine<span class="token punctuation">.</span><span class="token function">getAsset</span><span class="token punctuation">(</span>name<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">,</span> state<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token punctuation">{</span> js<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> css<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">;</span> state<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">;</span> <span class="token punctuation">}</span></code></pre>
    /easy-team/egg-view-react-ssr MIT
    0
  • function buildEmbeddedCode(data, webpackAssets) {
      
      //...
    return `
        <script>
          (function() {
            var namespace = '${buildConst.namespace}';
            var pkg = '${buildConst.pkgName}';
            if (typeof window != 'undefined') {
              if (!window.hasOwnProperty(namespace)) {
                window[namespace] = {};
              }
              if (window[namespace] && !window[namespace].hasOwnProperty(pkg)) {
                window[namespace][pkg] = [];
              }
              if (Array.isArray(window[namespace][pkg])) {
                var data = ${serialize(dataWithUuid)};
                window[namespace][pkg].push(data);
              }
            }
          })()
        </script>
        <div id=${uuid}></div>
        ${_.map(chunks, chunk => {
          
          //...
    }).join('')}
        ${_.map(bundles, bundle => {
          
          //...
    }).join('')}
      `
    }
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">buildEmbeddedCode</span><span class="token punctuation">(</span><span class="token parameter">data<span class="token operator">:</span> <span class="token punctuation">{</span> chapters<span class="token operator">:</span> any<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> embeddedItems<span class="token operator">:</span> any<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> isFullWidth<span class="token operator">:</span> boolean<span class="token punctuation">;</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> webpackAssets<span class="token operator">:</span> <span class="token punctuation">{</span> chunks<span class="token operator">:</span> string<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> bundles<span class="token operator">:</span> string<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token punctuation">}</span></span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">string</span></code><div class="typing-tooltip-markup"><em>@export</em><br><br><em>@param</em> <code>data</code> — Data for Dual Channel Root React Component<br><br><em>@param</em> <code>webpackAssets</code> — webpack bundles and chunks<br><br><em>@returns</em> — embedded code</div></pre>
    /twreporter/orangutan-monorepo mit
    0
  • const search = async (req, res, next) => {
    	
    	//...
    if (!(await fs.isDir(req.absolute))) return next()
    	if (accepts(req).type('html') !== 'html') return next() // todo: support JSON & plain text
    
    	let results = []
    	
    	//...
    }
    
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">module</span> search <span class="token keyword">const</span> search<span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token punctuation">(</span>req<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">,</span> res<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">,</span> next<span class="token operator">:</span> <span class="token builtin">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 builtin">any</span><span class="token operator">></span><span class="token punctuation">;</span> supported<span class="token operator">:</span> <span class="token builtin">boolean</span><span class="token punctuation">;</span> <span class="token punctuation">}</span></code></pre>
    /derhuerst/casket ISC
    0
  • const reactIntlLocaleMessages = function (req, res, next) {
        const accept = accepts(req);
        const locale = accept.language(languages) || "en";
        req.locale = locale;
        req.localeDataScript = getLocaleDataScript(locale);
        req.messages = getMessages(locale);
        next();
    };
    
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">const</span> <span class="token function-variable function">reactIntlLocaleMessages</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token parameter">req<span class="token operator">:</span> any<span class="token punctuation">,</span> res<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 keyword">void</span></code></pre>
    /Enalmada/next-reason-boilerplate MIT
    0
  • function Request (ctx) {
        this.ctx = ctx
        this.req = ctx.req
        this.res = ctx.res
        this.accept = accepts(ctx.req)
        this.originalUrl = ctx.req.url
      }
      
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>local <span class="token keyword">function</span><span class="token punctuation">)</span> <span class="token function">Request</span><span class="token punctuation">(</span>ctx<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span></code></pre>
    /toajs/toa mit
    0
  • function build (req) {
      
      //...
    req.accepts = function reqAccepts (...args) {
        const accept = accepts(this)
        return accept.types.apply(accept, args)
      }
    
      req.acceptsEncodings = function (...args) {
        const accept = accepts(this)
        return accept.encodings.apply(accept, args)
      }
    
      
    
      //...
    }
    
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token keyword">function</span> <span class="token function">build</span><span class="token punctuation">(</span><span class="token parameter">req<span class="token operator">:</span> any</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">any</span></code></pre>
    /fyrejet/fyrejet MIT
    0
  • constructor(event) {
        
        //...
    this.ips = (this.get('X-Forwarded-For') || '').split(', ');
        this.ip = this.ips[0];
        this.host = this.get('X-Forwarded-Host') || this.hostname;
        this.xhr = (this.get('X-Requested-With') || '').toLowerCase() === 'xmlhttprequest';
    
        this.url = `${this.headers}${this.path}`;
    
        this.event = event;
        this.accept = accepts(this);
    
        this.push(event.body);
        this.push(null);
      }
    
      
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript">constructor <span class="token function">Request</span><span class="token punctuation">(</span>event<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">)</span><span class="token operator">:</span> Request</code></pre>
    /muratcorlu/lambda-expressless mit
    0
  • var accepts = require('accepts')
    var http = require('http')
     
    function app (req, res) {
      var accept = accepts(req)
     
      // the order of this list is significant; should be server preferred order
    // the order of this list is significant; should be server preferred order
      switch (accept.type(['json', 'html'])) {
        case 'json':
          res.setHeader('Content-Type', 'application/json')
          res.write('{"hello":"world!"}')
          break
        case 'html':
          res.setHeader('Content-Type', 'text/html')
          res.write('<b>hello, world!</b>')
          break
        default:
          // the fallback is text/plain, so no need to specify it above
    // the fallback is text/plain, so no need to specify it above
          res.setHeader('Content-Type', 'text/plain')
          res.write('hello, world!')
          break
      }
     
      res.end()
    }
     
    http.createServer(app).listen(3000)
    <pre class="typing-tooltip"><code data-language="javascript" class="language-javascript"><span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">function</span> <span class="token function">accepts</span><span class="token punctuation">(</span><span class="token parameter">req<span class="token operator">:</span> IncomingMessage</span><span class="token punctuation">)</span><span class="token operator">:</span> accepts<span class="token punctuation">.</span><span class="token function">Accepts</span> <span class="token punctuation">(</span>alias<span class="token punctuation">)</span> <span class="token keyword">namespace</span> accepts <span class="token keyword">import</span> accepts</code></pre>
    Docs
    0
  • const stripe = require('stripe')('sk_test_1J2uTY2eZvKYlo2CP3QopFjO');
    
    const quote = await stripe.quotes.accept(
      'qt_1J2uTY2eZvKYlo2CP3QopFjO'
    );
    Docs
    0
  • const stripe = require('stripe')('sk_test_1J2uTY2eZvKYlo2CP3QopFjO');
    
    const quote = await stripe.quotes.acceptQuote(
      'qt_1J2uTY2eZvKYlo2CP3QopFjO'
    );
    Docs
    0
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples