Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Add lineNumber #8393

Closed
evenstensberg opened this issue Sep 2, 2016 · 5 comments · May be fixed by adamlaska/node#38
Closed

Suggestion: Add lineNumber #8393

evenstensberg opened this issue Sep 2, 2016 · 5 comments · May be fixed by adamlaska/node#38
Labels
feature request Issues that request new features to be added to Node.js. readline Issues and PRs related to the built-in readline module.

Comments

@evenstensberg
Copy link

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?

@princejwesley princejwesley added the readline Issues and PRs related to the built-in readline module. label Sep 2, 2016
@princejwesley
Copy link
Contributor

... read a line number of a module

@ev1stensberg Can you give an example?

@evenstensberg
Copy link
Author

evenstensberg commented Sep 2, 2016

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

@evenstensberg
Copy link
Author

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

@evenstensberg
Copy link
Author

evenstensberg commented Sep 2, 2016

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")
}

@mscdex mscdex added the feature request Issues that request new features to be added to Node.js. label Sep 2, 2016
princejwesley added a commit to princejwesley/node that referenced this issue Sep 3, 2016
While emitting 'line' event, line number will be
emitted as second parameter.

```js
rl.on('line', (input, lineNumber) => {
  console.log(`Received: ${input}, line #: ${lineNumber}`);
});
```

Refs: nodejs#8393
@mscdex
Copy link
Contributor

mscdex commented Sep 6, 2016

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
Labels
feature request Issues that request new features to be added to Node.js. readline Issues and PRs related to the built-in readline module.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants