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


TypeScript file-system.path類代碼示例

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


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

示例1: Promise

    return new Promise(function (resolve, reject) {
      try {
        if (!options.image) {
          reject("no image specified");
          return;
        }

        const lang = options.language || "eng";

        const progressNotifier = new com.googlecode.tesseract.android.TessBaseAPI.ProgressNotifier({
          onProgressValues: (progressValues) => {
            if (options.onProgress) {
              options.onProgress(progressValues.getPercent());
            } else {
              console.log("Progress: " + progressValues.getPercent());
            }
          }
        });

        const tessBaseAPI = new com.googlecode.tesseract.android.TessBaseAPI(progressNotifier);
        tessBaseAPI.setDebug(false);

        const tessfolder = fs.path.join(fs.knownFolders.currentApp().path, "tesseract");

        const initSuccess = tessBaseAPI.init(tessfolder, lang, com.googlecode.tesseract.android.TessBaseAPI.OEM_TESSERACT_ONLY);
        // const initSuccess = tessBaseAPI.init(tessfolder, lang, com.googlecode.tesseract.android.TessBaseAPI.OEM_DEFAULT);

        if (!initSuccess) {
          reject("init failed");
          return;
        }

        // see https://github.com/rmtheis/tess-two/blob/master/tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java#L53
        // tessBaseAPI.setPageSegMode(com.googlecode.tesseract.android.TessBaseAPI.PageSegMode.PSM_AUTO_OSD);
        // tessBaseAPI.setVariable(com.googlecode.tesseract.android.TessBaseAPI.VAR_SAVE_BLOB_CHOICES, com.googlecode.tesseract.android.TessBaseAPI.VAR_TRUE);

        if (options.whitelist) {
          tessBaseAPI.setVariable(com.googlecode.tesseract.android.TessBaseAPI.VAR_CHAR_WHITELIST, options.whitelist);
        }

        if (options.blacklist) {
          tessBaseAPI.setVariable(com.googlecode.tesseract.android.TessBaseAPI.VAR_CHAR_BLACKLIST, options.blacklist);
        }

        tessBaseAPI.setImage(options.image.android);
        const recognizedText = tessBaseAPI.getUTF8Text();

        tessBaseAPI.end();

        resolve({
          text: recognizedText
        });
      } catch (ex) {
        console.log("Error in ocr.retrieveText: " + ex);
        reject(ex);
      }
    });
開發者ID:EddyVerbruggen,項目名稱:nativescript-ocr,代碼行數:57,代碼來源:ocr.android.ts

示例2: resolve

 resolve(url: string, baseUrl: string): string {
     //Angular assembles absolute URL's and prefixes them with //
     if (url.indexOf("/") !== 0) {
         //Resolve relative URL's based on the app root.
         return path.join(baseUrl, url);
     } else {
         return url;
     }
 }
開發者ID:AhmedRagheb,項目名稱:nativescript-angular,代碼行數:9,代碼來源:xhr.ts

示例3: get

  get(url: string): Promise<string> {
      let appDir = knownFolders.currentApp().path;
      let templatePath = path.join(appDir, url);

      if (!File.exists(templatePath)) {
          throw new Error(`File ${url} does not exist.`);
      }
      let templateFile = File.fromPath(templatePath);
      return templateFile.readText();
  }
開發者ID:ImNitinNayar7,項目名稱:nativescript-angular,代碼行數:10,代碼來源:xhr.ts

示例4: loadStyles

function loadStyles() {
    var path = fs.path.join(fs.knownFolders.currentApp().path, cssPath);

    if (!fs.File.exists(path)) {
        throw new Error("Could not find code-highlight.css. Lookup path: " + path);
    }

    style = fs.File.fromPath(path).readTextSync((error) => {
        console.log("Error loading style file: " + error);
    });
};
開發者ID:phattranky,項目名稱:nativescript-marketplace-demo,代碼行數:11,代碼來源:code-page-view-model.ts

示例5: constructor

  constructor(protected path: string) {
    if (path.indexOf("~/") === 0) {
      this.path = path = fs.path.join(fs.knownFolders.currentApp().path, path.replace("~/", ""));
    }

    const documents = fs.knownFolders.currentApp();

    console.log('folder:', documents.path);

    fs.Folder.fromPath(fs.path.join(documents.path, '')).eachEntity(function (entity) {
      console.log('-', entity.name);
      // Return true to continue, or return false to stop the iteration.
      return true;
    });

    if (!fs.File.exists(path)) {
      console.error("Sound not initialized; file not found.");
      return;
    }
  };
開發者ID:m-abs,項目名稱:testing-nativescript,代碼行數:20,代碼來源:sound-common.ts

