plist

package module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2023 License: MIT Imports: 2 Imported by: 0

README

xk6-plist

This is a k6 extension using the xk6 system.

Build

To build a k6 binary with this plugin, first ensure you have the prerequisites:

Then:

  1. Install xk6:
go install go.k6.io/xk6/cmd/xk6@latest
  1. Build the binary:
xk6 build --with github.com/mcosta74/xk6-plist

Example

// script.js
import plist, { XMLFormat } from "k6/x/plist";

const data = `<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
    <dict>
      <key>TheString</key>
      <string>Hello World</string>
      <key>TheInt</key>
      <integer>1</integer>
      <key>TheReal</key>
      <real>1.7</real>
      <key>TheBool</key>
      <true />
      <key>TheArray</key>
      <array>
        <integer>1</integer>
        <integer>2</integer>
        <integer>3</integer>
      </array>
    </dict>
  </plist>`;

export default function() {
  const [xxx, format] = plist.parse(data);
  console.log(xxx, plist.getFormatName(format))

  let foo = {
    A: 1,
    B: 2,
    C: ['a', 'b'],
    D: {
      d1: 1,
      d2: 2.3,
    },
  };

  const str1 = plist.serialize(foo, XMLFormat);
  console.log(str1)

  const str2 = plist.serializeIndent(foo, XMLFormat, "\t");
  console.log(str2);

  const str3 = plist.serializeXML(foo);
  console.log(str3)

  const str4 = plist.serializeIndentXML(foo, "\t");
  console.log(str4);
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ModuleInstance

type ModuleInstance struct {
	// contains filtered or unexported fields
}

ModuleInstance represents an instance of the JS module.

func (*ModuleInstance) Exports

func (mi *ModuleInstance) Exports() modules.Exports

Exports implements the modules.Instance interface and returns the exported types for the JS module.

type PList

type PList struct {
	// contains filtered or unexported fields
}

func (*PList) GetFormatName added in v0.2.0

func (p *PList) GetFormatName(format int) string

func (*PList) Parse

func (p *PList) Parse(input string) (data any, format int, err error)

func (*PList) Serialize

func (p *PList) Serialize(data any, format int) (string, error)

func (*PList) SerializeBinary added in v0.3.0

func (p *PList) SerializeBinary(data any) (string, error)

func (*PList) SerializeIndent

func (p *PList) SerializeIndent(data any, format int, indent string) (string, error)

func (*PList) SerializeIndentBinary added in v0.3.0

func (p *PList) SerializeIndentBinary(data any, indent string) (string, error)

func (*PList) SerializeIndentXML added in v0.3.0

func (p *PList) SerializeIndentXML(data any, indent string) (string, error)

func (*PList) SerializeXML added in v0.3.0

func (p *PList) SerializeXML(data any) (string, error)

type RootModule

type RootModule struct{}

RootModule is the global module instance that will create module instances for each VU.

func New

func New() *RootModule

New returns a pointer to a new RootModule instance.

func (*RootModule) NewModuleInstance

func (*RootModule) NewModuleInstance(vu modules.VU) modules.Instance

NewModuleInstance implements the modules.Module interface returning a new instance for each VU.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL