• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript core.relative函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: buildRelativePath

export function buildRelativePath(from: string, to: string): string {
  from = normalize(from);
  to = normalize(to);

  // Convert to arrays.
  const fromParts = from.split('/');
  const toParts = to.split('/');

  // Remove file names (preserving destination)
  fromParts.pop();
  const toFileName = toParts.pop();

  const relativePath = relative(normalize(fromParts.join('/')), normalize(toParts.join('/')));
  let pathPrefix = '';

  // Set the path prefix for same dir or child dir, parent dir starts with `..`
  if (!relativePath) {
    pathPrefix = '.';
  } else if (!relativePath.startsWith('.')) {
    pathPrefix = `./`;
  }
  if (pathPrefix && !pathPrefix.endsWith('/')) {
    pathPrefix += '/';
  }

  return pathPrefix + (relativePath ? relativePath + '/' : '') + toFileName;
}
开发者ID:baconwaffles,项目名称:angular-cli,代码行数:27,代码来源:find-module.ts


示例2: resolve

  const isInside = (base: Path, potential: Path): boolean => {
    const absoluteBase = resolve(workspace.root, base);
    const absolutePotential = resolve(workspace.root, potential);
    const relativePotential = relative(absoluteBase, absolutePotential);
    if (!relativePotential.startsWith('..') && !isAbsolute(relativePotential)) {
      return true;
    }

    return false;
  };
开发者ID:nickroberts,项目名称:angular-cli,代码行数:10,代码来源:config.ts


示例3: importPath

export function importPath(from: Path, to: Path): string {
  const relativePath = relative(dirname(from), dirname(to));

  if (relativePath.startsWith('.')) {
    return relativePath;
  }

  if (!relativePath) {
    return generateCurrentDirImport(basename(to));
  }

  return generateCurrentDirImport(join(relativePath, basename(to)));
}
开发者ID:kevinheader,项目名称:nebular,代码行数:13,代码来源:path.ts


示例4: actions

  get actions(): Action[] {
    const scopedActions = [];

    for (const action of this._base.actions) {
      if (!action.path.startsWith(this._root.scope + '/')) {
        continue;
      }

      if (action.kind !== 'r') {
        scopedActions.push({
          ...action,
          path: join(NormalizedRoot, relative(this._root.scope, action.path)),
        });
      } else if (action.to.startsWith(this._root.scope + '/')) {
        scopedActions.push({
          ...action,
          path: join(NormalizedRoot, relative(this._root.scope, action.path)),
          to: join(NormalizedRoot, relative(this._root.scope, action.to)),
        });
      }
    }

    return scopedActions;
  }
开发者ID:angular,项目名称:angular-cli,代码行数:24,代码来源:scoped.ts


示例5: _recursiveList

  private async _recursiveList(path: Path, items: string[]): Promise<string[]> {
    const fragments = await this._host.list(path).toPromise();

    for (const fragment of fragments) {
      const item = join(path, fragment);

      if (await this._host.isDirectory(item).toPromise()) {
        await this._recursiveList(item, items);
      } else {
        items.push('/' + relative(normalize(this.base), item));
      }
    }

    return items;
  }
开发者ID:angular,项目名称:angular-cli,代码行数:15,代码来源:index.ts


示例6: normalize

    .map(assetPattern => {
      // Normalize string asset patterns to objects.
      if (typeof assetPattern === 'string') {
        const assetPath = normalize(assetPattern);
        const resolvedAssetPath = resolve(root, assetPath);

        // Check if the string asset is within sourceRoot.
        if (!resolvedAssetPath.startsWith(resolvedSourceRoot)) {
          throw new MissingAssetSourceRootException(assetPattern);
        }

        let glob: string, input: Path, output: Path;
        let isDirectory = false;

        try {
          isDirectory = host.isDirectory(resolvedAssetPath);
        } catch {
          isDirectory = true;
        }

        if (isDirectory) {
          // Folders get a recursive star glob.
          glob = '**/*';
          // Input directory is their original path.
          input = assetPath;
        } else {
          // Files are their own glob.
          glob = basename(assetPath);
          // Input directory is their original dirname.
          input = dirname(assetPath);
        }

        // Output directory for both is the relative path from source root to input.
        output = relative(resolvedSourceRoot, resolve(root, input));

        // Return the asset pattern in object format.
        return { glob, input, output };
      } else {
        // It's already an AssetPatternObject, no need to convert.
        return assetPattern;
      }
    });
