New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@trim21/php-serialize

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@trim21/php-serialize

PHP serialize/deserialize in Javascript

latest
Source
npmnpm
Version
0.2.2
Version published
Weekly downloads
59
-84.05%
Maintainers
0
Weekly downloads
 
Created
Source

PHP-Serialize

Codecov

serialize and deserialize php encoded string to/from js Object/Array/Map.

Install

npm add @trim21/php-serialize
yarn add @trim21/php-serialize
pnpm add @trim21/php-serialize

Example

import * as php from '@trim21/php-serialize'

class User {
  [php.ObjectName] = 'User'

  private name: string
  private age: number

  constructor({ name, age }) {
    this.name = name
    this.age = age
  }
}

php.stringify({
  b: true,

  a: [1, 2, 3, 'a', 100n, null, undefined],

  s: 'str',

  m: new Map([
    [1, 2],
    [2, 'b'],
  ]),

  withObjectName: {
    [php.ObjectName]: 'O',
  },
})

const steel = new User({ name: 'Steel Brain', age: 17 })
const serialized = php.stringify(steel)
console.log(serialized)

const deserialized = php.parse('...', { strict: false }) // won't parse serializable class with default strict=true

API

export declare function parse(
  item: any,
  {
    strict = true,
    encoding = 'utf-8',
  }: {
    strict: boolean
    encoding: 'utf-8' | 'binary'
  } = {},
): string

export declare function stringify(item: string | Buffer): any

export declare const ObjectName: unique symbol

parse

php serialized object "O:1:"A":1:{...}" will be parsed to object with symbol name { {php.ObjectName]: "A", ... }

stringify

js Object with symbol as object name { {php.ObjectName]: "A" } will be serialized to php object "O:1:"A":1:{...}"

License

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

FAQs

Package last updated on 19 Mar 2025

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