Skip to content

Commit

Permalink
merge master -> lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatiusmb committed May 19, 2023
2 parents 9b952f0 + 75b45c6 commit 7028075
Show file tree
Hide file tree
Showing 33 changed files with 456 additions and 443 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# mauss changelog

## 0.5.0 - Unreleased

- ([#223](https://github.com/alchemauss/mauss/pull/223)) remove `create` from `ntv` namespace
- ([#222](https://github.com/alchemauss/mauss/pull/222)) remove `/utils` module

### Breaking Changes

- [#223](https://github.com/alchemauss/mauss/pull/223) | Removed `create` from `ntv` namespace, use array `.reduce` instead
- [#222](https://github.com/alchemauss/mauss/pull/222) | Removed `/utils` namespace
- `dt` has been moved to core module
- `random` has been moved to core module
- `tryNumber` has been removed, use `Number.isNaN(Number(s)) ? s : Number(s)`

## 0.4.12 - 2023/05/02

- ([#224](https://github.com/alchemauss/mauss/pull/224)) add string guards
- ([#221](https://github.com/alchemauss/mauss/pull/221)) add `tsf` function to `/std` module

## 0.4.11 - 2023/03/30

- ([#216](https://github.com/alchemauss/mauss/pull/216)) remove deprecated option for TS 5.0
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "mauss",
"author": "Ignatius Bagus",
"description": "fast and efficient type-safe SDK",
"version": "0.4.11",
"version": "0.4.12",
"license": "MIT",
"type": "module",
"types": "./core/index.d.ts",
"scripts": {
"clean": "git add * && git clean -dfx -e node_modules",
"watch": "pnpm pub:build --watch",
"check": "pnpm check:code && pnpm check:style",
"check:code": "tsc --noEmit --target ES2020",
"check:code": "pnpm pub:build --noEmit",
"check:style": "prettier -c \"src/**/*.ts\"",
"test": "pnpm test:unit",
"test:unit": "uvu -r tsm src \"(spec\\.ts)\"",
Expand Down Expand Up @@ -52,10 +52,10 @@
"settings"
],
"devDependencies": {
"@types/node": "^18.15.11",
"prettier": "^2.8.7",
"@types/node": "^18.16.0",
"prettier": "^2.8.8",
"tsm": "^2.3.0",
"typescript": "^5.0.2",
"typescript": "^5.0.4",
"uvu": "^0.5.6"
}
}
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

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

31 changes: 31 additions & 0 deletions src/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,37 @@ dSearch('mauss'); // execute after 500ms
tSearch('mauss'); // execute every 500ms
```

## `dt`

Simple `date/time` (`dt`) utility namespace.

```ts
type DateValue = string | number | Date;

interface BuildOptions {
base?: 'UTC';
}

interface TravelOptions {
/** relative point of reference to travel */
from?: DateValue;
/** relative days to travel in number */
to: number;
}

export const dt: {
current(d?: DateValue): Date;
build(options: BuildOptions): (date?: DateValue) => (mask?: string) => string;
format: ReturnType<typeof this.build>;
travel({ from, to }: TravelOptions): Date;
}
```
- `dt.current` is a function `(d?: DateValue) => Date` that optionally takes in a `DateValue` to be converted into a `Date` object, `new Date()` will be used if nothing is passed
- `dt.build` is a function that accepts `BuildOptions` and builds a formatter, a convenience export is included with all the default options as `dt.format`
- `dt.format` is a function that takes in a `DateValue` and returns a renderer that accepts a string mask to format the date in, defaults to `'DDDD, DD MMMM YYYY'`
- `dt.travel` is a function `({ from, to }) => Date` that takes in a `{ from, to }` object with `from` property being optional
## `execute`
```ts
Expand Down
58 changes: 26 additions & 32 deletions src/core/compare/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,26 @@ import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import * as compare from './index.js';

const basics = {
inspect: suite('compare:inspect'),
wildcard: suite('compare:wildcard'),
const suites = {
'inspect/': suite('compare/inspect'),
'wildcard/': suite('compare/wildcard'),

undefined: suite('compare:undefined'),
boolean: suite('compare:boolean'),
number: suite('compare:number'),
bigint: suite('compare:bigint'),
symbol: suite('compare:symbol'),
string: suite('compare:string'),
object: suite('compare:object'),
'undefined/': suite('compare/undefined'),
'boolean/': suite('compare/boolean'),
'number/': suite('compare/number'),
'bigint/': suite('compare/bigint'),
'symbol/': suite('compare/symbol'),
'string/': suite('compare/string'),
'object/': suite('compare/object'),

date: suite('compare:date'),
time: suite('compare:time'),
'date/': suite('compare/date'),
'time/': suite('compare/time'),

order: suite('compare:order'),
};
'order/': suite('compare/order'),
'order/key': suite('compare/order:key'),
} as const;

const composite = {
order: suite('compare:key+order'),
};

// ---- standard ----

basics.inspect('inspect', () => {
suites['inspect/']('inspect', () => {
assert.type(compare.inspect, 'function');

const data = [{ id: 0, name: 'B' }, { name: 'A' }, { id: 1, name: 'C' }];
Expand All @@ -37,25 +32,28 @@ basics.inspect('inspect', () => {
]);
});

basics.undefined('sort undefined values with null values above', () => {
suites['undefined/']('sort undefined values with null values above', () => {
assert.equal(
[undefined, 3, 0, null, 1, -1, undefined, -2, undefined, null].sort(compare.undefined),
[3, 0, 1, -1, -2, null, null, undefined, undefined, undefined]
);
});
basics.boolean('sort boolean values with true above', () => {

suites['boolean/']('sort boolean values with true above', () => {
assert.equal(
[true, false, true, false, true, false, true, false, true, false].sort(compare.boolean),
[true, true, true, true, true, false, false, false, false, false]
);
});
basics.number('sort number in descending order', () => {

suites['number/']('sort number in descending order', () => {
assert.equal(
[5, 3, 9, 6, 0, 2, 1, -1, 4, -2].sort(compare.number),
[9, 6, 5, 4, 3, 2, 1, 0, -1, -2]
);
});
basics.string('sort string in alphabetical order', () => {

suites['string/']('sort string in alphabetical order', () => {
assert.equal(
['k', 'h', 'g', 'f', 'e', 'l', 'd', 'm', 'c', 'b', 'j', 'i', 'a'].sort(compare.string),
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm']
Expand All @@ -66,18 +64,14 @@ basics.string('sort string in alphabetical order', () => {
);
});

basics.order('customized compare with order', () => {
suites['order/']('customized compare with order', () => {
const months = ['January', 'February', 'March', 'April', 'May', 'June'];
const list = ['March', 'June', 'May', 'April', 'January', 'June', 'February'];
const result = ['January', 'February', 'March', 'April', 'May', 'June', 'June'];
assert.equal(list.sort(compare.order(months)), result);
});

Object.values(basics).forEach((v) => v.run());

// ---- composite ----

composite.order('nested keyed compare with order', () => {
suites['order/key']('nested keyed compare with order', () => {
const months = ['January', 'February', 'March', 'April', 'May', 'June'];
const posts = [
{ date: { pub: { month: 'March' } } },
Expand All @@ -99,4 +93,4 @@ composite.order('nested keyed compare with order', () => {
]);
});

Object.values(composite).forEach((v) => v.run());
Object.values(suites).forEach((v) => v.run());
3 changes: 2 additions & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from './processor/index.js';
export * from './standard/index.js';

export * as compare from './compare/index.js';
export { default as unique } from './standard/unique.js';
export * as random from './random/index.js';
export * as dt from './temporal/index.js';
23 changes: 8 additions & 15 deletions src/core/lambda/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import * as lambda from './index.js';

const basics = {
curry: suite('lambda:curry'),
pipe: suite('lambda:pipe'),
const suites = {
'curry/': suite('lambda/curry'),
'pipe/': suite('lambda/pipe'),
'masked/reveal': suite('lambda/masked:reveal'),
};

const composite = {
masked: suite('lambda:mask+reveal'),
};

basics.curry('properly curry a function', () => {
suites['curry/']('properly curry a function', () => {
const sum = (a: number, b: number, c: number) => a + b + c;
const curried = lambda.curry(sum);

Expand All @@ -22,7 +19,7 @@ basics.curry('properly curry a function', () => {
assert.equal(curried(1)(1)(1), 3);
});

basics.pipe('properly apply functions in ltr order', () => {
suites['pipe/']('properly apply functions in ltr order', () => {
const cap = (v: string) => v.toUpperCase();
const name = <T extends { name: string }>(v: T) => v.name;
const split = (v: string) => v.split('');
Expand All @@ -31,11 +28,7 @@ basics.pipe('properly apply functions in ltr order', () => {
assert.equal(pipeline({ name: 'mom' }), ['M', 'O', 'M']);
});

Object.values(basics).forEach((v) => v.run());

// ---- composite ----

composite.masked('properly mask and reveal a value', () => {
suites['masked/reveal']('properly mask and reveal a value', () => {
const { mask, reveal } = lambda;

const answer = mask.of(() => 42);
Expand All @@ -49,4 +42,4 @@ composite.masked('properly mask and reveal a value', () => {
assert.equal(reveal(wrapped).expect('unreachable'), '2023-04-06');
});

Object.values(composite).forEach((v) => v.run());
Object.values(suites).forEach((v) => v.run());
38 changes: 18 additions & 20 deletions src/utils/random/index.spec.ts → src/core/random/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,53 @@ import { suite } from 'uvu';
import * as assert from 'uvu/assert';
import * as random from './index.js';

const basics = {
float: suite('random:float'),
int: suite('random:int'),
bool: suite('random:bool'),
array: suite('random:array'),
key: suite('random:key'),
val: suite('random:val'),
// hex: suite('random:hex'),
// ipv4: suite('random:ipv4'),
uuid: suite('random:uuid'),
const suites = {
'float/': suite('random/float'),
'int/': suite('random/int'),
'bool/': suite('random/bool'),
'array/': suite('random/array'),
'key/': suite('random/key'),
'val/': suite('random/val'),
// 'hex/': suite('random/hex'),
// 'ipv4/': suite('random/ipv4'),
'uuid/': suite('random/uuid'),
};

// ---- standard ----

basics.float('generate random float', () => {
suites['float/']('generate random float', () => {
const number = random.float();
assert.type(number, 'number');
assert.ok(number >= 0 && number <= 1);
});

basics.int('generate random integer', () => {
suites['int/']('generate random integer', () => {
const number = random.int();
assert.type(number, 'number');
assert.ok(number === 0 || number === 1);
});

basics.bool('generate random bool', () => {
suites['bool/']('generate random bool', () => {
assert.type(random.bool(), 'boolean');
});

basics.array('generate array with random values', () => {
suites['array/']('generate array with random values', () => {
const array = random.array(5, 3);
assert.type(array, 'object');
assert.equal(array.length, 5);
});

basics.key('get random key from object', () => {
suites['key/']('get random key from object', () => {
const key = random.key({ foo: 0, bar: 1 });
assert.type(key, 'string');
assert.ok(key === 'foo' || key === 'bar');
});

basics.val('get random value from object', () => {
suites['val/']('get random value from object', () => {
const val = random.val({ foo: 0, bar: 1 });
assert.type(val, 'number');
assert.ok(val === 0 || val === 1);
});

basics.uuid('generate random uuid', () => {
suites['uuid/']('generate random uuid', () => {
const floating = random.uuid();
assert.equal(floating.length, 36);
assert.equal(floating.split('-').length, 5);
Expand All @@ -61,4 +59,4 @@ basics.uuid('generate random uuid', () => {
assert.equal(secure.split('-').length, 5);
});

Object.values(basics).forEach((v) => v.run());
Object.values(suites).forEach((v) => v.run());
File renamed without changes.
Loading

0 comments on commit 7028075

Please sign in to comment.