当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript querystring.unescape函数代码示例

本文整理汇总了TypeScript中querystring.unescape函数的典型用法代码示例。如果您正苦于以下问题:TypeScript unescape函数的具体用法?TypeScript unescape怎么用?TypeScript unescape使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了unescape函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: listener

export function listener(request, response): void {
  const urlParts = url.parse(request.url, true);
  if (request.method === "GET") {
    const filename = querystring.unescape(urlParts.pathname.substring(1));
    db.filesCollection.findOne({ _id: filename }, (err, file) => {
      if (err) {
        response.writeHead(500, { Connection: "close" });
        response.end(`${err.name}: ${err.message}`);
        throw err;
      }

      if (!file) {
        response.writeHead(404);
        response.end();
        return;
      }

      response.writeHead(200, {
        "Content-Type": file.contentType || "application/octet-stream",
        "Content-Length": file.length
      });

      const bucket = new GridFSBucket(db.client.db());
      const downloadStream = bucket.openDownloadStreamByName(filename);
      downloadStream.pipe(response);
    });
  } else {
    response.writeHead(405, { Allow: "GET" });
    response.end("405 Method Not Allowed");
  }
}
开发者ID:zaidka,项目名称:genieacs,代码行数:31,代码来源:fs.ts

示例2: function

        this.renderer.link = function(href, title, text) {
            if (!href) {
                return marked.Renderer.prototype.link.call(this, href, title, text);
            }

            if (this.options.sanitize) {
                try {
                    const prot = decodeURIComponent(unescape(href))
                        .replace(/[^\w:]/g, '')
                        .toLowerCase();
                    if (prot.startsWith('javascript:') || prot.startsWith('vbscript:')) {
                        return '';
                    }
                } catch (e) {
                    return '';
                }
            }

            let onclick = 'cancelClick(event)';
            if (href.startsWith('http://') || href.startsWith('https://')) {
                onclick = 'openLinkWithExternalBrowser(event)';
            } else if (re_ext.test(href)) {
                onclick = 'openMarkdownLink(event)';
            } else if (href.indexOf('#') !== -1) {
                onclick = 'openHashLink(event)';
            }

            self.link_id += 1;
            const id = `md-link-${self.link_id}`;
            self.tooltips += `<paper-tooltip for="${id}" offset="0">${he.encode(href)}</paper-tooltip>`;

            return title !== null ?
                `<a id="${id}" href="${href}" onclick="${onclick}" title=${title}>${text}</a>` :
                `<a id="${id}" href="${href}" onclick="${onclick}">${text}</a>`;
        };
开发者ID:WondermSwift,项目名称:Shiba,代码行数:35,代码来源:markdown-preview.ts

示例3: openMarkdownLink

/* tslint:disable:no-unused-variable */
function openMarkdownLink(event: MouseEvent) {
/* tslint:enable:no-unused-variable */
    event.preventDefault();

    let target = event.target as HTMLAnchorElement;
    while (target !== null) {
        if (target.href) {
            break;
        }
        target = target.parentElement as HTMLAnchorElement;
    }
    if (target === null) {
        console.log('openMarkdownLink(): No target <a> was found', event);
        return;
    }

    let path = unescape(target.href);
    if (path.startsWith('file://')) {
        path = path.slice(7); // Omit 'file://'
    }

    const hash_idx = path.indexOf('#');
    if (hash_idx !== -1) {
        path = path.slice(0, hash_idx);
    }

    if (element_env.openMarkdownDoc) {
        element_env.openMarkdownDoc(path, event.ctrlKey || event.metaKey);
    } else {
        console.log('openMarkdownDoc() is not defined!! Link ignored: ' + path);
    }
}
开发者ID:WondermSwift,项目名称:Shiba,代码行数:33,代码来源:markdown-preview.ts

示例4: buildRequestAccessTokenUrl

/**
 * Build url string to request access token, optionally with given query parameters.
 *
 * @param accessTokenEndpoint
 * @param queryParams - key-value pairs which will be added as query parameters
 * @returns {string}
 */
function buildRequestAccessTokenUrl(accessTokenEndpoint: string, queryParams?: Object): string {

  if (queryParams !== undefined) {
    const queryString = qs.stringify(queryParams);

    // we are unescaping again since we did not escape before using querystring and we do not want to break anything
    const unescapedQueryString = qs.unescape(queryString);

    return `${accessTokenEndpoint}?${unescapedQueryString}`;
  } else {
    return accessTokenEndpoint;
  }
}
开发者ID:zalando-incubator,项目名称:lib-oauth-tooling,代码行数:20,代码来源:oauth-tooling.ts

