https://github.com/akinozgen/alternatives
Some alternative implementations for common interfaces, classes etc.
https://github.com/akinozgen/alternatives
alternative definition es6 functional-programming javascript json react
Last synced: 26 days ago
JSON representation
Some alternative implementations for common interfaces, classes etc.
- Host: GitHub
- URL: https://github.com/akinozgen/alternatives
- Owner: akinozgen
- Created: 2018-10-08T13:05:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-23T16:38:55.000Z (over 7 years ago)
- Last Synced: 2025-03-02T11:13:00.591Z (over 1 year ago)
- Topics: alternative, definition, es6, functional-programming, javascript, json, react
- Language: JavaScript
- Size: 19.5 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# alternatives
Some alternative implementations for common interfaces, classes etc.
1. ### React Native AsyncStorage Alternative
[goto file](https://github.com/akinozgen/alternatives/blob/master/asyncstorage-alt.js)
Data reading usage:
```javascript
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:
```json
{
"get_via_array": {
"id": 1,
"name": "Akın Özgen",
"email": "akinozgen17@outlook.com"
},
"get_directly": 1
}
```
Data writing usage:
```javascript
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);
}
```
2. ### php's http_build_query for key-value pair objects
[goto file](https://github.com/akinozgen/alternatives/blob/master/http_build_query.js)
```javascript
import http_build_query from 'http_build_query';
const loginPayload = {
username: 'root',
password: 'toor'
};
console.log(http_build_query(loginPayload));
```
Output:
```raw
username=root&password=toor
```
3. ### NodeList to Array
[goto file](https://github.com/akinozgen/alternatives/blob/master/nodelist_to_array.js)
```javascript
import n2a from 'nodelist_to_array.js';
const rows = document.querySelectorAll('tr');
console.log(n2a(rows));
```
4. ### Insister (really annoying)
[goto file](https://github.com/akinozgen/alternatives/blob/master/insister.js)
```javascript
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"));
```
4. ### String mask with *** (php)
[goto file](https://github.com/akinozgen/alternatives/blob/master/string-mask-php.php)
```php
/**
* 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**
```