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

Commit

Permalink
i used the framework to document the framework
Browse files Browse the repository at this point in the history
  • Loading branch information
hb432 committed Jun 14, 2020
1 parent dd39772 commit 6f0a8db
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 11 deletions.
111 changes: 101 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Encodes a `string` to base64 format.
Decodes a `string` from base64 format.

### `framework.camel(string, separator)`
Converts a `string` into camel case format, with words being seperated by `seperator`.
Converts a `string` into [camel case format](https://techterms.com/definition/camelcase), with words being seperated by `seperator`.

### `framework.clamp(number, min, max)`
If the `number` is more than the `max`, return the `max`. If the number is less than the `min`, return the `min`. Otherwise, return the `number`.
Expand Down Expand Up @@ -70,25 +70,116 @@ const foo = object.foo;
object.foo = 'test';
```

### `framework.entries(object)`
Converts the input `object` into an array of entries. The entry format differs from `Object.entries` output:
```javascript
const object = { a: 'x', b: 'y', c: 'z' };

// returns [['a', 'x'], ['b', 'y'], ['c', 'z']]
Object.entries(object);

// returns [ { key: 'a', value: 'x' }, { key: 'b', value: 'y' }, { key: 'c', value: 'z' } ];
framework.entries(object);
```

### `framework.extend(...objects)`
An alias for `Object.assign(...objects)`.

### `framework.flat(array)`
Removes false-like values from the input `array`. A false-like value when passed into `Boolean` will return false.

### `framework.interval(script, period)`
Executes a `script` every `period` milliseconds, starting after `period` milliseconds. Returns an object with a `.cancel()` method to stop the loop.

### `framework.key(object, value)`
If the provided `object` contains an entry whose value matches the input `value`, return that entry's key.

### `framework.keys(object)`
An alias for `Object.keys(object)`.

### `framework.lower(string)`
Returns the lowercased version of the input `string`.

### `framework.match(object, filter)`
Compares an object to a `filter`.

If the `filter` is a function, return the output of `filter(object)`.

If the `filter` is an array, map each element in the `filter` to `framework.match(object, element)`, and if at least one element in this mapped array is true, return true, otherwise, return false.

If the `filter` is an object, map each key in the `filter` object to `framework.match(object[key], filter[key])`, and if all elements in the mapped array are true, return true, otherwise, return false.

If the `filter` is a primitive value or a non-standard object, return true if the `object === filter`. A non-standard object is an object whose `typeof` value is `"object"`, but whose constructor is not `Object` or `Array`.

### `framework.mirror(options)`
Creates an array whose values can be accessed and modified by set-like functions, then returns an object to dynamically `get` and `set` the array. This is useful for specific cases involving interactions between getter/setters and java sets or maps.

### `framework.object(array, consumer)`
Converts the output `array` of `framework.entries` back into an object, with an optional consumer to process each entry before being added. False-like return values from this consumer will not be added to the output object.

### `framework.pascal(string, separator)`
Converts a `string` into [pascal case format](https://techterms.com/definition/pascalcase), with words being seperated by `seperator`.

### `framework.simplify(object)`
Creates a clone of the input `object` and recursively removes false-like or circular values. This works with arrays, too.

### `framework.splice(string, separator, ...index)`
Splits the input `string` with the `seperator`, slices the array with `array.slice(...index)`, and rejoins the sliced array with the `seperator`.

### `framework.strain(object, consumer)`
Creates a clone of the input `object`, and filters each entry with the provided `consumer`. If no consumer is provided, then removes entries whose values are false-like.

### `framework.timeout(script, period)`
Executes a `script` after `period` milliseconds. Returns an object with a `.cancel()` method to abort the execution.

### `framework.type(object)`
Returns a type string for the given object. This type string is first checked by formatting the output of `toString.call(object)`, and if that returns `"Object"`, then instead return the object's constructor name.

### `framework.upper(string)`
Returns the uppercased version of the input `string`.

### `framework.uuid(string)`
Converts the input `string` into a [UUID](https://docs.oracle.com/javase/10/docs/api/java/util/UUID.html), and if no string is provided, creates a random [UUID](https://docs.oracle.com/javase/10/docs/api/java/util/UUID.html).

### `framework.values(object)`
An alias for `Object.values(object)`.

# Polyfills
### `atob(), btoa()`
```javascript
framework.extend(global, {
atob: (string) => {
return framework.base.decode(string);
},
btoa: (string) => {
return framework.base.encode(string);
}
});
```

### `clearImmediate(), clearInterval(), clearTimeout(), setImmediate(), setInterval(), setTimeout()`
```javascript
framework.extend(global, {
clearImmediate: (task) => {
task.cancel();
clearImmediate: (index) => {
framework.tasks[index].cancel();
},
clearInterval: (task) => {
task.cancel();
clearInterval: (index) => {
framework.tasks[index].cancel();
},
clearTimeout: (task) => {
task.cancel();
clearTimeout: (index) => {
framework.tasks[index].cancel();
},
setImmediate: (script) => {
return framework.timeout(script, 0);
framework.timeout(script, 0);
return framework.tasks.length - 1;
},
setInterval: (script, period) => {
return framework.interval(script, period);
framework.interval(script, period);
return framework.tasks.length - 1;
},
setTimeout: (script, period) => {
return framework.timeout(script, period);
framework.timeout(script, period);
return framework.tasks.length - 1;
}
});
```
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 6f0a8db

Please sign in to comment.