1

I install the nodejs stringformat pacakage, and I run their first example: https://npmjs.org/package/stringformat

but I get the following error:

> npm install stringformat
> node
> var $ = require('stringformat')
> console.log($.format("Hello, {0}!", "World"))
TypeError: Object function () {
            // Call as a method
            return format.apply(arguments[0], Array.prototype.slice.call(arguments, 1))
        } has no method 'format'
    at repl:1:16
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:98:17)
    at emitKey (readline.js:1095:12)
> 

what can be the problem?

1 Answer 1

3

It doesn't have a format() method.

You can use it either as a function:

 console.log($("Hello, {0}!", "World"))

or by enabling String extension:

 $.extendString();
 // here, you call format() on a String instance .
 console.log("Hello, {0}!".format("World"));
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I see; the doc is up to date at github.com/jcayzac/stringformat.js but not at npmjs.org/package/stringformat

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.