How to use the detect-newline function in detect-newline

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 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 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),
    });
  }
}

detect-newline

Detect the dominant newline character of a string

MIT
Latest version published 8 months ago

Package Health Score

76 / 100
Full package analysis

Popular detect-newline functions