vajexal / js-object-parser

JS 对象解析器

0.1.3 2021-05-26 16:24 UTC

This package is auto-updated.

Last update: 2024-09-29 06:14:25 UTC


README

JS 对象解析器

Build Status codecov

安装

composer require vajexal/js-object-parser

使用

<?php

declare(strict_types=1);

use Vajexal\JsObjectParser\JsObjectParser;

require_once 'vendor/autoload.php';

$jsObjectParser = new JsObjectParser();

var_dump(
    $jsObjectParser->parse('true'), // bool(true)
    $jsObjectParser->parse('123'), // int(123)
    $jsObjectParser->parse("'foo'"), // string(3) "foo"
    $jsObjectParser->parse('[1, 2]'), // array(2) { [0] => int(1) [1] => int(2) }
    $jsObjectParser->parse("{foo: 'bar'}") // array(1) { ["foo"] => string(3) "bar" }
);