5.1.2 • Published 11 months ago
php-serialize v5.1.2
PHP-Serialize
It also supports Serializable objects decode. Here's how you can use them.
Installation
$ npm install php-serialize # If you're using npm
$ yarn add php-serialize # If you're using YarnUsage
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 nameAPI
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
): booleanLicense
This project is licensed under the terms of MIT License. See the License file for more info.
5.1.2
11 months ago
5.1.1
11 months ago
5.1.0
11 months ago
5.0.1
2 years ago
5.0.0
2 years ago
4.1.0
3 years ago
4.1.1
3 years ago
4.0.1
6 years ago
4.0.2
6 years ago
4.0.0
6 years ago
3.0.1
6 years ago
3.0.0
7 years ago
2.1.0
7 years ago
2.0.1
7 years ago
2.0.0
7 years ago
1.3.1
8 years ago
1.3.0
8 years ago
1.2.5
9 years ago
1.2.4
9 years ago
1.2.3
9 years ago
1.2.2
9 years ago
1.2.1
9 years ago
1.2.0
10 years ago
1.1.1
10 years ago
1.1.0
10 years ago
1.0.0
11 years ago
0.0.1
11 years ago