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


TypeScript file-system.path類代碼示例

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


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

示例1: function

export var test_XmlParser_IntegrationTest = function () {
    var actualResult = "";
    var xmlParser = new xmlModule.XmlParser(function (event: xmlModule.ParserEvent) {
        if (event.eventType === xmlModule.ParserEventType.Text && event.data.trim() === "") {
            // Ignore ignorable whitespace.
            return;
        }

        actualResult += event.toString();
    });

    var file = fs.File.fromPath(fs.path.join(__dirname, "xml.xml"));
    var xmlString = file.readTextSync();
    xmlString = xmlString.replace(/(\r\n|\n|\r)/gm, "\n");
    xmlParser.parse(xmlString);

    var expectedResult: string;
    file = fs.File.fromPath(fs.path.join(__dirname, "xml.expected"));
    expectedResult = file.readTextSync();

    var i;
    var maxLength = Math.max(actualResult.length, expectedResult.length);
    for (i = 0; i < maxLength; i++) {

        var actualChar;
        var actualCharCode;
        if (i <= actualResult.length) {
            actualChar = actualResult.charAt(i);
            actualCharCode = actualResult.charCodeAt(i);
        }
        else {
            actualChar = "undefined";
            actualCharCode = "undefined";
        }

        var expectedChar;
        var expectedCharCode;
        if (i <= expectedResult.length) {
            expectedChar = expectedResult.charAt(i);
            expectedCharCode = expectedResult.charCodeAt(i);
        }
        else {
            expectedChar = "undefined";
            expectedCharCode = "undefined";
        }

        TKUnit.assert(actualCharCode === expectedCharCode, "At index " + i + ": Actual character is " + actualChar + "[" + actualCharCode + "]; Expected character is: " + expectedChar + "[" + expectedCharCode + "]");
    }
};
開發者ID:triniwiz,項目名稱:NativeScript,代碼行數:49,代碼來源:xml-parser-tests.ts

示例2: test_DummyTestForSnippetOnly

export function test_DummyTestForSnippetOnly() {
    // >> image-cache-request-images
    var cache = new imageCacheModule.Cache();
    cache.placeholder = imageSource.fromFile(fs.path.join(__dirname, "res/no-image.png"));
    cache.maxRequests = 5;
    
    // Enable download while not scrolling
    cache.enableDownload();
    
    var imgSouce: imageSource.ImageSource;
    var url = "https://github.com/NativeScript.png";
    // Try to read the image from the cache
    var image = cache.get(url);
    if (image) {
        // If present -- use it.
        imgSouce = imageSource.fromNativeSource(image);
    }
    else {
        // If not present -- request its download.
        cache.push({
            key: url,
            url: url,
            completed: (image: any, key: string) => {
                if (url === key) {
                    imgSouce = imageSource.fromNativeSource(image);
                }
            }
        });
    }

    // Disable download while scrolling
    cache.disableDownload();
    // << image-cache-request-images
}
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:34,代碼來源:image-cache-tests.ts

示例3: function

export var test_getContentAsFile = function (done) {
    var result;

    // >> http-get-urlfile-content
    var filePath = fs.path.join(fs.knownFolders.documents().path, "test.png");
    http.getFile("https://httpbin.org/image/png?testQuery=query&anotherParam=param", filePath).then(function (r) {
        //// Argument (r) is File!
        // >> (hide)
        result = r;
        try {
            TKUnit.assert(result instanceof fs.File, "Result from getFile() should be valid File object!");
            done(null);
        }
        catch (err) {
            done(err);
        }
        // << (hide)
    }, function (e) {
        //// Argument (e) is Error!
        // >> (hide)
        done(e);
        // << (hide)
    });
    // << http-get-urlfile-content
};
開發者ID:sitefinitysteve,項目名稱:NativeScript,代碼行數:25,代碼來源:http-tests.ts

示例4: getPlaceholderImageDrawable

  public static getPlaceholderImageDrawable(value) {

    let fileName = "",
      drawable = null;


    if (types.isString(value)) {

      value = value.trim();

      if (utils.isFileOrResourcePath(value)) {


        if (0 === value.indexOf("~/")) {
          fileName = fs.path.join(fs.knownFolders.currentApp().path, value.replace("~/", ""));
          drawable = android.graphics.drawable.Drawable.createFromPath(fileName);
        } else if (0 === value.indexOf("res")) {
          fileName = value;
          let res = utils.ad.getApplicationContext().getResources();
          let resName = fileName.substr(utils.RESOURCE_PREFIX.length);
          let identifier = res.getIdentifier(resName, 'drawable', utils.ad.getApplication().getPackageName());
          drawable = res.getDrawable(identifier);
        }


      }
    }

    return drawable;

  }
開發者ID:VideoSpike,項目名稱:nativescript-web-image-cache,代碼行數:31,代碼來源:helpers.ts

示例5: function

export var test_leading_slash_is_not_returned = function () {
    var parts = ["app", "tns_modules", "fileName"];
    var expected = parts.join("/");
    var path = fs.path.join(...parts);

    TKUnit.assertEqual(path, expected, "Leading slash should not be part of the path");
}
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:7,代碼來源:file-system-access-tests.ts

示例6: test_MultiParserTemplate

export function test_MultiParserTemplate() {
    const file = fs.File.fromPath(fs.path.join(__dirname, "itemTemplates.xml"));
    const xml = file.readTextSync();

    const view: any = builder.parse(xml);
    TKUnit.assertNotNull(view.items)
    TKUnit.assertEqual(view.items.length, 1);
}
開發者ID:triniwiz,項目名稱:NativeScript,代碼行數:8,代碼來源:xml-parser-tests.ts

示例7: testSaveToFile_WithQuality

export function testSaveToFile_WithQuality() {
    const img = imageSource.fromFile(imagePath);
    const folder = fs.knownFolders.documents();
    const path = fs.path.join(folder.path, "test.png");
    const saved = img.saveToFile(path, "png", 70);
    TKUnit.assert(saved, "Image not saved to file");
    TKUnit.assert(fs.File.exists(path), "Image not saved to file");
}
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:8,代碼來源:image-source-tests.ts

示例8: resolveRelativeUrls

 private resolveRelativeUrls(url: string): string {
     // Angular assembles absolute URLs and prefixes them with //
     if (url.indexOf("/") !== 0) {
         // Resolve relative URLs based on the app root.
         return path.join(this.fs.currentApp().path, url);
     } else {
         return url;
     }
 }
開發者ID:NathanWalker,項目名稱:nativescript-angular,代碼行數:9,代碼來源:resource-loader.ts

示例9:

 source.fromAsset(imageAsset).then((source) => {
     let folder = fs.knownFolders.documents().path;
     let fileName = "test.png"
     let path = fs.path.join(folder, fileName);
     let saved = source.saveToFile(path, "png");
     if(saved){
        console.log("saved image")
     }
 })
開發者ID:sitefinitysteve,項目名稱:NativeScript,代碼行數:9,代碼來源:image-source-snippet.ts

示例10:

 source.fromAsset(imageAsset).then((imageSource) => {
     let folder = fs.knownFolders.documents().path;
     let fileName = "test.png";
     let path = fs.path.join(folder, fileName);
     let saved = imageSource.saveToFile(path, "png");
     if (saved) {
         console.log("Image saved successfully!");
     }
 })
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:9,代碼來源:image-source-snippet.ts


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