How to use detect-newline - 10 common examples

To help you get started, we’ve selected a few detect-newline 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 renke / import-sort / packages / import-sort / src / index.ts View on Github external
file?: string,
  options?: any,
): ISortResult {
  const items = addFallback(style, file, options || {})(StyleAPI);

  const buckets: Array> = items.map(() => []);

  const imports = parser.parseImports(code, {
    file,
  });

  if (imports.length === 0) {
    return {code, changes: []};
  }

  const eol = detectNewline.graceful(code);

  const changes: Array = [];

  // Fill buckets
  for (const imported of imports) {
    let sortedImport = imported;

    const index = items.findIndex(item => {
      sortedImport = sortNamedMembers(imported, item.sortNamedMembers);
      return !!item.match && item.match!(sortedImport);
    });

    if (index !== -1) {
      buckets[index].push(sortedImport);
    }
  }
github GitbookIO / markup-it / src / html / parse.js View on Github external
function splitLines(text, sep = detectNewLine(text) || '\n') {
    return List(text.split(sep));
}
github howtocards / frontend / src / lib / rich-text / extensions / hot-keys / code-block / on-paste-code-block.js View on Github external
const deserializeCode = (opts, text) => {
  const sep = detectNewline(text) || DEFAULT_NEWLINE

  const lines = List(text.split(sep)).map((line) =>
    Block.create({
      type: opts.line,
      nodes: [Text.create(line)],
    }),
  )

  const code = Block.create({
    type: opts.block,
    nodes: lines,
  })

  return code
}
github GitbookIO / slate-edit-code / lib / utils / deserializeCode.js View on Github external
function deserializeCode(opts: Options, text: string): Block {
    const sep = detectNewline(text) || DEFAULT_NEWLINE;

    const lines = List(text.split(sep)).map(line =>
        Block.create({
            type: opts.lineType,
            nodes: [Text.create(line)]
        })
    );

    const code = Block.create({
        type: opts.containerType,
        nodes: lines
    });

    return code;
}
github brumbrum-it / styled-components-stylefmt / src / index.js View on Github external
export default function (inputPath: string, options?: Options = {}) {
  const input = fs.readFileSync(inputPath).toString()

  const EOL = detectNewline(input)
  const escapedEOL = escapeStringRegexp(EOL)

  const closingTokens = [tokTypes.bracketR, tokTypes.braceR, tokTypes.braceBarR, tokTypes.parenR, tokTypes.backQuote]
    .map(({ label }) => label)
    .map(escapeStringRegexp)

  const closingRegexp = new RegExp(`^\\s*((?:${closingTokens.join('|')}|\\s)+)\\s*${closingTokens[1]}.*$`, 'm')

  const getClosingLineTokens = (line: string) => {
    const matches = line.match(closingRegexp)

    return matches ? matches[1] : ''
  }

  const lines = input.split(EOL)
  let output = input
github gulp-sourcemaps / gulp-sourcemaps / src / utils.js View on Github external
function getCommentFormatter(file) {
  var extension = file.relative.split('.').pop();
  var fileContents = file.contents.toString();
  var newline = detectNewline.graceful(fileContents || '');

  var commentFormatter = commentFormatters.default;

  if (file.sourceMap.preExistingComment) {
    commentFormatter = (commentFormatters[extension] || commentFormatter).bind(undefined, '', newline);
    debug(function() {
      return 'preExistingComment commentFormatter ' + commentFormatter.name;
    });
  } else {
    commentFormatter = (commentFormatters[extension] || commentFormatter).bind(undefined, newline, newline);
  }

  debug(function() {
    return 'commentFormatter ' + commentFormatter.name;
  });
  return commentFormatter;
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 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 mlewand / win-clipboard / lib / html.js View on Github external
encode( str, sourceUrl ) {
		const eol = detectNewline.graceful( str );

		let headers = [
			'Version:0.9',
			'StartHTML:00000000',
			'EndHTML:00000000',
			'StartFragment:00000000',
			'EndFragment:00000000'
		];

		if ( sourceUrl ) {
			headers.push( 'SourceURL:' + sourceUrl );
		}

		str = this._calculateHeaders( headers, str, eol );

		headers.push( str );

detect-newline

Detect the dominant newline character of a string

MIT
Latest version published 5 months ago

Package Health Score

77 / 100
Full package analysis

Popular detect-newline functions