开发者ID:DevIntent,项目名称:angular-cli,代码行数:42,代码来源:normalize-asset-patterns.ts


示例7: tap

      tap((output: BrowserBuilderOutput) => {
        const path = relative(host.root(), join(normalize(output.outputPath), 'main.js'));
        const content = virtualFs.fileBufferToString(
          host.scopedSync().read(path),
        );

        switch (buildCount) {
          case 1:
            expect(content).toContain('var a = 2');
            host.writeMultipleFiles({
              'src/my-js-file.js': `console.log(1); export const a = 1;`,
            });
            break;
          case 2:
            expect(content).toContain('var a = 1');
            break;
        }

        buildCount++;
      }),
开发者ID:angular,项目名称:angular-cli,代码行数:20,代码来源:allow-js_spec_large.ts


示例8: map

          map(isDirectory => {
            let glob: string, input: Path, output: Path;
            if (isDirectory) {
              // Folders get a recursive star glob.
              glob = '**/*';
              // Input directory is their original path.
              input = assetPath;
            } else {
              // Files are their own glob.
              glob = basename(assetPath);
              // Input directory is their original dirname.
              input = dirname(assetPath);
            }

            // Output directory for both is the relative path from source root to input.
            output = relative(resolvedSourceRoot, resolve(root, input));

            // Return the asset pattern in object format.
            return { glob, input, output };
          }),
开发者ID:baconwaffles,项目名称:angular-cli,代码行数:20,代码来源:normalize-asset-patterns.ts


示例9: return

  return (host: Tree) => {
    if (!options.module) {
      return host;
    }

    const modulePath = normalize('/' + options.module);

    const text = host.read(modulePath);
    if (text === null) {
      throw new SchematicsException(`File ${modulePath} does not exist.`);
    }
    const sourceText = text.toString('utf-8');
    const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);

    const importModulePath = normalize(
      `/${options.path}/`
      + (options.flat ? '' : strings.dasherize(options.name) + '/')
      + strings.dasherize(options.name)
      + '.module',
    );
    const relativeDir = relative(dirname(modulePath), dirname(importModulePath));
    const relativePath = (relativeDir.startsWith('.') ? relativeDir : './' + relativeDir)
      + '/' + basename(importModulePath);
    const changes = addImportToModule(source, modulePath,
                                      strings.classify(`${options.name}Module`),
                                      relativePath);

    const recorder = host.beginUpdate(modulePath);
    for (const change of changes) {
      if (change instanceof InsertChange) {
        recorder.insertLeft(change.pos, change.toAdd);
      }
    }
    host.commitUpdate(recorder);

    return host;
  };
开发者ID:iwe7,项目名称:devkit,代码行数:37,代码来源:index.ts


示例10: buildRelativePath

export function buildRelativePath(from: string, to: string): string {
  const {
    path: fromPath,
    filename: fromFileName,
    directory: fromDirectory,
  } = parsePath(from);
  const {
    path: toPath,
    filename: toFileName,
    directory: toDirectory,
  } = parsePath(to);
  const relativePath = relative(fromDirectory, toDirectory);
  const fixedRelativePath = relativePath.startsWith('.')
    ? relativePath
    : `./${relativePath}`;

  return !toFileName || toFileName === 'index.ts'
    ? fixedRelativePath
    : `${
        fixedRelativePath.endsWith('/')
          ? fixedRelativePath
          : fixedRelativePath + '/'
      }${convertToTypeScriptFileName(toFileName)}`;
}
开发者ID:AlexChar,项目名称:platform,代码行数:24,代码来源:find-module.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript core.resolve函数代码示例发布时间:2022-05-28
下一篇:
TypeScript core.parseJsonAst函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap