镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Suggestion: Add lineNumber #8393

Description

@evenstensberg

Right now, I can't find out how to read a line number of a module, using readLine. I thought this was already implemented, but it is not :/ Is there anyway to get this to work / find out a line number of a module?

Activity

  1. added
    readlineIssues and PRs related to the built-in readline module.
    on Sep 2, 2016
  2. princejwesley commented on Sep 2, 2016

    @princejwesley
    Contributor

    ... read a line number of a module

    @ev1stensberg Can you give an example?

  3. evenstensberg commented on Sep 2, 2016

    @evenstensberg
    Author

    I have a config file, where user can input line number and a string. (linenumber is lineNumber && query is string),

    if the line number is correct and the string is the same as in the config, we log and write to the output.txt file.

    Let me know if this was unclear!

    const readline = require('readline')
    const fs = require("fs")
    
    module.exports = function(){
      const outi = fs.createWriteStream('output.txt')
      const rl = readline.createInterface({
        input:  fs.createReadStream('input.txt')
      })
      let counter = 0;
      rl.on('line', (line) => {
          ++counter
    
        lineNumber.filter( (lines) => {
          if(lines === counter) {
            query.filter ( (pair) => {
              if(pair === line) {
                console.log("yess", line)
                outi.write(pair)
              }
            })
          }
        })
      })
    }
  4. evenstensberg commented on Sep 2, 2016

    @evenstensberg
    Author

    Compared, having lineNumber, I could make this less volatile and perhaps cut some loops off.

  5. evenstensberg commented on Sep 2, 2016

    @evenstensberg
    Author
    const rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout,
      LineNumber: line.number
    });

    This is rather a crazy idea, but having this run in parallell, so we could do something like

    lineNumber.filter( (number) => {
    if(rl.LineNumber === number) {
     console.log("yeeey")
    }
  6. mscdex commented on Sep 6, 2016

    @mscdex
    Contributor

    As I mentioned in the PR related to this, I am -1 on this idea. It's easy enough to do in userland and IMHO adding it to core would be a sign of feature creep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues requesting new Node.js features.readlineIssues and PRs related to the built-in readline module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions