Skip to content

Commit

Permalink
doc: Add doc for jsmodern, closes #6.
Browse files Browse the repository at this point in the history
Also, fix other modules to import from original sources.
  • Loading branch information
motss committed Oct 31, 2019
1 parent 5ced7b8 commit d8a9163
Show file tree
Hide file tree
Showing 61 changed files with 819 additions and 897 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- [normalize_diacritics] - Remove accents/ diacritics in string
- [polling_observer] - A new way of running polling function with observer pattern
- [delay_until] - A typical delay function but Promise based
- [jsmodern] - An extension to existing JavaScript, influenced by other great languages such as Rust, Dart, Java, Golang, etc.

## License

Expand All @@ -40,11 +41,13 @@
[deno]: https://github.com/denoland/deno

<!-- Modules -->

[deep_clone]: /deep_clone
[lit_ntml]: /lit_ntml
[normalize_diacritics]: /normalize_diacritics
[polling_observer]: /polling_observer
[delay_until]: /delay_until
[jsmodern]: /jsmodern

<!-- Badges -->

Expand Down
42 changes: 20 additions & 22 deletions deep_clone/deep_clone.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import {
equal,
assert,
assertStrictEq,
prepareTest,
} from "../test.mod.ts";
import { equal, assert, assertStrictEq, prepareTest } from "../test.mod.ts";

import { deepClone } from "./mod.ts";
import { owno, awno, towno } from './CONSTANTS.ts';
import { owno, awno, towno } from "./CONSTANTS.ts";

async function willDeeplyCloneNestedObject() {
assert(equal(await deepClone(owno), owno));
Expand Down Expand Up @@ -113,23 +108,26 @@ async function willDeepCloningWithAbsoluteFlagBeforeMutatingClonedObject() {
assert(!equal(dc, towno));
}

prepareTest([
willDeeplyCloneNestedObject,
willTrulyDeepCloneNestedObject,
prepareTest(
[
willDeeplyCloneNestedObject,
willTrulyDeepCloneNestedObject,

willDeeplyCloneNestedArray,
willTrulyDeepCloneNestedArray,
willDeeplyCloneNestedArray,
willTrulyDeepCloneNestedArray,

willDeeplyCloneNonNestedObject,
willTrulyDeepCloneNonNestedObject,
willDeeplyCloneNonNestedObject,
willTrulyDeepCloneNonNestedObject,

willDeeplyCloneNonNestedArray,
willTrulyDeepCloneNonNestedArray,
willDeeplyCloneNonNestedArray,
willTrulyDeepCloneNonNestedArray,

willDeepCloneString,
willDeepCloneNumber,
willDeepCloneBoolean,
willDeepCloneString,
willDeepCloneNumber,
willDeepCloneBoolean,

willDeepCloningWithAbsoluteFlag,
willDeepCloningWithAbsoluteFlagBeforeMutatingClonedObject,
], "deep_clone");
willDeepCloningWithAbsoluteFlag,
willDeepCloningWithAbsoluteFlagBeforeMutatingClonedObject
],
"deep_clone"
);
14 changes: 6 additions & 8 deletions deep_clone/error.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
assertThrowsAsync,
prepareTest,
} from "../test.mod.ts";
import { assertThrowsAsync, prepareTest } from "../test.mod.ts";

import { deepClone } from "./mod.ts";

Expand All @@ -27,7 +24,8 @@ async function failsWhenDeeplyCloneUndefined() {
);
}

prepareTest([
failsWhenDeeplyCloneNull,
failsWhenDeeplyCloneUndefined,
], "deep_clone", "error");
prepareTest(
[failsWhenDeeplyCloneNull, failsWhenDeeplyCloneUndefined],
"deep_clone",
"error"
);
21 changes: 2 additions & 19 deletions deep_clone/mod.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,2 @@
export interface DeepCloneOptions {
absolute?: boolean;
}

import { deepAssign } from "https://cdn.jsdelivr.net/gh/denoland/[email protected]/std/util/deep_assign.ts";

export function deepCloneSync<T>(target: T, options?: DeepCloneOptions): T {
if (target == null) throw new TypeError(`'target' is not defined`);

return options && options.absolute
? deepAssign({}, target as any)
: JSON.parse(JSON.stringify(target));
}

export async function deepClone<T>(target: T, options?: DeepCloneOptions) {
return deepCloneSync<T>(target, options);
}

export default deepClone;
// @deno-types="https://cdn.jsdelivr.net/npm/[email protected]/dist/deep-clone/index.d.ts"
export * from "https://cdn.jsdelivr.net/npm/[email protected]/dist/deep-clone/index.js";
4 changes: 2 additions & 2 deletions delay_until/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { delayUntil } from "https://denopkg.com/motss/[email protected]/delay_unti
(async () => {
await delayUntil(3e3);

console.log('This message prints out after 3 seconds');
console.log("This message prints out after 3 seconds");
})();
```

Expand All @@ -43,7 +43,7 @@ import { delayUntil } from "https://denopkg.com/motss/[email protected]/delay_unti

<!-- References -->

[setTimeout]: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout
[settimeout]: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout
[async...await]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await

<!-- MDN -->
Expand Down
11 changes: 5 additions & 6 deletions delay_until/delay_until.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertStrictEq, prepareTest } from "../test.mod.ts";

import { delayUntil } from './mod.ts';
import { delayUntil } from "./mod.ts";

async function willDelay() {
const r = await delayUntil(3e3);
Expand All @@ -20,8 +20,7 @@ async function willResolveWithDelayFallbacksTo0() {
assertStrictEq(r, void 0);
}

prepareTest([
willDelay,
willResolveWithDelayFallbacksTo0,
willResolveWithOptionalDelay,
], "delay_until");
prepareTest(
[willDelay, willResolveWithDelayFallbacksTo0, willResolveWithOptionalDelay],
"delay_until"
);
2 changes: 1 addition & 1 deletion delay_until/mod.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from 'https://cdn.jsdelivr.net/gh/motss/[email protected]/src/delay-until/index.ts';
export * from "https://cdn.jsdelivr.net/gh/motss/[email protected]/src/delay-until/index.ts";
Empty file added deno.ts
Empty file.
91 changes: 91 additions & 0 deletions jsmodern/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<div align="center" style="text-align: center;">
<h1 style="border-bottom: none;">jsmodern</h1>

<p>An extension to existing JavaScript, influenced by other great languages such as Rust, Dart, Java, Golang, etc.</p>
</div>

<hr />

[![MIT License][mit-license-badge]][mit-license-url]

> A collections of extensions for JavaScript that borrow some of the useful features from other programming languages.
## Table of contents <!-- omit in toc -->

- [Usage](#usage)
- [API Reference](#api-reference)
- [License](#license)

## Usage

```ts
// It is recommended to only import those extensions you need instead of everything.
import { extend } from "https://cdn.jsdelivr.net/gh/motss/[email protected]/jsmodern/extend.ts";
import { sum } from "https://cdn.jsdelivr.net/gh/motss/[email protected]/jsmodern/array.ts";

extend({ array: [sum] });

const total = [1, 2, 3].sum();

console.log(total === 6); // true
```

## API Reference

- [x] [Array extensions]
- [x] [Boolean extensions]
- [x] [Date extensions]
- [x] [Error extensions]
- [x] [Function extensions]
- [x] [Iterator extensions]
- [x] [Map extensions]
- [x] [Number extensions]
- [x] [Object extensions]
- [x] [Promise extensions]
- [x] [RegExp extensions]
- [x] [Set extensions]
- [x] [String extensions]
- [x] [Symbol extensions]
- [x] [WeakMap extensions]
- [x] [WeakSet extensions]

## License

[MIT License](http://motss.mit-license.org/) © Rong Sen Ng

<!-- References -->

[array extensions]: https://github.com/motss/jsmodern/tree/master/src/array
[boolean extensions]: https://github.com/motss/jsmodern/tree/master/src/boolean
[date extensions]: https://github.com/motss/jsmodern/tree/master/src/date
[error extensions]: https://github.com/motss/jsmodern/tree/master/src/error
[function extensions]: https://github.com/motss/jsmodern/tree/master/src/function
[iterator extensions]: https://github.com/motss/jsmodern/tree/master/src/iterator
[map extensions]: https://github.com/motss/jsmodern/tree/master/src/map
[number extensions]: https://github.com/motss/jsmodern/tree/master/src/number
[object extensions]: https://github.com/motss/jsmodern/tree/master/src/object
[promise extensions]: https://github.com/motss/jsmodern/tree/master/src/promise
[regexp extensions]: https://github.com/motss/jsmodern/tree/master/src/regexp
[set extensions]: https://github.com/motss/jsmodern/tree/master/src/set
[string extensions]: https://github.com/motss/jsmodern/tree/master/src/string
[symbol extensions]: https://github.com/motss/jsmodern/tree/master/src/symbol
[weakmap extensions]: https://github.com/motss/jsmodern/tree/master/src/weak-map
[weakset extensions]: https://github.com/motss/jsmodern/tree/master/src/weak-set

<!-- MDN -->

[map-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
[string-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
[object-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
[number-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
[boolean-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[html-style-element-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLStyleElement
[promise-mdn-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

<!-- Badges -->

[mit-license-badge]: https://flat.badgen.net/badge/license/MIT/blue

<!-- Links -->

[mit-license-url]: https://github.com/motss/deno_mod/blob/master/LICENSE
89 changes: 44 additions & 45 deletions jsmodern/array.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertStrictEq, prepareTest } from '../test.mod.ts';
import { assertStrictEq, prepareTest } from "../test.mod.ts";

import { extend } from './extend.ts';
import { extend } from "./extend.ts";

import {
all,
Expand Down Expand Up @@ -35,8 +35,8 @@ import {
splitAt,
startsWith,
sum,
truncate,
} from './array.ts';
truncate
} from "./array.ts";

extend({
array: [
Expand Down Expand Up @@ -72,44 +72,44 @@ extend({
splitAt,
startsWith,
sum,
truncate,
],
truncate
]
});

async function willExtendArrayPrototype() {
const extensions = [
['Array.prototype.all', 'all'],
['Array.prototype.any', 'any'],
['Array.prototype.binarySearch', 'binarySearch'],
['Array.prototype.chunks', 'chunks'],
['Array.prototype.clear', 'clear'],
['Array.prototype.contains', 'contains'],
['Array.prototype.endsWith', 'endsWith'],
['Array.prototype.enumerate', 'enumerate'],
['Array.prototype.firstItem', 'firstItem'],
['Array.prototype.fold', 'fold'],
['Array.prototype.insert', 'insert'],
['Array.prototype.isEmpty', 'isEmpty'],
['Array.prototype.isSorted', 'isSorted'],
['Array.prototype.iter', 'iter'],
['Array.prototype.lastIndex', 'lastIndex'],
['Array.prototype.lastItem', 'lastItem'],
['Array.prototype.len', 'len'],
['Array.prototype.max', 'max'],
['Array.prototype.min', 'min'],
['Array.prototype.partition', 'partition'],
['Array.prototype.product', 'product'],
['Array.prototype.reject', 'reject'],
['Array.prototype.remove', 'remove'],
['Array.prototype.repeat', 'repeat'],
['Array.prototype.retain', 'retain'],
['Array.prototype.select', 'select'],
['Array.prototype.shuffle', 'shuffle'],
['Array.prototype.splitAt', 'splitAt'],
['Array.prototype.split', 'split'],
['Array.prototype.startsWith', 'startsWith'],
['Array.prototype.sum', 'sum'],
['Array.prototype.truncate', 'truncate'],
["Array.prototype.all", "all"],
["Array.prototype.any", "any"],
["Array.prototype.binarySearch", "binarySearch"],
["Array.prototype.chunks", "chunks"],
["Array.prototype.clear", "clear"],
["Array.prototype.contains", "contains"],
["Array.prototype.endsWith", "endsWith"],
["Array.prototype.enumerate", "enumerate"],
["Array.prototype.firstItem", "firstItem"],
["Array.prototype.fold", "fold"],
["Array.prototype.insert", "insert"],
["Array.prototype.isEmpty", "isEmpty"],
["Array.prototype.isSorted", "isSorted"],
["Array.prototype.iter", "iter"],
["Array.prototype.lastIndex", "lastIndex"],
["Array.prototype.lastItem", "lastItem"],
["Array.prototype.len", "len"],
["Array.prototype.max", "max"],
["Array.prototype.min", "min"],
["Array.prototype.partition", "partition"],
["Array.prototype.product", "product"],
["Array.prototype.reject", "reject"],
["Array.prototype.remove", "remove"],
["Array.prototype.repeat", "repeat"],
["Array.prototype.retain", "retain"],
["Array.prototype.select", "select"],
["Array.prototype.shuffle", "shuffle"],
["Array.prototype.splitAt", "splitAt"],
["Array.prototype.split", "split"],
["Array.prototype.startsWith", "startsWith"],
["Array.prototype.sum", "sum"],
["Array.prototype.truncate", "truncate"]
];
const expectation = extensions.every(([_, methodName]) => {
return methodName in Array.prototype;
Expand All @@ -119,17 +119,16 @@ async function willExtendArrayPrototype() {
}

async function willExtendArrayConstructor() {
const extensions = [
['Array.filled', 'filled'],
];
const extensions = [["Array.filled", "filled"]];
const expectation = extensions.every(([_, methodName]) => {
return methodName in Array;
});

assertStrictEq(expectation, true);
}

prepareTest([
willExtendArrayConstructor,
willExtendArrayPrototype,
], 'jsmodern', 'array');
prepareTest(
[willExtendArrayConstructor, willExtendArrayPrototype],
"jsmodern",
"array"
);
Loading

0 comments on commit d8a9163

Please sign in to comment.