How to use detect-indent - 9 common examples

To help you get started, we’ve selected a few detect-indent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / expo-cli / packages / package-manager / src / PackageManager.ts View on Github external
private async _patchAsync(
    specs: npmPackageArg.Result[],
    packageType: 'dependencies' | 'devDependencies'
  ) {
    const pkgPath = path.join(this.options.cwd || '.', 'package.json');
    const pkgRaw = await fs.readFile(pkgPath, { encoding: 'utf8', flag: 'r' });
    const pkg = JSON.parse(pkgRaw);
    specs.forEach(spec => {
      pkg[packageType] = pkg[packageType] || {};
      pkg[packageType][spec.name!] = spec.rawSpec;
    });
    await fs.writeJson(pkgPath, pkg, {
      spaces: detectIndent(pkgRaw).indent,
      EOL: detectNewline(pkgRaw),
    });
  }
}
github opencollective / opencollective-bot / src / actions / addPackageJsonFunding.ts View on Github external
function setIndent(packageJSON: string): string {
  return detectIndent(packageJSON).indent || '  '
}
github babel / babel / packages / babel-generator / src / index.js View on Github external
static normalizeOptions(code, opts, tokens) {
    let style = "  ";
    if (code) {
      let indent = detectIndent(code).indent;
      if (indent && indent !== " ") style = indent;
    }

    let format = {
      auxiliaryCommentBefore: opts.auxiliaryCommentBefore,
      auxiliaryCommentAfter: opts.auxiliaryCommentAfter,
      shouldPrintComment: opts.shouldPrintComment,
      retainLines: opts.retainLines,
      comments: opts.comments == null || opts.comments,
      compact: opts.compact,
      minified: opts.minified,
      concise: opts.concise,
      quotes: opts.quotes || CodeGenerator.findCommonStringDelimiter(code, tokens),
      indent: {
        adjustMultilineComment: true,
        style: style,
github forivall / tacoscript / packages / babylon-plugin-cst / src / plugin.js View on Github external
return function parseTopLevel() {
      let format = this.cstState.format;
      if (format.indent == null) format.indent = detectIndent(this.input);
      let ast = inner.apply(this, arguments);
      ast.format = format;
      postprocess(ast);
      return ast;
    };
  });
github expo / expo-cli / packages / expo-cli / src / PackageManager.ts View on Github external
async _patchAsync(
    specs: npmPackageArg.Result[],
    packageType: 'dependencies' | 'devDependencies'
  ) {
    const pkgPath = path.join(this.options.cwd || '.', 'package.json');
    const pkgRaw = await fs.readFile(pkgPath, { encoding: 'utf8', flag: 'r' });
    const pkg = JSON.parse(pkgRaw);
    specs.forEach(spec => {
      pkg[packageType] = pkg[packageType] || {};
      pkg[packageType][spec.name!] = spec.rawSpec;
    });
    await fs.writeJson(pkgPath, pkg, {
      spaces: detectIndent(pkgRaw).indent,
      EOL: detectNewline(pkgRaw),
    });
  }
}
github boltpkg / bolt / src / Config.js View on Github external
constructor(filePath: string, fileContents: string) {
    this.filePath = filePath;
    this.fileContents = fileContents;
    try {
      this.indent = detectIndent(fileContents).indent || '  ';
      this.newline = detectNewline(fileContents) || os.EOL;
      this.json = parseJson(fileContents);
    } catch (e) {
      if (e.name === 'JSONError') {
        logger.error(messages.errorParsingJSON(filePath), {
          emoji: '💥',
          prefix: false
        });
      }
      throw e;
    }
  }
github byCedric / semantic-release-expo / src / expo.ts View on Github external
export async function writeManifest(meta: ManifestMeta, manifest: Manifest) {
	const { indent } = detectIndent(meta.content) || { indent: DEFAULT_INDENT };
	const newline = detectNewline(meta.content) || DEFAULT_NEWLINE;

	await writeJson(meta.filename, { expo: manifest }, { spaces: indent, EOL: newline });
}
github teambit / bit / src / consumer / component / package-json-file.ts View on Github external
static async load(workspaceDir: PathOsBasedAbsolute, componentDir?: PathRelative = '.'): Promise {
    const filePath = composePath(componentDir);
    const filePathAbsolute = path.join(workspaceDir, filePath);
    const packageJsonStr = await PackageJsonFile.getPackageJsonStrIfExist(filePathAbsolute);
    if (!packageJsonStr) {
      return new PackageJsonFile({ filePath, fileExist: false, workspaceDir });
    }
    const packageJsonObject = PackageJsonFile.parsePackageJsonStr(packageJsonStr, componentDir);
    const indent = detectIndent(packageJsonStr).indent;
    const newline = detectNewline(packageJsonStr);
    return new PackageJsonFile({ filePath, packageJsonObject, fileExist: true, workspaceDir, indent, newline });
  }
github th0r / npm-upgrade / src / Config.js View on Github external
save() {
    const data = this[getData]();

    if (_.isEqual(data, this[storedData])) return;

    try {
      if (_.isEmpty(data)) {
        this.remove();
      } else {
        const {source: packageSource} = loadPackageJson();
        const {indent} = detectIndent(packageSource);

        writeFileSync(
          this[path],
          JSON.stringify(data, null, indent)
        );
      }
    } catch (err) {
      err.message = `Unable to update npm-upgrade config file: ${err.message}`;
      throw err;
    }
  }

detect-indent

Detect the indentation of code

MIT
Latest version published 2 years ago

Package Health Score

73 / 100
Full package analysis

Popular detect-indent functions