A js library for those that like python.
npm install -g pythonicjs@latest
npx mocha pythonicjsTest.js
Also check the test file to see how to use and test certain functionality
/** Require*/
require("pythonicjs")()
<script src="https://unpkg.com/pythonicjs@latest"></script>
Prints messages to the console.
print("Hello", "World");
Output
Hello World
Prints a prettified JSON representation of the object.
const exampleObject = { key: 'value', number: 42 };
pprint(exampleObject);
Output
{
"key": "value",
"number": 42
}
Logs messages to the console with a timestamp.
log("This is a log message");
Output
2023-11-12T16:36:11.004Z ::==> This is a log message
Returns the absolute value of a number.
Returns x to the power of y.
returns a random number between min, max
rounds the number to n digits
Returns the sum of all elements in the list.
Returns the maximum value in the list.
Returns the minimum value in the list.
Returns the length of the object, it could be string or list
Returns the average value of the elements in the list.
Sorts a list in ascending or descending order.
const ascending = sorted([3, 1, 4, 1, 5, 9]);
const descending = sorted([3, 1, 4, 1, 5, 9], key=null, reverse=true);
const sorted_dict_ascending = sorted( {b:4, p:5, a:1, q:0, c:-1})
const sorted_dict_descending = sorted( {b:4, p:5, a:1, q:0, c:-1}, key=null, reverse=true)
print(ascending)
print(descending)
print(sorted_dict_ascending)
print(sorted_dict_descending)
output
[ 1, 1, 3, 4, 5, 9 ]
[ 9, 5, 4, 3, 1, 1 ]
{ a: 1, b: 4, c: -1, p: 5, q: 0 }
{ q: 0, p: 5, c: -1, b: 4, a: 1 }
Reverses the order of elements in an array.
const reversedArray = reversed([1, 2, 3, 4]);
print(reversedArray)
output
[4, 3, 2, 1]
Converts an object to a string.
Converts a string to an integer
Converts a string to a float
Returns the current timestamp in ISO format.
2023-11-12T12:34:56.789Z
Returns an array of keys in an object.
Returns an array of values in an object.
Creates a shallow copy of an object or array.
Creates a deep copy of an object or array.
Checks if an object is empty.
Returns a Boolean - a logical negation of the object, just like in Python. Returns true if the object is null or undefined or has length 0
not('') // true
not ("") // true
not([]) // true
not({}) // true
not(null) // true
not(undefined) // true
not(0) // true
not(1) // false
not(-3.5) // false
not(-0.00000001) // false
not([1, 2]) // false
not({"a":"b"}) // false
Returns a Boolean by checking if an object is null.
Returns a Boolean by checking if an object is undefined.
Returns a Boolean by checking if an object is equal to another object
Returns the index of the specified item within the object array. If the item is not found in the array, it returns -1.
Returns the first item of the array
Returns the last item of the array
Returns a new array with all instances of item removed
Returns a new array with elements in array 'a' but not in array 'b'
Returns a new array with unique items present in one or more arrays
Returns a new array with unique items that are common in both arrays
Returns a new that includes only the elements from the original array that are not present in the values array
It converts the given number to a string representation in the specified base
Returns an array from start to end in step increments just like the range function in Python It can be supplied 1 parameter, 2 parameters (start, end), or 3 parameters (start, end, step)
Returns an array that is reversed
Filter the elements of the input array based on the condition specified by the operation function. The operation function is expected to be a callback function that returns a boolean value
Converts the unsigned decimal number 'a' to its hexadecimal representation with a "0x" prefix
applies the provided operation function to each element of the array and returns a new array containing the results.
retrieves the value of the property with the specified name from the given obj.
sets the value of the property with the specified name to the given value in the provided obj
returns a boolean by checking if the specified name is a property in the given obj and
returns an object with key and values inverted
returns a random number between min and max
rounds the number (to ndigits if supplied)
- Categorize functionality a bit better
- write more tests for the functions
- Improve documentation