Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 3 days ago
JSON representation

Some alternative implementations for common interfaces, classes etc.

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": "[email protected]"
},
"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: '[email protected]' });
// 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**
```