0.0.4 • Published 8 years ago

ng_dictionary v0.0.4

Weekly downloads
15
License
-
Repository
github
Last release
8 years ago

ng_dictionary

Loop Dictionary functions. Manipulate values ??using keywords and key functions. This directive enhances your JS code. It support sorting, filtering, and changes in arrays.

Npm

npm install ng_dictionary

Install

Download

//Include the script in your html file
<script src="mini.js"></script>
//Include the library inside of the module
var myApp = angular.module('exampleApp' , ['ng_dictionary']);
//Inside your controller call to loop
myApp.controller('example' , [ '$scope' , '$rootScope' , 'loop' , function($scope , $rootScope , loop){

   var array = $scope.array = [
      {var1: 'Omri' , var2: 'lugasi'},
      {var1: 'Hope' , var2: 'Piloni'}
  ];

       if(loop.isExistsByObject(array ,{var1: 'Omri' , var2: 'lugasi'}))
          alert("Item found!");
}]);

#Basic examples

    var array = $scope.array = [
        {var1: 'Omri' , var2: 'lugasi'},
        {var1: 'Hope' , var2: 'Piloni'},
        {var1: 'Vali' , var2: 'Folski'},
        {var1: 'David' , var2: 'Chaj'},
        {var1: 'Ben' , var2: 'Sinoa'},
        {var1: 'Cima' , var2: 'Klovaski'},
    ];
    
    $scope.falseObject = {var1: 2 , var2: 4};




  // Check if item exists by object
   // return boolean
   loop.isExistsByObject(array ,array[0]);

    ----------------------------------------------

  // Check if item exists by property
   // return boolean
   loop.isExistsByProperty(array, 'var1',array[0].var1)

     ----------------------------------------------

  // Find and replace value by item
    // return boolean
    loop.replaceByItem(array, array[0] , $scope.falseObject)

     ----------------------------------------------

  // Find and replace object by property
  // return boolean
    loop.replaceProperty(array, 'var1'  ,$scope.array[2].var1 , $scope.falseObject);

     ----------------------------------------------

  // Find item inside of the loop
    //return item or undefined
    var item = loop.findByProperty(array , 'var2' , 'Chaj')

     ----------------------------------------------

    // Get all the properties of 'var2' from the array
      //return array of properties
      var some = [];
      some = loop.getSomeProperty(array ,'var2');

     ----------------------------------------------

  // Delete item by property from array
    // return the value that was deleted!
    var callback = loop.deleteByProperty(array , 'var2' , $scope.array[4].var2);

     ----------------------------------------------

    // Delete item by object from array
      // return the value that was deleted!
        var callback = loop.deleteObject(array,$scope.array[1]);

     ----------------------------------------------

     // Get Index By Property:
      // return array of all the indexes that have condition {(property == equalValue)}
      // For example var some =[1,2,3,4,5,6];
     loop.getIndexByProperty(array , property , equalValue);

     ----------------------------------------------

     // ClearProperty:
     // Clears the property from all of the items in the array
      // (no return) Void
      loop.clearProperty(array , property);

     ----------------------------------------------
      // AddProperty:
      // Add property to all of the array's items
      // return array that contains all of the items with the new property
          loop.addProperty(array , property , value);

     ----------------------------------------------

     //GetObjectByRange:
      // Get items from array by range of numbers
       // return array of items
        loop.getObjectByRange(array , minimumRange , maximumRange);

     ----------------------------------------------

     // GetRandomObject
      // return random item from the array
       loop.getRandomObject(array);

     ----------------------------------------------

     // GetRandomObjectWithProperty
      // Get random item with condition { (item.property == value)}
        // return item or undefined;
         loop.getRandomObjectWithProperty(array , property , value);

     ----------------------------------------------

Live example click here

For more examples look at js/examples #License MIT License

Copyright (c) 2016 Omri Lugasi.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.