當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript validator.escape函數代碼示例

本文整理匯總了TypeScript中validator.escape函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript escape函數的具體用法?TypeScript escape怎麽用?TypeScript escape使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了escape函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: pNext

vApp.use(function(pRequest, pResponse, pNext) {
    // Allow access control origin
    let vAllow: string;
    let vOrigin: string = pRequest.get('origin');
    if (vOrigin == 'http://localhost:3000') {
        vAllow = 'http://localhost:3000';
    }
    if(vAllow) {
         pResponse.header('Access-Control-Allow-Origin', vAllow);
    }
    pResponse.header('Access-Control-Allow-Credentials', 'true');
    pResponse.header('Access-Control-Allow-Headers', 
        'Access-Control-Allow-Origin, X-Requested-With, Content-Type, Accept,Authorization,Proxy-Authorization,X-session');
    pResponse.header('Access-Control-Allow-Methods','GET,PUT,DELETE,POST');
    if(
        pRequest.path !== '/service/login' && 
        pRequest.path !== '/service/login/MPIN' &&
        pRequest.path !== '/service/generateCallPlan' &&
        pRequest.path.indexOf('/testing') !== -1 //bypass token for testing purpose

    ){
        if(pRequest.method !== 'OPTIONS') {
            // all request to service will validate token except login & logout
            var vToken = '';
            try{
                if(pRequest.cookies['accessToken']){//accessed from web
                    vToken = vCookieParser.JSONCookies(pRequest.cookies).accessToken;
                }else{ // accessed from mobile
                    vToken = pRequest.get('Authorization');
                    vToken = vToken.replace('Bearer ','');
                }
                console.log(vToken);
                var jwt = vTokenSvc.verifyToken(vToken);
                pResponse.locals.jwt = jwt;
            }catch(pErr){
                console.log('Error while parsing token : ' + pErr);
                pResponse.sendStatus(403);
            }
        }
    }
    // Sanitize all the parameter send with POST request
    if(pRequest.method === 'POST') {
        for(let param in pRequest.body) {
            pRequest.body[param] = vValidator.escape(pRequest.body[param]);
        }
    }
    pNext();
});
開發者ID:acndavidd,項目名稱:iDSP-admin,代碼行數:48,代碼來源:main.ts

示例2:

  result = validator.isWhitelisted('sample', ['a', 'b', 'c']);

  result = validator.matches('foobar', 'foo/i');
  result = validator.matches('foobar', 'foo', 'i');
}

// **************
// * Sanitizers *
// **************

{
  let result: string;

  result = validator.blacklist('sample', 'abc');

  result = validator.escape('sample');

  result = validator.unescape('sample');

  result = validator.ltrim('sample');
  result = validator.ltrim('sample', ' ');

  let normalizeEmailOptions: ValidatorJS.NormalizeEmailOptions;
  let normalizeResult: string | false;
  normalizeResult = validator.normalizeEmail('sample');
  normalizeResult = validator.normalizeEmail('sample', normalizeEmailOptions);

  result = validator.rtrim('sample');
  result = validator.rtrim('sample', ' ');

  result = validator.stripLow('sample');
開發者ID:Crevil,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:validator-tests.ts


注:本文中的validator.escape函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。