Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
accessors have moved bro, outta here
Browse files Browse the repository at this point in the history
  • Loading branch information
hb432 committed Jun 15, 2020
1 parent e9dcb4f commit f596e23
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 87 deletions.
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,7 @@ const framework = core.import('grakkit/framework');
```

# Documentation
### `framework.array(object)`
Converts an array-like `object` into a fully qualified array. Array-like objects can be one of the following:
- an object with a length property and numeric keys
- an object with a `.forEach` iterator method
- an object with a `.forEachRemaining` iterator method

These criteria cover the following common data types:
- JS Set
- JS String
- JS Array
- [Java Iterator](https://docs.oracle.com/javase/10/docs/api/java/util/Iterator.html)
- [Java Set](https://docs.oracle.com/javase/10/docs/api/java/util/Set.html)
- [Java ArrayList](https://docs.oracle.com/javase/10/docs/api/java/util/ArrayList.html)
- [Java Map](https://docs.oracle.com/javase/10/docs/api/java/util/Map.html) (returns an array of its entries)

### `framework.base.encode(string)`
Encodes a `string` to base64 format.

Expand Down Expand Up @@ -144,9 +131,6 @@ Converts the input `string` into a [UUID](https://docs.oracle.com/javase/10/docs
### `framework.values(object)`
An alias for `Object.values(object)`.

### `framework.wrapper(object)`
Adds nashorn-style accessors to the input `object`. These accessors themselves implement `framework.wrapper`, meaning any accessed property will also have accessors, and so on.

# Polyfills
### `atob(), btoa()`
```javascript
Expand Down
70 changes: 1 addition & 69 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
(function () {
const tasks = [];
const framework = {
array: (object) => {
const output = [];
if (typeof object.length === 'number') {
if (object.length > 0) {
let index = 0;
while (output.length < object.length) {
output.push(object[index++]);
}
}
} else if (typeof object.forEach === 'function') {
object.forEach((entry) => {
output.push(entry);
});
} else if (typeof object.forEachRemaining === 'function') {
object.forEachRemaining((entry) => {
output.push(entry);
});
}
return output;
},
base: {
characters: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
encode: (string) => {
Expand Down Expand Up @@ -190,7 +170,7 @@
(consumer = (entry, index) => {
return { [entry.key || index]: entry.value || entry };
});
return framework.extend({}, ...framework.flat(framework.array(array).map(consumer)));
return framework.extend({}, ...framework.flat(array.map(consumer)));
},
pascal: (string, separator) => {
return string
Expand Down Expand Up @@ -260,54 +240,6 @@
},
values: (object) => {
return Object.values(object);
},
wrapper: (object) => {
if (object === null || typeof object !== 'object') {
return object;
} else {
const output = { instance: object };
framework.entries(object).forEach((entry) => {
let index = undefined;
entry.key.startsWith('is') && entry.key[2] && (index = 2);
entry.key.startsWith('get') && entry.key[3] && (index = 3);
if (index) {
let key = entry.key.slice(index);
if (key.length) {
let camel = framework.lower(key[0]) + key.slice(1);
if (!framework.keys(object).includes(camel)) {
try {
entry.value();
Object.defineProperty(output, camel, {
get () {
return framework.wrapper(entry.value());
},
set (value) {
return object[`set${key}`] && object[`set${key}`](value);
}
});
} catch (error) {}
}
}
} else {
Object.defineProperty(output, entry.key, {
get () {
return framework.wrapper(entry.value);
}
});
}
});
const array = framework.array(object);
framework.keys(array).forEach((index) => {
if (!framework.keys(output).includes(index)) {
Object.defineProperty(output, index, {
get () {
return framework.wrapper(array[index]);
}
});
}
});
return output;
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f596e23

Please sign in to comment.