Skip to content

Commit

Permalink
Merge pull request #71 from Jozty/70-style-use-deno-lint-and-fmt-for-…
Browse files Browse the repository at this point in the history
…formatting-purposes

70 style use deno lint and fmt for formatting purposes
  • Loading branch information
singla-shivam authored Jul 5, 2022
2 parents 042b46c + 694eb49 commit 09c85d8
Show file tree
Hide file tree
Showing 274 changed files with 5,942 additions and 6,080 deletions.
57 changes: 28 additions & 29 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.236.0/containers/deno
{
"name": "Deno",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Debian OS version: bullseye, buster
"args": {
"VARIANT": "bullseye"
}
},
"name": "Deno",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Debian OS version: bullseye, buster
"args": {
"VARIANT": "bullseye"
}
},

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
// Enables the project as a Deno project
"deno.enable": true,
// Enables Deno linting for the project
"deno.lint": true,
// Sets Deno as the default formatter for the project
"editor.defaultFormatter": "denoland.vscode-deno"
},
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
// Enables the project as a Deno project
"deno.enable": true,
// Enables Deno linting for the project
"deno.lint": true,
// Sets Deno as the default formatter for the project
"editor.defaultFormatter": "denoland.vscode-deno"
},


// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"denoland.vscode-deno"
]
}
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"denoland.vscode-deno"
]
}
},

"remoteUser": "vscode"
"remoteUser": "vscode"
}
7 changes: 4 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ A clear and concise description of what the bug is.

**To Reproduce**
Code-
Playground link-
Playground link-

**Expected behavior**
A clear and concise description of what you expected to happen.
Expand All @@ -21,8 +21,9 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Versions (please complete the following information):**
- Deno:
- Fae:

- Deno:
- Fae:

**Additional context**
Add any other context about the problem here.
5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE/types-refine-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ A clear and concise description of problem along with an example code.
A clear and concise description of what you expected to happen along with an example code.

**Versions (please complete the following information):**
- Deno:
- Fae:

- Deno:
- Fae:
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ jobs:
run: npm i -g dts-bundle-generator typescript

- name: Generate declaration
run: deno run --allow-write --allow-read --allow-run --unstable declarations.ts
run: deno task gen-declarations

- name: Compile files
run: |
cd temp/
tsc --init
tsc --lib esnext --downlevelIteration --outDir compiled
tsc --lib esnext --target es6 --outDir compiled
cd compiled
zip -r bundle.zip .
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/tests-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ jobs:
- name: Run tests
run: deno test --doc

- name: Linter
run: deno lint

- name: Formatter
run: deno fmt --check

examples:
runs-on: ubuntu-latest
steps:
Expand All @@ -31,4 +37,4 @@ jobs:
deno-version: v1.x

- name: Run examples
run: deno run --allow-read --allow-run run-utils/examples.ts
run: deno task examples
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"request": "attach",
"port": 9229
}]
}
}
13 changes: 6 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"deno.enable": true,
"editor.formatOnSave": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"workbench.colorCustomizations": {},
"window.titleBarStyle": "custom",
"deno.import_intellisense_origins": {
"https://deno.land": true
}
"deno.lint": true,
"editor.defaultFormatter": "denoland.vscode-deno",
"deno.codeLens.implementations": true,
"deno.codeLens.references": true,
"deno.codeLens.test": true,
"deno.codeLens.referencesAllFunctions": true
}
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"label": "dec",
"type": "shell",
"command": "deno run -A --unstable declarations.ts",
"isBackground": true,
"isBackground": true
},
{
"label": "prettify",
"type": "shell",
"command": "prettier -w specs/*.ts && prettier -w *.ts",
"isBackground": true,
"isBackground": true
},
{
"label": "debug _test.ts",
Expand All @@ -30,7 +30,7 @@
"activeOnStart": true,
"beginsPattern": "Debugger listening"
}
},
}
}
]
}
77 changes: 45 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
![](./assets/logo-160x160-2.png)


# Fae