示例5: createAuthCodeRequestUri

/**
 * Returns URI to request authorization code with the given parameters.
 *
 * @param authorizationEndpoint - OAuth authorization endpoint
 * @param redirectUri - absolute URI specifying the endpoint the authorization code is responded
 * @param clientId - client id of requesting application
 * @param queryParams - optional set of key-value pairs which will be added as query parameters to the request
 * @returns {string}
 */
function createAuthCodeRequestUri(authorizationEndpoint: string,
                                  redirectUri: string,
                                  clientId: string,
                                  queryParams?: { [index: string]: string }): string {

  const _queryParams = {
    'client_id': clientId,
    'redirect_uri': redirectUri,
    'response_type': 'code',
    ...queryParams
  };

  const queryString = qs.stringify(_queryParams);
  // we are unescaping again since we did not escape before using querystring and we do not want to break anything
  const unescapedQueryString = qs.unescape(queryString);

  return `${authorizationEndpoint}?${unescapedQueryString}`;
}
开发者ID:zalando-incubator,项目名称:lib-oauth-tooling,代码行数:27,代码来源:oauth-tooling.ts

示例6: function

  function(req, res) {
    var fqn = querystring.unescape(req.path.substring('/pageDetailsByFQN/'.length));
    log.debug("Getting page details with name: " + fqn);
    queryPermissionWrapper(
      Page.findOne({fullyQualifiedName:fqn}), req.user)
      .exec(function(err, page) {
        log.debug("Got page: " + JSON.stringify(page));
        if (page) {
          fetchPageDetailsForPage(
            page,
            function(pageDetails) {
              res.status(200).type("application/json").send(JSON.stringify(pageDetails));
            },
            function(error) {
              log.error(error);
              res.status(500).end();
            });
        } else {
          Page.findOne({fullyQualifiedName:fqn}, function(err, permissionPage) {
            if (err) {
              log.error(err);
            }

            if (permissionPage) {
              fetchPageDetailsForPage(
                permissionPage,
                function(permissionPageDetails) {
                  permissionPageDetails.page.content = null;
                  permissionPageDetails.editable = false;
                  permissionPageDetails.viewable = false;
                  res.status(200).type("application/json").send(JSON.stringify(permissionPageDetails));
                },
                function(error) {
                  log.error(error);
                  res.status(500).end();
                });
            } else {
              log.error("User tried to access page with permission");
              res.status(404).end();
            }
          });
        }
      });
  }
开发者ID:MisterTea,项目名称:TidalWave,代码行数:44,代码来源:services.ts

示例7: openMarkdownLink

/* tslint:disable:no-unused-variable */
function openMarkdownLink(event: MouseEvent) {
    /* tslint:enable:no-unused-variable */
    event.preventDefault();

    let target = event.target as HTMLAnchorElement;
    while (target !== null) {
        if (target.href) {
            break;
        }
        target = target.parentElement as HTMLAnchorElement;
    }

    if (target === null) {
        console.log('openMarkdownLink(): No target <a> was found', event);
        return;
    }

    let path = unescape(target.href);
    if (path.startsWith('file://')) {
        path = path.slice(7); // Omit 'file://'
    }

    const hash_idx = path.indexOf('#');
    if (hash_idx !== -1) {
        path = path.slice(0, hash_idx);
    }

    if (process.platform === 'win32' && path[0] === '/') {
        // Chromium convert relative path of 'href' into absolute path.
        // But on Windows 'foo/bar' is converted into 'file:///C:/foo/bar'.
        // C:/foo/bar is correct. So strip first '/' here (#37).
        path = path.slice(1);
    }

    if (element_env.openMarkdownDoc) {
        element_env.openMarkdownDoc(path, event.ctrlKey || event.metaKey);
    } else {
        console.log('openMarkdownDoc() is not defined!! Link ignored: ' + path);
    }
}
开发者ID:Sheshouzuo,项目名称:Shiba,代码行数:41,代码来源:markdown-preview.ts

示例8:

        let eq: string;
        let options: querystring.ParseOptions;
        let result: SampleObject;

        result = querystring.parse<SampleObject>(str);
        result = querystring.parse<SampleObject>(str, sep);
        result = querystring.parse<SampleObject>(str, sep, eq);
        result = querystring.parse<SampleObject>(str, sep, eq, options);
    }

    {
        let str: string;
        let result: string;

        result = querystring.escape(str);
        result = querystring.unescape(str);
    }
}

////////////////////////////////////////////////////
/// path tests : http://nodejs.org/api/path.html
////////////////////////////////////////////////////

