Skip to content

QmarXX/php-serialize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP-Serialize

PHP-Serialize is tiny library that helpers you encode/decoded data in PHP's Serialization format.

It also supports Serializable objects decode. Here's how you can use them. (Note: This example uses ES6)

let Serialize = require('php-serialize')
class User{
  constructor(Info){
    this.Name = Info.Name
    this.Age = Info.Age
  }
  serialize(){
    return JSON.stringify({Name: this.Name, Age: this.Age})
  }
  unserialize(Data){
    Data = JSON.parse(Data)
    this.Name = Data.Name
    this.Age = Data.Age
  }
}
let Steel = new User({Name: "Steel Brain", Age: 16})
let Serialized = Serialize.serialize(Steel)
let Unserialized = Serialize.unserialize(Serialized, {User: User}) // Passing available classes
console.log(Unserialized instanceof User) // true

API

class Serializable{
  serialize(Item): string
  unserialize(Item, Scope = {})
}

License

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

About

PHP Serialize/Unserialize in Javascript

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 96.2%
  • PHP 3.8%