[![CodeFactor](https://www.codefactor.io/repository/github/jozty/fae/badge)](https://www.codefactor.io/repository/github/jozty/fae)
Expand All @@ -9,10 +8,16 @@
![GitHub](https://img.shields.io/github/license/jozty/fae)
[![codecov](https://codecov.io/gh/Jozty/Fae/branch/master/graph/badge.svg)](https://codecov.io/gh/Jozty/Fae)

Fae is a fully-fledged library that supports the functional style of programming
in Deno and is inspired from [Ramda](https://ramdajs.com). This style provides
many benefits like it never mutates input data and is used to create function
pipelines. Fae functions are automatically curried. The data to be operated on
is generally supplied last. It results in easy to build functions as sequences
of simpler or atomic functions (pipelines), each of which transforms the data
and passes it along to the next.

Fae is a fully-fledged library that supports the functional style of programming in Deno and is inspired from [Ramda](https://ramdajs.com). This style provides many benefits like it never mutates input data and is used to create function pipelines. Fae functions are automatically curried. The data to be operated on is generally supplied last. It results in easy to build functions as sequences of simpler or atomic functions (pipelines), each of which transforms the data and passes it along to the next.

Fae provides over 110 functions that help programmers to write clean and concise code.
Fae provides over 110 functions that help programmers to write clean and concise
code.

## Installing

Expand All @@ -21,7 +26,7 @@ _Deno allows you to directly import modules from URLs!_
To import and use the client in your file, add the following import statement:

```typescript
import * as Fae from 'https://deno.land/x/[email protected]/mod.ts'
import * as Fae from 'https://deno.land/x/[email protected]/mod.ts';
```

Function usage and documentation can be found [here](https://fae.jozty.io/)
Expand All @@ -37,51 +42,59 @@ deno test --coverage --unstable
### Usage

```typescript
import * as Fae from 'https://deno.land/x/[email protected]/mod.ts'
import * as Fae from 'https://deno.land/x/[email protected]/mod.ts';

// arithmetic functions
Fae.add(10, 20) // 30
Fae.add(10)(20) // 30
Fae.add(10, 20); // 30
Fae.add(10)(20); // 30

const add20 = Fae.add(20)
add20(10) // 30
add20(125) // 145
const add20 = Fae.add(20);
add20(10); // 30
add20(125); // 145

// Expression - (2*5+5-10)/2
const double = Fae.multiply(2)
const half = Fae.divide(Fae._, 2)
const add5 = Fae.add(5)
const subtract10 = Fae.subtract(Fae._, 10)

half(subtract10(add5(double(15)))) // 12.5
Fae.compose(half, subtract10, add5, double)(15) // 12.5
Fae.pipe(double, add5, subtract10, half)(15) // 12.5
const double = Fae.multiply(2);
const half = Fae.divide(Fae._, 2);
const add5 = Fae.add(5);
const subtract10 = Fae.subtract(Fae._, 10);

half(subtract10(add5(double(15)))); // 12.5
Fae.compose(half, subtract10, add5, double)(15); // 12.5
Fae.pipe(double, add5, subtract10, half)(15); // 12.5
```

**With lenses**

```typescript
import { lens, view, over, inc, set } from 'https://deno.land/x/[email protected]/mod.ts'
import {
inc,
lens,
over,
set,
view,
} from 'https://deno.land/x/[email protected]/mod.ts';

const array = [1, 2, 3, 4, 5, 6, 7, 8]
const array = [1, 2, 3, 4, 5, 6, 7, 8];

// gets element at index `0`
function getter(a: number[]) {
return a[0]
return a[0];
}

// returns a new array by setting passed value `val` at index `0`
function setter(val: number, a: number[]) {
const x = [...a]
x[0] = val
return x
const x = [...a];
x[0] = val;
return x;
}

const l = lens(getter, setter)
const l = lens(getter, setter);

const viewResult = view(l, array)
const overResult = over(l, inc, array)
const setResult = set(l, 12, array)
const viewResult = view(l, array);
const overResult = over(l, inc, array);
const setResult = set(l, 12, array);

console.log(viewResult) // 1
console.log(overResult) // [2, 2, 3, 4, 5, 6, 7, 8]
console.log(setResult) // [12, 2, 3, 4, 5, 6, 7, 8]
console.log(viewResult); // 1
console.log(overResult); // [2, 2, 3, 4, 5, 6, 7, 8]
console.log(setResult); // [12, 2, 3, 4, 5, 6, 7, 8]
```
11 changes: 5 additions & 6 deletions add.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// Copyright (c) 2020 Jozty. All rights reserved. MIT license.

import curryN from './utils/curry_n.ts'
import curryN from './utils/curry_n.ts';

// @types
type Add_2 = (b: number) => number
type Add_2 = (b: number) => number;

// prettier-ignore
type Add =
& ((a: number) => Add_2)
& ((a: number, b: number) => number)
& ((a: number, b: number) => number);

function _add(a: number, b: number) {
return a + b
return a + b;
}

/**
Expand All @@ -20,4 +19,4 @@ function _add(a: number, b: number) {
* const add5 = Fae.add(5, Fae._)
* const a = add5(4) // 9
*/
export const add: Add = curryN(2, _add)
export const add: Add = curryN(2, _add);
32 changes: 16 additions & 16 deletions addIndex.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
// Copyright (c) 2020 Jozty. All rights reserved. MIT license.

import { concat } from './concat.ts'
import curryN from './utils/curry_n.ts'
import type { Func } from './utils/types.ts'
import { getFunctionLength } from './utils/get.ts'
import { concat } from './concat.ts';
import curryN from './utils/curry_n.ts';
import type { Func } from './utils/types.ts';
import { getFunctionLength } from './utils/get.ts';

// @types
type AddIndex = (fn: Func) => Func
type AddIndex = (fn: Func) => Func;

function _addIndex(fn: Func) {
return curryN(getFunctionLength(fn), function (this: any) {
let index = 0
const origFn = arguments[0]
const list = arguments[arguments.length - 1]
const args = [...arguments]
let index = 0;
const origFn = arguments[0];
const list = arguments[arguments.length - 1];
const args = [...arguments];

args[0] = function () {
let result = origFn.apply(
this,
concat([...arguments], [index, list]),
)
index += 1
return result
}
);
index += 1;
return result;
};

return fn.apply(this, args)
})
return fn.apply(this, args);
});
}

/**
Expand All @@ -41,4 +41,4 @@ function _addIndex(fn: Func) {
* indexedMap((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r'])
* // ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r']
*/
export const addIndex: AddIndex = curryN(1, _addIndex)
export const addIndex: AddIndex = curryN(1, _addIndex);
Loading

0 comments on commit 09c85d8

Please sign in to comment.