Skip to content

Some alternative implementations for common interfaces, classes etc.

Notifications You must be signed in to change notification settings

akinozgen/alternatives

Repository files navigation

alternatives

Some alternative implementations for common interfaces, classes etc.

  1. React Native AsyncStorage Alternative

goto file

Data reading usage:

import { getItem, setItem } from 'asyncstorage-alt';

async function readData() {
  const values = {};
  
  values['get_via_array'] = await getItem(['id', 'name', 'email']);
  values['get_directly'] = await getItem('id');
  console.log(values);
}

Output:

{
  "get_via_array": {
    "id": 1,
    "name": "Akın Özgen",
    "email": "akinozgen17@outlook.com"
  },
  "get_directly": 1
}

Data writing usage:

import { getItem, setItem } from 'asyncstorage-alt';

async function writeData() {
  // Multi definition
  await setItem({ id: 1, name: 'Akın Özgen', email: 'akinozgen17@outlook.com' });
  // Single definition
  await setItem('id', 1);
}
  1. php's http_build_query for key-value pair objects

goto file

import http_build_query from 'http_build_query';

const loginPayload = {
  username: 'root',
  password: 'toor'
};

console.log(http_build_query(loginPayload));

Output:

username=root&password=toor
  1. NodeList to Array

goto file

import n2a from 'nodelist_to_array.js';

const rows = document.querySelectorAll('tr');

console.log(n2a(rows));
  1. Insister (really annoying)

goto file

import ins from 'insister.js';

// Parameters:
//  (ins): insister (which is this function)
//  (_ => prompt("Accept?") !== "yes"): condition (if returns false, function repeats itself)
//  (_ => alert("Thanks")): callback (runs if condtion is true)

ins(ins, _ => prompt("Accept?") !== "yes", _ => alert("Thanks"));
  1. String mask with *** (php)

goto file

/**
 * asteriskMask($string: string, $length: number, $beginning: bool);
 *
 */
require_once 'string-mask-php.php';

$myUnprotectedPhoneNumber = '+90 588 4777 777 777 44';

echo asteriskMask($myUnprotectedPhoneNumber, 3) . "\n";
echo asteriskMask($myUnprotectedPhoneNumber, 5, true) . "\n";
echo asteriskMask('root', 5); // If length greater than strlen('root') new length is strlen('root') / 2

// Output: +90 588 4777 777 77***
//         *****88 4777 777 77 44
//         ro**

About

Some alternative implementations for common interfaces, classes etc.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published