npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

arqile

v0.1.0

Published

arqile is a package to restructure and modify json-based data

Downloads

15

Readme

Arqile


( arqile ) is a tiny package to restructure your json-based data

Installation


Use the npm to install arqile.

npm install arqile --save

or you can use yarn to install it

yarn add arqile

Quick Start


Restructure data by write the name of property

class Arqile {
  pass (
    data: any[],
    recipe: Record<string, any>,
    callback: (key: any, item: any) => void
  ): Promise< any[] | Record< any, any > >
}
const Arqile = require('arqile')
const arqile = new Arqile()
const data = [
   {
       name : 'abrahem ali',
       age : 15,
       address : { first : 'Egypt', second : 'Cairo' },
       techs : ['sass', 'node js', 'typescript']
   }
]

arqile.pass(data, {
  "*" : { // Every Item
    name : '',
    address : { first : '' }
  }
}).then( result => console.log(result) )

// result
[
    {
         name : 'abrahem ali',
         address : {
             first : 'Egypt',
         },
    },
    ...
]

Actions


Action is a query starts with "$" makes a mutations on data

$take

$take provide you to specify a count of items to take

const data = new Array(10).fill({
  name : 'abrahem ali',
  age : 15,
  address : { first : 'Egypt', second : 'Cairo' }
})

arqile.pass(data, {
  $take : 1 // take one item
  '*' : {
    name : {
      $take : 7 // take first three characters
    },
    address : {
      $take : [ 'first' ] // take "first" property
    }
  }
}).then( result => console.log(result) )

// result
[
  {
    name : 'abrahem',
    address : { first : 'Egypt' }
  }
]

$ignore

$ignore provide you to ignore properties, items and strings

arqile.pass(data, {
  "*" : {
    name : { $ignore : 'alhofe' },
    address : { $ignore : [ 'last' ] },
    techs : { $ignore : ['sass'] }
  }
}).then( result => console.log( result ) )

// result
[
  {
    name : 'abrahem ',
    address : { first : 'Egypt' },
    techs : ['node js', 'typescript']
  }
]

$include

$include provide you to include item to object, array or even string

arqile.pass(data, {
  '*' : {
    $include : (payload, recipe) => ({ adult : payload.value.age > 18 }),
    techs : { $include : ['python'] },
    name : { $include : ' alhofe' }
  }
}).then( result => console.log( result ) )

// result
[
  {
    adult: false,
    name: 'abrahem ali alhofe',
    techs: [ 'sass', 'node js', 'typescript', 'python' ]
  }
]

$keyname

$keyname provide you to change key name of item

arqile.pass(data, {
  '*' : {
    name : { $keyname : 'full_name' },
    address : {
        first : { $keyname : () => 'country' },
        second : { $keyname : () => 'city' }
    }
  }
}).then( result => console.log(result) )

// result
[
  {
    full_name: 'abrahem ali',
    address: { country: 'Egypt', city: 'Cairo' }
  }
]

$value

$value provide you to set value of item

arqile.pass(data, {
  '*' : {
    $value : (payload, recipe) => payload.value.name
  }
}).then( result => console.log(result) )

// result
[ 'abrahem ali' ]

Aliases


Aliases provide you to change key name of item ( you can see it as a shorthand of keyname )

arqile.pass(data, {
  '*' : {
    'name : full_name' : '',
    address : {
      'first : country' : '',
      'second : city' : ''
    }
  }
}).then( result => console.log(result) )

// result
[
  {
    full_name: 'abrahem alhofe',
    address: { country: 'Egypt', city: 'Cairo' }
  }
]

Layers


Layers provide you to add layer to something before work on item

class Arqile {
  addLayer(
    layerMatcher: (payload: Payload, recipe: Recipe) => Boolean,
    layerHandler: (payload: Payload, recipe: Recipe) => Promise<any>
  )
}
const authors = [
  {
    name : 'George Orwell',
    age : 46,
    id : 0
  },
]
const books = [
  {
    title : "Animal Farm",
    description : "Is an allegoircal novella by George Orwell.",
    author : 0
  },
]

arqile.addLayer(
  payload => payload.path.includes('author'),
  payload => payload.value = authors[payload.value]
)

arqile.pass(books, {
  '*' : {
    title : '',
    author : { $ignore : ['id'] }
  }
}).then( result => console.log( result ) )

// result
[
  {
      title : "Animal Farm",
      author : {
          name : "George Orwell",
          age : 46
      }
  }
]

References


References are strings start with '@' to get value from item, so you can use it with Aliases

const data = [
  {
    name : {
      value : 'abrahem ali',
      database_keyname : 'full_name'
    },
    address : {
      value : 'Egypt, Cairo',
      database_keyname : 'full_address'
    }
  }
]

arqile.pass(data, {
  '*' : {
    'name : @database_keyname' : '',
    'address : @database_keyname' : ''
  }
}).then( result => console.log(result) )

// result
[
  {
    full_name: { value: 'abrahem ali', database_keyname: 'full_name' },
    full_address: { value: 'Egypt, Cairo', database_keyname: 'full_address' }
  }
]

Or $value

arqile.pass(data, {
  '*' : { $value : '@name' }
}).then( result => console.log(result) )

// result
[ 'abrahem ali' ]

Or $keyname

const data = [
  {
    name : {
      value : 'abrahem ali',
      database_keyname : 'full_name'
    },
    address : {
      value : 'Egypt, Cairo',
      database_keyname : 'full_address'
    }
  }
]

arqile.pass(data, {
  '*' : {
    'name' : {
      $keyname : '@database_keyname',
      $ignore : [] // to get all properties inside "name"
    },
    'address' : {
      $keyname : '@database_keyname',
      $ignore : [] // to get all properties inside "address"
    }
  }
}).then( result => console.log(result) )

// result
[
  {
    full_name: { value: 'abrahem ali', database_keyname: 'full_name' },
    full_address: { value: 'Egypt, Cairo', database_keyname: 'full_address' }
  }
]

Payload


Arqile does't work with data direct it convert data to Payload, you will work with Payload on Layers and Actions ( like $include )

class Payload {
  value : any,
  keyname : string,
  path : string[],
  parent : () => Payload,
  get : (keyname: string) => Payload,
  metadata : Record< string | symbol , any >
}

Recipe


Arqile does't work with recipe direct it convert recipe to Recipe, you will work with Recipe on Layers and Actions ( like $include )

class Recipe {
  keyname : string,
  alias : string,
  value : any,
  path : string[],
  parent : () => Recipe,
  get : (keyname: string) => Recipe,
}

License

MIT