GithubHelp home page GithubHelp logo

zxh-kevin / data-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fenzland/data-parser

0.0 2.0 0.0 24 KB

A library for unifying data into specific structure, and transforming data from one structure to another with given meta data.

License: MIT License

PHP 100.00%

data-parser's Introduction

PHP Data Parser

A library for unifying data into specific structure, and transforming data from one structure to another with given meta data.

Usage

composer require fenzland/data-parser
use Fenzland\DataParser\Unifier;
use Fenzland\DataParser\Transformer;

$unifier= Unifier::make_( $unifying_meta );

$unifier->unify( $data );

$transformer= Transformer::make_( $transforming_meta );

$transformer->transform( $data );

Sturcture of meta data

Unifying meta

Scalar.

[
	"key"=> [

		// Type of value. Available scalar values are:
		//   'bool', 'boolean',
		//   'int', 'integer',
		//   'float', 'double',
		//   'string',
		//   'auto',
		//   'null',
		'type'=> "string",

		// Default value
		'default'=> "default_value",

		// Hard value
		// 'value'=> "hard_value",
	],
];

Simplified form of scalar.

[
	"key"=> true,
	// is simplified form of
	"key"=> [
		'type'=> 'bool',
		'default'=> true,
	],

	"key"=> 5,
	// is simplified form of
	"key"=> [
		'type'=> 'int',
		'default'=> 5,
	],

	"key"=> 1.0,
	// is simplified form of
	"key"=> [
		'type'=> 'float',
		'default'=> 1.0,
	],

	"key"=> "default_value",
	// is simplified form of
	"key"=> [
		'type'=> 'string',
		'default'=> "default_value",
	],

	"key"=> null,
	// is simplified form of
	"key"=> [
		'type'=> 'null',
		'value'=> null,
	],
];

Map.

[
	"key"=> [
		'type'=> 'map',
		'items'=> [
			"column_0"=> /* a unifying meta */,
			"column_1"=> /* a unifying meta */,
		],
	],
];

Array.

[
	"key"=> [
		'type'=> 'array',
		'item'=> [
			// a unifying meta
			'type'=> ...,
			'default'=> ...,
		],
	],
];

Array of maps.

[
	"key"=> [
		'type'=> 'array',
		'item'=> [
			'type'=> 'map',
			'items'=> [
				"column_0"=> /* a unifying meta */,
				"column_1"=> /* a unifying meta */,
			],
		],
	],
];

Array slicing.

[
	"key"=> [
		'type'=> 'array',
		'item'=> /* a unifying meta */,
		'slice'=> [ 0, -2 ],  // Will call array_slice( $array, 0, -2 );
	],
];

Transforming meta

Standard.

// meta
[
	"foo"=> [
		'type'=> 'value',
		'keys'=> [ "Foo", "Bar", ],
		'meta'=> [
			// a unifying meta
			'type'=> 'string',
		],
	],
];

// Transform
[
	"Foo"=> [
		"Bar"=> 8,
	],
];
// Into
[
	"foo"=> "8",
];

Simplified.

[
	"key"=> "Foo",
	// and
	"key"=> [
		'type'=> 'value',
		'keys'=> "Foo",
		'meta'=> [
			'type'=> 'auto',
		],
	],
	// are simplified form of
	"key"=> [
		'type'=> 'value',
		'keys'=> [ "Foo", ],
		'meta'=> [
			'type'=> 'auto',
		],
	],
];

Map.

[
	"key"=> [
		'type'=> 'map',
		'items'=> [
			'column_0'=> /* a transforming meta */,
			'column_1'=> /* a transforming meta */,
		],
	],
];

With complex unifying meta.

[
	"key"=> [
		'type'=> 'value',
		'keys'=> [ "foo", "0", "bar", ],
		'meta'=> [
			'type'=> 'map',
			'items'=> [
				"field_0"=> "",
				"field_1"=> 0,
				"field_2"=> [
					'type'=> 'array',
					'item'=> [
						'type'=> 'int',
						'default'=> 0,
					],
				],
			],
		],
	],
];

data-parser's People

Contributors

uukoo avatar fenzland avatar

Watchers

James Cloos avatar zxh-Kevin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.