{"id":28192950,"url":"https://github.com/jyxon/data-tools","last_synced_at":"2025-05-16T12:16:12.504Z","repository":{"id":57003581,"uuid":"128675063","full_name":"Jyxon/Data-Tools","owner":"Jyxon","description":"A basic library for data manipulation.","archived":false,"fork":false,"pushed_at":"2018-07-05T19:11:38.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-16T12:15:54.125Z","etag":null,"topics":["data","library","php","tools"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jyxon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-08T19:32:38.000Z","updated_at":"2018-07-05T19:08:34.000Z","dependencies_parsed_at":"2022-08-21T14:50:37.545Z","dependency_job_id":null,"html_url":"https://github.com/Jyxon/Data-Tools","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jyxon%2FData-Tools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jyxon%2FData-Tools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jyxon%2FData-Tools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jyxon%2FData-Tools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jyxon","download_url":"https://codeload.github.com/Jyxon/Data-Tools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254527092,"owners_count":22085920,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","library","php","tools"],"created_at":"2025-05-16T12:15:54.131Z","updated_at":"2025-05-16T12:16:12.467Z","avatar_url":"https://github.com/Jyxon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Tools\nData Tools is a simple library for basic operations on data. This library simplifies simple operations that sometimes might be required during development. It also adds a few extra capabilities by using objects.\n\n## Installation\nInstalling Data Tools can be done through composer. This is done with the following command:\n```\ncomposer require jyxon/data-tools\n```\n\n## Usage\nThe package is separated into 2 namespace (currently).\n\n### Native\nWithin the Native namespace we have defined packages that are simple manipulators of native data types and object of PHP.\n\n#### ArrayTool\nThe `ArrayTool` is a tool that enables paths within arrays. It also allows flattening of an array in this manner and expanding a flattened array. For the `ArrayTool` a `path` or `flat path` is a \"/\" (slash) separated path (foo/bar). A `array path` is basically the result of an exploded path (the result of `explode('/', $path)`).\n\nThe `ArrayTool` can be initialised as follows:\n```php\nuse Jyxon\\DataTools\\Native\\ArrayTool;\n\n$associative_array = [\n    'foo' =\u003e [\n        'bar' =\u003e 'baz'\n    ]\n];\n\n$array = new ArrayTool($associative_array);\n```\n\nThe following functions are available for the `ArrayTool`:\n\n```php\n/**\n * The array is expanded and multidimensional.\n */\nArrayTool::STATUS_EXPANDED;\n\n/**\n * The array is flat and one dimensional.\n */\nArrayTool::STATUS_FLAT;\n\n/**\n * Constructor\n *\n * @param array $array The array that needs to be loaded into the tool.\n * @param int $type The type of the array. Can either be ArrayTool::STATUS_EXPANDED or ArrayTool::STATUS_FLAT\n */\npublic function __construct(array $array, int $type = self::STATUS_EXPANDED);\n\n/**\n * Returns the array in it's current state.\n *\n * @return array\n */\npublic function getArray(): array;\n\n/**\n * Loads a new array into the tool.\n *\n * @return ArrayTool\n */\npublic function setArray(array $array, int $type = self::STATUS_EXPANDED): ArrayTool;\n\n/**\n * Expands the array from the flattened form.\n *\n * @return ArrayTool\n */\npublic function expandArray(): ArrayTool;\n\n/**\n * Flattens the array.\n *\n * @return ArrayTool\n */\npublic function flattenArray(): ArrayTool;\n\n/**\n * Fetches a value in an array through a \"/\" separated path.\n *\n * @param string $path\n *\n * @return mixed\n */\npublic function getByPath(string $path);\n\n/**\n * Sets an entry by a path.\n *\n * @param string $path\n * @param mixed $value\n *\n * @return ArrayTool\n */\npublic function setByPath(string $path, $value): ArrayTool;\n\n/**\n * Strips all empty strings from an array (array_filter, but explicitly with strings).\n *\n * @return ArrayTool\n */\npublic function stripEmptyString(): ArrayTool;\n\n/**\n * Fetches the value within an array by the given array path.\n *\n * @return mixed\n */\npublic function getArrayValueByArrayPath(array $path);\n\n/**\n * Sets a value in the array by an array path.\n *\n * @param array $path\n * @param mixed $value\n *\n * @return ArrayTool\n */\npublic function setArrayValueByArrayPath(array $path, $value): ArrayTool;\n\n/**\n * Creates a subarray wether the mixed variable is an array or not.\n * If the mixed variable is an array it creates an entry.\n * If it is not an array it will create an array with the key set as a variable.\n *\n * @param mixed $mixed\n * @param string $key\n *\n * @return array\n */\npublic function forceSubArrayKey($mixed, string $key): array;\n```\n\n#### DataObject\nThe `DataObject` is not so much a tool, but more a basis for 3 standard functions for an object. You could use it as a basis, but also as an Object on it's own as a data container. You can either choose to let an existing class extend the `DataObject` to \"add\" the functionality to the class. Or you can choose to initialise it on it's own:\n```php\nuse Jyxon\\DataTools\\Native\\DataObjet;\n\n$container = new DataObject();\n```\n\nThe functions that this object adds are:\n```php\n/**\n * Sets data on the object.\n *\n * @param string $key\n * @param mixed $value\n */\npublic function setData(string $key, $value);\n\n/**\n * Retrieves the value of the object.\n *\n * @param string $key\n *\n * @return mixed\n */\npublic function getData(string $key = '');\n\n/**\n * Check wether the value is set or not.\n *\n * @param string $key\n *\n * @return boolean\n */\npublic function hasData(string $key): bool;\n```\n\n#### ReflectorTool\nThe `ReflectorTool` adds a few extra functions to the initial `ReflectionClass` native to PHP. It can be initialised as follows:\n```php\nuse Jyxon\\DataTools\\Native\\ReflectorTool;\n\n$reflection = new ReflectorTool('\\\\Foo\\\\Bar\\\\Baz');\n```\n\nThe `ReflectorTool` adds the following functions:\n```php\n/**\n * Returns the type of the object as defined in the constants.\n *\n * @return int This can be ReflectorTool::TYPE_UNKNOWN, ReflectorTool::TYPE_INTERFACE, ReflectorTool::TYPE_CLASS or ReflectorTool::TYPE_TRAIT.\n */\npublic function getType(): int;\n\n/**\n * Fetches the constructor arguments.\n *\n * @return bool|ReflectionParameter[]\n */\npublic function getConstructorArgs();\n\n/**\n * Fetches the arguments of a method.\n *\n * @param string $methodName\n *\n * @return bool|ReflectionParameter[]\n */\npublic function getMethodArguments(string $methodName);\n```\n\n### Operation\nWithin the Operation namespace we have defined packages that are not native to PHP, but add functionality or simplify standard operations.\n\n#### CalculationTool\nThe `CalculationTool` exposes some calculations that can be tedious to implement.\n\nIt can be initialised as follows:\n```php\nuse Jyxon\\DataTools\\Operation\\CalculationTool;\n\n$calculator = new CalculationTool();\n```\n\nIt exposes the following functions:\n```php\n/**\n * Gets the percentage of a factor based on a base number.\n *\n * @param float $baseNumber\n * @param float $factorNumber\n * @param float $basePercentage\n *\n * @return float\n */\npublic function getPercentageOfFactor(float $baseNumber, float $factorNumber, float $basePercentage = 1): float;\n\n/**\n * Gets the factor of a percentage based on a base number.\n *\n * @param float $baseNumber\n * @param float $percentage\n * @param float $basePercentage\n *\n * @return float\n */\npublic function getFactorOfPercentage(float $baseNumber, float $percentage, float $basePercentage = 1): float;\n\n/**\n * Adds a percentage to a base number.\n *\n * @param float $baseNumber\n * @param float $percentage\n * @param float $basePercentage\n *\n * @return float\n */\npublic function addPercentage(float $baseNumber, float $percentage, float $basePercentage = 1): float;\n\n/**\n * Subtracts a percentage of a base number.\n *\n * @param float $baseNumber\n * @param float $percentage\n * @param float $basePercentage\n *\n * @return float\n */\npublic function subtractPercentage(float $baseNumber, float $percentage, float $basePercentage = 1): float;\n\n/**\n * Returns the average of an array.\n *\n * @param array $numbers\n *\n * @return float\n */\npublic function average(array $numbers): float;\n\n/**\n * Returns the median of an array of numbers.\n *\n * @param array $numbers\n *\n * @return float\n */\npublic function median(array $numbers): float;\n\n/**\n * Returns horizon distance between 2 points on earth.\n * Using the Haversine formula.\n *\n * @param float $lat1\n * @param float $lon1\n * @param float $lat2\n * @param float $lon2\n *\n * @return float Distance in KM\n */\npublic function distance(float $lat1, float $lon1, float $lat2, float $lon2);\n\n/**\n * Calculates the correlation between 2 sets of data.\n *\n * @param float[] $x\n * @param float[] $y\n *\n * @return float\n */\npublic function correlation(array $x, array $y): float;\n\n/**\n * Calculates the offset between 2 arrays.\n *\n * @param float[] $x\n * @param float[] $y\n *\n * @return float\n */\npublic function offset(array $x, array $y): float;\n\n/**\n * Checks wether the provided array are similar or not.\n *\n * @param float[] $x\n * @param float[] $y\n *\n * @return float\n */\npublic function similarity(array $x, array $y): float;\n\n/**\n * Runs the similarity function with sorted arrays.\n *\n * @param float[] $x\n * @param float[] $y\n *\n * @return float\n */\npublic function sortedSimilarity(array $x, array $y): float;\n```\n\n#### PathTool\nThe `PathTool` is a parser for paths. It turns readable paths into useable paths for your application.\n```php\nuse Jyxon\\DataTools\\Operation\\PathTool;\n\n$path = new PathTool('foo/bar/baz?foo=bar', true);\n```\n\nIt exposes the following functions:\n```php\n/**\n * Constructor\n *\n * @param string $path\n * @param bool $parseQuery\n */\npublic function __construct(string $path, bool $parseQuery = false);\n\n/**\n * Returns the path that is set.\n *\n * @return string\n */\npublic function getPath(): string;\n\n/**\n * Sets the path that needs to be parsed.\n *\n * @param string $path\n *\n * @return void\n */\npublic function setPath(string $path);\n\n/**\n * Returns the previous path.\n *\n * @return PathTool\n */\npublic function getPreviousPath(): PathTool;\n\n/**\n * Reverts the current object to the last.\n *\n * @return void\n */\npublic function revertToPreviousPath();\n\n/**\n * Returns the expanded path.\n *\n * @return array\n */\npublic function getExpanded(): array;\n\n/**\n * Merges multiple paths into the current path.\n *\n * @param string ...$param\n *\n * @return void\n */\npublic function mergePaths();\n\n/**\n * Returns an associative array of the parameters from the path.\n *\n * @return array\n */\npublic function getParameters(): array;\n```\n\n### VersionTool\nA tool to analyse versions for your application.\n\nIt can be initialised as follows:\n```php\nuse Jyxon\\DataTools\\Operation\\VersionTool;\n\n$path = new VersionTool('1.2.3');\n```\n\nIt exposes the following functions:\n```php\n/**\n * Constructor\n *\n * @param string $version\n */\npublic function __construct(string $version);\n\n/**\n * Compares one version to another.\n *\n * @param VersionTool $version\n *\n * @return bool\n */\npublic function versionCompare(VersionTool $version, string $operator): bool;\n\n/**\n * Resets the object with a new version.\n *\n * @param string $version\n *\n * @return void\n */\npublic function setVersion(string $version);\n\n/**\n * Returns the version that is set within the VersionTool.\n *\n * @return string\n */\npublic function getVersion(): string;\n\n/**\n * __toString interpreter hook.\n *\n * @return string\n */\npublic function __toString(): string;\n\n/**\n * Returns the version depth.\n *\n * @return int\n */\npublic function getVersionDepth(): int;\n\n/**\n * Returns the expanded version.\n *\n * @return array\n */\npublic function getExpandedVersion(): array;\n\n/**\n * Returns the version number at a certain depth.\n *\n * @param int $depth\n *\n * @return int\n */\npublic function getVersionAt(int $depth): int\n```\n\n## Feedback\nWe like to get some feedback on this package. You can do so by creating an issue on GitHub.\nAlso keep in mind that this package might receive quite some updates in the near future, due to our own development process requiring this package to change.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjyxon%2Fdata-tools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjyxon%2Fdata-tools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjyxon%2Fdata-tools/lists"}