namespace path_tests {

    path.normalize('/foo/bar//baz/asdf/quux/..');

    path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
    // returns
    //'/foo/bar/baz/asdf'
开发者ID:Crevil,项目名称:DefinitelyTyped,代码行数:30,代码来源:node-tests.ts

示例9: Buffer

var ds: dgram.Socket = dgram.createSocket("udp4", (msg: Buffer, rinfo: dgram.RemoteInfo): void => {
});
var ai: dgram.AddressInfo = ds.address();
ds.send(new Buffer("hello"), 0, 5, 5000, "127.0.0.1", (error: Error, bytes: number): void => {
});

////////////////////////////////////////////////////
///Querystring tests : https://gist.github.com/musubu/2202583
////////////////////////////////////////////////////

var original: string = 'http://example.com/product/abcde.html';
var escaped: string = querystring.escape(original);
console.log(escaped);
// http%3A%2F%2Fexample.com%2Fproduct%2Fabcde.html
var unescaped: string = querystring.unescape(escaped);
console.log(unescaped);
// http://example.com/product/abcde.html

////////////////////////////////////////////////////
/// path tests : http://nodejs.org/api/path.html
////////////////////////////////////////////////////

namespace path_tests {

    path.normalize('/foo/bar//baz/asdf/quux/..');

    path.join('/foo', 'bar', 'baz/asdf', 'quux', '..');
    // returns
    //'/foo/bar/baz/asdf'
开发者ID:demurgos,项目名称:env-node,代码行数:29,代码来源:index.ts

示例10: getBody

  request.addListener("end", () => {
    const body = getBody();
    const urlParts = url.parse(request.url, true);
    if (PRESETS_REGEX.test(urlParts.pathname)) {
      const presetName = querystring.unescape(
        PRESETS_REGEX.exec(urlParts.pathname)[1]
      );
      if (request.method === "PUT") {
        const preset = JSON.parse(body.toString());
        preset._id = presetName;
        db.presetsCollection.replaceOne(
          { _id: presetName },
          preset,
          { upsert: true },
          err => {
            if (err) return void throwError(err, response);

            cache.del("presets_hash", err => {
              if (err) return void throwError(err, response);

              response.writeHead(200);
              response.end();
            });
          }
        );
      } else if (request.method === "DELETE") {
        db.presetsCollection.deleteOne({ _id: presetName }, err => {
          if (err) return void throwError(err, response);

          cache.del("presets_hash", err => {
            if (err) return void throwError(err, response);

            response.writeHead(200);
            response.end();
          });
        });
      } else {
        response.writeHead(405, { Allow: "PUT, DELETE" });
        response.end("405 Method Not Allowed");
      }
    } else if (OBJECTS_REGEX.test(urlParts.pathname)) {
      const objectName = querystring.unescape(
        OBJECTS_REGEX.exec(urlParts.pathname)[1]
      );
      if (request.method === "PUT") {
        const object = JSON.parse(body.toString());
        object._id = objectName;
        db.objectsCollection.replaceOne(
          { _id: objectName },
          object,
          { upsert: true },
          err => {
            if (err) return void throwError(err, response);

            cache.del("presets_hash", err => {
              if (err) return void throwError(err, response);

              response.writeHead(200);
              response.end();
            });
          }
        );
      } else if (request.method === "DELETE") {
        db.objectsCollection.deleteOne({ _id: objectName }, err => {
          if (err) return void throwError(err, response);

          cache.del("presets_hash", err => {
            if (err) return void throwError(err, response);

            response.writeHead(200);
            response.end();
          });
        });
      } else {
        response.writeHead(405, { Allow: "PUT, DELETE" });
        response.end("405 Method Not Allowed");
      }
    } else if (PROVISIONS_REGEX.test(urlParts.pathname)) {
      const provisionName = querystring.unescape(
        PROVISIONS_REGEX.exec(urlParts.pathname)[1]
      );
      if (request.method === "PUT") {
        const object = {
          _id: provisionName,
          script: body.toString()
        };

        try {
          new vm.Script(`"use strict";(function(){\n${object.script}\n})();`);
        } catch (err) {
          response.writeHead(400);
          response.end(`${err.name}: ${err.message}`);
          return;
        }

        db.provisionsCollection.replaceOne(
          { _id: provisionName },
          object,
          { upsert: true },
          err => {
//.........这里部分代码省略.........
开发者ID:zaidka,项目名称:genieacs,代码行数:101,代码来源:nbi.ts


注:本文中的querystring.unescape函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。