Socket
Book a DemoInstallSign in
Socket

github.com/kazion500/jskit

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/kazion500/jskit

v0.0.8
Source
Go
Version published
Created
Source

JSKit Go Module

JSKit is a Go module that provides a set of utility functions commonly used in JavaScript programming. It offers an interface to handle JSON data, allowing users to stringify and parse JSON strings. Additionally, JSKit provides other useful functions like sorting arrays, searching for elements in arrays, and manipulating strings.

Installation

To use this module in your Go project, you can run the following command:

go get github.com/Kazion500/jskit

After installing the package, you can import it in your Go code:

import "github.com/Kazion500/jskit"

Usage

The JSKit module provides an interface that allows users to work with JSON data. The JSON function returns an interface that provides methods to stringify and parse JSON data. The ToString function returns a string representation of a byte array.

type AnyType interface{}

type JSKit[T AnyType] interface {
	JSON() JSON[T]
	ToString(value []byte) string
}

type JSON[T AnyType] interface {
	Stringify(any) (string, error)
	Parse(string, T) (T, error)
}

The jsont and jskit structs implement the JSON and JSKit interfaces respectively. The NewJSKit function returns a new JSKit interface.

Examples

Here's an example of how to use this module to stringify and parse JSON data:

package main

import (
    "fmt"
    "github.com/username/repo/jskit"
)

type Person struct {
    Name string `json:"name"`
    Age int `json:"age"`
}

func main() {
    person := Person{"John Doe", 30}
    jskit := jskit.NewJSKit[Person]()
    jsonString, _ := jskit.JSON.Stringify(person)
    fmt.Println(jsonString)

    // Output: {"name":"John Doe","age":30}

    var p Person
    jskit.JSON.Parse(jsonString, &p)
    fmt.Println(p.Name)

    // Output: John Doe

}

Contributing

We welcome contributions to this project. To contribute, please fork this repository and create a pull request.

Author

Email: Patrick

Full Name: Patrick Kabwe

FAQs

Package last updated on 28 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.