示例6: require

 toFile: (destinationFilePath?: string) => {
     var fs: typeof fsModule = require("file-system");
     var fileName = options.url;
     if (!destinationFilePath) {
         destinationFilePath = fs.path.join(fs.knownFolders.documents().path, fileName.substring(fileName.lastIndexOf('/') + 1));
     }
     if (data instanceof NSData) {
         data.writeToFileAtomically(destinationFilePath, true);
         return fs.File.fromPath(destinationFilePath);
     } else {
         reject(new Error(`Cannot save file with path: ${destinationFilePath}.`));
     }
 }
開發者ID:Prettycode-KC,項目名稱:NativeScript,代碼行數:13,代碼來源:http-request.ios.ts

示例7: Promise

    return new Promise((resolve, reject) => {
      try {
        let MediaPlayer = android.media.MediaPlayer;
        let audioPath;

        let fileName = isString(options.audioFile) ? options.audioFile.trim() : "";
        if (fileName.indexOf("~/") === 0) {
          fileName = fs.path.join(fs.knownFolders.currentApp().path, fileName.replace("~/", ""));
          console.log('fileName: ' + fileName);
          audioPath = fileName;
        }

        this.player = new MediaPlayer();
          
        this.player.setAudioStreamType(android.media.AudioManager.STREAM_MUSIC);         
        this.player.setDataSource(audioPath);
        this.player.prepareAsync();

        // On Complete
        this.player.setOnCompletionListener(new MediaPlayer.OnCompletionListener({
          onCompletion: (mp) => {
            options.completeCallback();
          }
        }));

        // On Error
        this.player.setOnErrorListener(new MediaPlayer.OnErrorListener({
          onError: (mp: any, what: number, extra: number) => {
            options.errorCallback();
          }
        }));

        // On Info
        this.player.setOnInfoListener(new MediaPlayer.OnInfoListener({
          onInfo: (mp: any, what: number, extra: number) => {
            options.infoCallback();
          }
        }))

        // On Prepared
        this.player.setOnPreparedListener(new MediaPlayer.OnPreparedListener({
          onPrepared: (mp) => {
            mp.start();
            resolve();
          }
        }));

      } catch (ex) {
        reject(ex);
      }
    });
開發者ID:dwilanang,項目名稱:nativescript-audio,代碼行數:51,代碼來源:player.ts

示例8: getFilenameFromUrl

export function getFilenameFromUrl(url: string) {
    const fs: typeof fsModule = require("file-system");
    const slashPos = url.lastIndexOf("/") + 1;
    const questionMarkPos = url.lastIndexOf("?");

    let actualFileName: string;
    if (questionMarkPos !== -1) {
        actualFileName = url.substring(slashPos, questionMarkPos);
    } else {
        actualFileName = url.substring(slashPos);
    }
    
    const result = fs.path.join(fs.knownFolders.documents().path, actualFileName);
    return result;
}
開發者ID:NathanWalker,項目名稱:NativeScript,代碼行數:15,代碼來源:http-request-common.ts

示例9: constructor

    constructor(example: examplesVM.Example) {
        super();

        var lastSlashIndex = example.path.lastIndexOf("/");
        var initialSelectedFile = example.path.substr(lastSlashIndex + 1) + ".xml";
        var path = example.path.substring(0, lastSlashIndex);
        path = fs.path.join(fs.knownFolders.currentApp().path, path.replace("~/", ""));
        console.log("Showing code for " + path);

        var folder = fs.Folder.fromPath(path);
        folder.getEntities().then((entities) => {
            entities = entities.filter((e) => (e instanceof fs.File));
            this.set("files", entities);
            this.selectFile(initialSelectedFile);
        });
        
        this.set("group", example.group);
    }
開發者ID:phattranky,項目名稱:nativescript-marketplace-demo,代碼行數:18,代碼來源:code-page-view-model.ts

示例10: loadCss

export function loadCss(cssFile?: string): Array<cssSelector.CssSelector> {
    if (!cssFile) {
        return undefined;
    }

    var result: Array<cssSelector.CssSelector>;

    var fs: typeof fileSystemModule = require("file-system");
    var styleScope: typeof styleScopeModule = require("ui/styling/style-scope");

    var cssFileName = fs.path.join(fs.knownFolders.currentApp().path, cssFile);
    if (fs.File.exists(cssFileName)) {
        var file = fs.File.fromPath(cssFileName);
        var applicationCss = file.readTextSync();
        if (applicationCss) {
            result = styleScope.StyleScope.createSelectorsFromCss(applicationCss, cssFileName);
        }
    }

    return result;
}
開發者ID:ImNitinNayar7,項目名稱:NativeScript,代碼行數:21,代碼來源:application-common.ts


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