pybuiltinfunc
Version:
Python built-in Functions and Modules in Javascript
271 lines (225 loc) • 4.89 kB
Markdown
# `Python Built-in Functions`
## `What's new in 1.2.0`
+ Added new Python `Str` Type with 39 methods.
## `What's new in 1.1.9`
+ Added new module `json`.
## `Why I made this`
I loves both Python and Javascript.
Then I found that Python Built-in Functions is easier than Javascript.At first, I made this for my personal purpose.
Then I decided to publish in both yarn and npm. If you have any idea about add new Built-in Function or Any Bugs, Kindly Contact me through my email.
```
abhiajay0206@gmail.com
```
## `Installing`
```
// For npm
npm i pybuiltinfunc
// or
// For yarn
yarn add pybuiltinfunc
```
## `Importing`
```
// ES5
const { /* Some Functions */ } = require('pybuiltinfunc');
// ES6+
import { /* Some Functions */ } from 'pybuiltinfunc';
```
## `Available Functions`
You can find these uses with example [here](https://www.w3schools.com/python/python_ref_functions.asp)
- `abs()`
- `all()`
- `chr()`
- `str()`
- `int()`
- `float()`
- `ord()`
- `len()`
- `bin()`
- `print()`
- `min()`
- `map()`
- `sum()`
- `range()`
- `type()`
### `Examples`
```
import { print } from "pybuiltinfunc";
print("Hello")
```
```
import { print, len } from "pybuiltinfunc";
print(len("Some Text"))
```
## `Available Built-in Modules`
- `math`
- `sqrt()`
- `acos()`
- `acosh()`
- `asin()`
- `asinh()`
- `atan()`
- `atan2()`
- `atanh()`
- `ceil()`
- `comb()`
- `factorial()`
- `cbrt()`
- `copysign()`
- `cos()`
- `cosh()`
- `degrees()`
- `dist()`
- `exp()`
- `expm1()`
- `floor()`
- `fmod()`
- `gcd()`
- `hypot()`
- `sin()`
- `sinh()`
- `tan()`
- `tanh()`
- `pow()`
- `prod()`
- `isfinite()`
- `isinf()`
- `isprt()`
- `radians()`
- `isnan()`
- `perm()`
- `nan`
- `e`
- `pi`
- `log`
- `log2`
- `log10`
- `log1p`
- `tau`
- `random`
- `randint()`
- `uniform()`
- `os`
- `getcwd()`
- `chdir()`
- `mkdir()`
- `rmdir()`
- `remove()`
- `listdir()`
- `rename()`
- `name()`
- `path [ os.path ]`
- `join()`
- `json`
- `load()`
- `dumps()`
### Examples
```
import { print, math } from "pybuiltinfunc";
print(math.sqrt(16))
```
```
import { print, random } from "pybuiltinfunc";
print(random.randint(0, 4))
```
## `Python List`
List in Python and Array in Javascript are same. But, Those who learn Python as first language (like me) would find Python List is easy. So I made this. You can import `List` class by,
```
import { List } from "pybuiltinfunc";
```
Using it is little bit difference,
```
const list = new List([5, 7, 8, 9])
list.append(7)
print(list.return())
```
In Above code, You can find `list.return()`. It is used to return value.
### `Available Method:`
- `append()`
- `insert()`
- `extend()`
- `remove()`
- `pop()`
- `insert()`
- `clear()`
- `reverse()`
- `count()`
- `copy()`
## `Python String`
Yeah Python String is also available in this Package. Usage is same as `List`.
### `Example`
```
import { Str, print } from "pybuiltinfunc";
const string = new Str("Hello World!")
print(string.return())
print(string.casefold())
```
## `Available Methods`
- `capitalize()`
- `casefold()`
- `center()`
- `count()`
- `endswith()`
- `expandtabs()`
- `find()`
- `index()`
- `isalnum()`
- `isalpha()`
- `isdecimal()`
- `isidentifier()`
- `isprintable()`
- `isdigit()`
- `islower()`
- `isspace()`
- `istitle()`
- `isupper()`
- `join()`
- `ljust()`
- `lower()`
- `lstrip()`
- `partition()`
- `replace()`
- `rfind()`
- `rindex()`
- `rjust()`
- `rpartition()`
- `rsplit()`
- `rstrip()`
- `split()`
- `splitlines()`
- `startswith()`
- `strip()`
- `swapcase()`
- `title()`
- `translate()`
- `upper()`
- `zfill()`
## `Python Loops`
Python loops in Javascript is seems like insane idea. Let me tell What's difference is You can use `==` instead of `===`, use `!=` instead of `!==`, use `and` instead of `&&` and `or` instead of `||` .
`loop` is a object which you can import using ,
```
import { loop } from 'pybuiltinfunc';
```
Then using it is super simple and available method are `if` and `ifElse`.
Here some examples below ,
### `If Loop`
```
loop.if("5<6", ()=>{
// some code...
})
```
After v1.1.8, You can no longer use other than string as first parameter.
First Parameter is condition and Second Parameter is an Anonymous Function.
### `If and Else Loop`
```
loop.if("5<6", ()=>{
// some code runs if true
}, ()=>{
// some code runs if false
})
```
First Parameter is condition, Second Parameter is an Anonymous Function for `If` condition and Third Parameter is also an Anonymous Function for `Else` condition.
### `My Email`
```
abhiajay0206@gmail.com
```