Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Knockout.js object wrapperNew to Visual Studio Code? Get it now.
Knockout.js object wrapper

Knockout.js object wrapper

smk2672

|
1,114 installs
| (0) | Free
Accepts a JavaScript object, and wraps every value with the appropriate KnockoutJS observable
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

knockout-js-object-wrapper README

If you're using TypeScript, remove TypeScript annotation from the object you want to wrap. Next, select a JavaScript object, making sure not to select code that surrounds the object -- other than its declaration and its terminating semicolon/newline. Finally, execute the command "Wrap Javascript object in Knockout.js". The extension will then wrap every value in the appropriate Knockout.js observable and paste the result below the object you selected.

For instance, if you execute the command after selecting this:

const obj = {
    key: "string",
    key2: 0,
    key3: [
        "1"
    ],
    key4: {
      innerKey: "value",
    },
    key5: [
      {
        innerKey: true,
      },
    ],
}

the result will be

const obj = {
    key: "string",
    key2: 0,
    key3: [
        "1"
    ],
    key4: {
      innerKey: "value",
    },
    key5: [
      {
        innerKey: true,
      },
    ],
}
const obj = {
    key: ko.observable("string"),
    key2: ko.observable(0),
    key3: ko.observableArray([
        "1"
    ]),
    key4: ko.observable({
      innerKey: ko.observable("value"),
    }),
    key5: ko.observableArray([
      {
        innerKey: ko.observable(true),
      },
    ]),
}

If you'd like to add functionality, feel free to make a pull request.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft