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
1
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

Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
65
-82.09%
Maintainers
1
Weekly downloads
 
Created
Source

PHP-Serialize

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

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

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

License

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

FAQs

Package last updated on 26 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