2017 © Pedro Peláez
 

library data-enricher

Enrich objects by processing special properties

image

legalthings/data-enricher

Enrich objects by processing special properties

  • Saturday, April 7, 2018
  • by jasny
  • Repository
  • 11 Watchers
  • 3 Stars
  • 1,476 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 59 Versions
  • 6 % Grown

The README.md

Data enricher

Build Status Scrutinizer Code Quality Code Coverage, (*1)

Enrich objects by processing special properties known as data instruction., (*2)

  • <ref> - Resolve a reference to another part of the document using a dot key path
  • <ifset> - Checks if a reference is null. If so, replace the object by null.
  • <switch> - Choose one of the child properties based on a property in the document
  • <src> - Load an external resource (through HTTP)
  • <merge> - Merge a set of objects
  • <enrich> - Enrich an object with extra data by matching properties
  • <tpl> - Parse text as Mustache template
  • <transform> - Transform the input using a function. The following functions are available You can pass in a string with the following format <function>:<arg> Alternatively you can pass in an object to pass multiple args { function: <string>, args: [...] }
  • <jmespath> - Project an object using the JMESPath query language
  • <dateformat> - Takes a date and a format (defaults to Y-m-d) and formats the accordingly. Optionally you can set the timezone if you wish to output timezone information.

Installation

composer require legalthings/data-enricher

Usage

Source

{
  "foo": {
    "bar": {
      "qux": 12345,
    },
    "term": "data enrichment",
    "city": "Amsterdam",
    "country": "Netherlands"
  },
  "amount": {
    "<ref>" : "foo.bar.qux"
  },
  "message": {
    "<tpl>": "I want to go to {{ foo.city }}, {{ foo.country }}"
  },
  "shipping": {
    "<switch>": "foo.country",
    "USA": "UPS",
    "Netherlands": "PostNL",
    "_other": "DHL"
  },
  "user" : {
    "<src>": "https://api.example.com/users/9870"
  },
  "search_results": {
    "<src>": {
      "<tpl>": "http://api.duckduckgo.com/?q={{ foo.term }}&format=json"
    },
    "<jmespath>": "RelatedTopics[].{url: FirstURL, description: Text}"
  },
  "profile": {
    "<merge>": [
      { "<ref>": "foo.bar" },
      { "<src>": "https://api.example.com/zoo/99" },
      {
        "apples": 100,
        "pears": 220
      }
    ]
  }
}

PHP script

$json = file_get_contents('source.json');
$object = json_decode($json);

$enricher = new DataEnricher();
$enricher->applyTo($object);

echo json_encode($object, JSON_PRETTY_PRINT);

Result

{
  "foo": {
    "bar": {
      "qux": 12345,
    },
    "term": "data enrichment",
    "city": "Amsterdam",
    "country": "Netherlands"
  },
  "amount": 12345,
  "message": "I want to go to Amsterdam, Netherlands",
  "shipping": "PostNL",
  "user" : {
    "id": "9870",
    "name": "John Doe",
    "email": "john@example.com"
  },
  "search_results": [
    {
      "url": "https://duckduckgo.com/Names_Database",
      "description": "Names Database - The Names Database is a partially defunct social network, owned and operated by Classmates.com, a wholly owned subsidiary of United Online. The site does not appear to be significantly updated since 2008, and has many broken links and display issues."
    },
    {
      "url": "https://duckduckgo.com/c/Tor_hidden_services",
      "description": "Tor hidden services"
    },
    {
      "url": "https://duckduckgo.com/c/Internet_privacy_software",
      "description": "Internet privacy software"
    }
  ],
  "profile": {
    "qux": 12345,
    "zoop": "P99",
    "zooq": "Q99",
    "apples": 100,
    "pears": 220
  }
}

The Versions

28/03 2018

v0.7.9

0.7.9.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

28/03 2018

dev-fix-warnings

dev-fix-warnings

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

23/09 2017

dev-openssl-issues

dev-openssl-issues

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

22/09 2017

v0.7.8

0.7.8.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

22/09 2017

dev-encryption-enrichers

dev-encryption-enrichers

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

23/08 2017

v0.7.7

0.7.7.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

23/08 2017

dev-transform-multiple-args

dev-transform-multiple-args

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

09/08 2017

v0.7.6

0.7.6.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

09/08 2017

dev-integration-test

dev-integration-test

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

27/07 2017

v0.7.5

0.7.5.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

27/07 2017

dev-date-format

dev-date-format

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

27/07 2017

v0.7.4

0.7.4.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

26/07 2017

dev-readme

dev-readme

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

26/07 2017

v0.7.3

0.7.3.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

26/07 2017

dev-transform-test

dev-transform-test

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

06/12 2016

v0.7.2

0.7.2.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

06/12 2016

dev-mustache-template-types

dev-mustache-template-types

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

10/11 2016

v0.7.1

0.7.1.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

10/11 2016

dev-deep-resolve

dev-deep-resolve

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

09/11 2016

v0.7.0

0.7.0.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

09/11 2016

dev-enrich

dev-enrich

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

01/11 2016

0.6.0

0.6.0.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

01/11 2016

dev-math-procressor

dev-math-procressor

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

06/09 2016

v0.5.8

0.5.8.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

06/09 2016

dev-merge-exceptions

dev-merge-exceptions

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

05/08 2016

v0.5.7

0.5.7.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

05/08 2016

dev-scalar-merge

dev-scalar-merge

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

14/07 2016

v0.5.6

0.5.6.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

14/07 2016

dev-transform-default-functions

dev-transform-default-functions

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

11/07 2016

v0.5.5

0.5.5.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

11/07 2016

dev-merge-fix

dev-merge-fix

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

23/06 2016

v0.5.4

0.5.4.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

23/06 2016

dev-merge-processor-fix

dev-merge-processor-fix

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

20/06 2016

v0.5.3

0.5.3.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

20/06 2016

dev-promise-result

dev-promise-result

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

16/06 2016

v0.5.2

0.5.2.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

16/06 2016

dev-fix-recursion

dev-fix-recursion

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

16/06 2016

dev-jmespath-fix

dev-jmespath-fix

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

15/06 2016

v0.5.1

0.5.1.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

15/06 2016

dev-getresult-recursive

dev-getresult-recursive

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

10/06 2016

v0.5.0

0.5.0.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

10/06 2016

dev-major-processor-change

dev-major-processor-change

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

09/06 2016

dev-http-fix-url-node

dev-http-fix-url-node

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

09/06 2016

dev-travis

dev-travis

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

09/06 2016

dev-prepare-node

dev-prepare-node

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

06/06 2016

v0.4.1

0.4.1.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

03/06 2016

v0.4.0

0.4.0.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

27/05 2016

v0.3.0

0.3.0.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

25/05 2016

dev-nodes

dev-nodes

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

20/05 2016

v0.2.1

0.2.1.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

20/05 2016

dev-Fixup-mustache-engine-namespace

dev-Fixup-mustache-engine-namespace

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

22/03 2016

dev-fix-mustache-engine

dev-fix-mustache-engine

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

21/03 2016

v0.2.0

0.2.0.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires

14/08 2015

v0.1.0

0.1.0.0

Enrich objects by processing special properties

  Sources   Download

MIT

The Requires

 

The Development Requires