Socket
Socket
Sign inDemoInstall

php-serialize

Package Overview
Dependencies
0
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    php-serialize

PHP serialize/unserialize in Javascript


Version published
Weekly downloads
37K
decreased by-1.87%
Maintainers
1
Install size
34.9 kB
Created
Weekly downloads
 

Changelog

Source

4.1.1

  • Fix Map support for multiple elements (Thanks @trim21)

Readme

Source

PHP-Serialize

It also supports Serializable objects decode. Here's how you can use them.

import {serialize, unserialize} from 'php-serialize'

class User {
  constructor({ name, age }) {
    this.name = name
    this.age = age
  }
  serialize() {
    return JSON.stringify({ name: this.name, age: this.age })
  }
  unserialize(rawData) {
    const { name, age } = JSON.parse(rawData)
    this.name = name
    this.age = age
  }
}
const steel = new User({ name: 'Steel Brain', age: 17 })
const serialized = serialize(steel)
const unserialized = unserialize(serialized, { User: User }) // Passing available classes
console.log(unserialized instanceof User) // true

const serializedForNamespace = serialize(steel, {
  'MyApp\\User': User,
})
// ^ Above code will serialize User class to given name
API
export function serialize(
  item: any,
  phpToJsScope: Object = {},
  options: { encoding: 'utf8' | 'binary' } = { encoding: 'utf8' }
): string
export function unserialize(
  item: string,
  scope: Object = {},
  options: { strict: boolean, encoding: 'utf8' | 'binary' } = { strict: false, encoding: 'utf8' }
): any
export function isSerialized(
  item: any,
  strict: false
): boolean
License

This project is licensed under the terms of MIT License. See the License file for more info.

FAQs

Last updated on 10 May 2023

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc