npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@gilbertfrausto/py-script

v1.0.0

Published

A lightweight and versatile library for running your favorite native Python methods in modern JavaScript and TypeScript applications.

Readme

py-script

A lightweight and versatile library for running your favorite native Python methods in modern JavaScript and TypeScript applications.

Installation

npm install @gilbertfrausto/py-script

Usage

Just import any of the methods you need, just like so.

import { len, range } from '@gilbertfrausto/py-script';

const arr = [0,1,2,4];

for (let item of range(5)) {
	console.log(i) // $> 0,1,2,4
}

API

len(element: any[]|Object|string, forLoop?: boolean): number

Gets the length of an array, object, or string.

Parameters:

  • element: The array, object, or string to get the length of.
  • forLoop: A boolean indicating whether to return the length minus one, for use in a for loop. Defaults to false.

Returns:

The length of the element.

Example:

len([1, 2, 3]); // 3
len({a: 1, b: 2}); // 2
len("hello"); // 5

range(startOrEnd: number, end?: number): Generator<number, void, unknown>

Generates a sequence of numbers within a specified range.

Parameters:

  • startOrEnd: The starting number of the sequence, or the ending number if end is not provided.
  • end: The ending number of the sequence.

Yields:

A number in the sequence.

Example:

for (const i of range(5)) {
	console.log(i); // 0, 1, 2, 3, 4
}

for (const i of range(2, 5)) {
	console.log(i); // 2, 3, 4
}

isalpha(str: string): boolean

Checks if a string contains only alphabetic characters.

Parameters:

  • str: The string to check.

Returns:

true if the string contains only alphabetic characters, false otherwise.

Example:

isalpha("hello"); // true
isalpha("hello123"); // false

isdigit(str: string): boolean

Checks if a string contains only digits.

Parameters:

  • str: The string to check.

Returns:

true if the string contains only digits, false otherwise.

Example:

isdigit("123"); // true
isdigit("hello123"); // true
isdigit("hello"); // false

enumarate(object: object): Generator<any[], void, unknown>

Enumerates over an object, yielding [key, value] pairs.

Parameters:

  • object: The object to enumerate over.

Yields:

A [key, value] pair.

Example:

const obj = {a: 1, b: 2};
for (const [key, value] of enumarate(obj)) {
	console.log(key, value); // "a" 1, "b" 2
}

zip<T>(arr_1: Array<T>,arr_2: Array<T>): Generator<unknown, undefined, unknown>

Zips two arrays together, returning an array of tuples.

Parameters:

  • arr_1: The first array.
  • arr_2: The second array.

Yields:

A tuple containing the elements from the two arrays at the same index.

Throws:

An error if the arrays are not of the same length.

Example:

const arr1 = [1, 2, 3];
const arr2 = ["a", "b", "c"];
for (const tuple of zip(arr1, arr2)) {
	console.log(tuple); // [1, "a"], [2, "b"], [3, "c"]
}

integer(count = 0, max = Number.MAX_SAFE_INTEGER, step = 1): () => number | undefined

Creates a function that generates a sequence of integers.

Parameters:

  • count: The starting number of the sequence. Defaults to 0.
  • max: The maximum number of the sequence. Defaults to Number.MAX_SAFE_INTEGER.
  • step: The step to increment the sequence by. Defaults to 1.

Returns:

A function that returns the next number in the sequence, or undefined if the sequence has finished.

Example:

const myInteger = integer(0, 5);
myInteger(); // 0
myInteger(); // 1
myInteger(); // 2
myInteger(); // 3
myInteger(); // 4
myInteger(); // undefined

inter<T>(element: Array<T> | string, gen = integer(0, element.length)): () => any

Creates a function that iterates over an array or string.

Parameters:

  • element: The array or string to iterate over.
  • gen: A function that generates the next index in the sequence. Defaults to a function that generates a sequence of integers from 0 to the length of the element.

Returns:

A function that returns the next element in the sequence, or undefined if the sequence has finished.

Example:

const myInter = inter([1, 2, 3]);
myInter(); // 1
myInter(); // 2
myInter(); // 3
myInter(); // undefined

next(gen: () => any): unknown

Gets the next item from a generator function.

Parameters:

  • gen: The generator function to get the next item from.

Returns:

The next item from the generator function.

Example:

const myInter = inter([1, 2, 3]);
next(myInter); // 1
next(myInter); // 2
next(myInter); // 3
next(myInter); // undefined

max<T extends string | number>(arr: Array<T>): string | number | undefined

Gets the maximum value from an array of numbers or strings.

Parameters:

  • arr: The array to get the maximum value from.

Returns:

The maximum value in the array, or undefined if the array is empty.

Example:

max([1, 2, 3]); // 3
max(["a", "b", "c"]); // "c"

min<T extends string | number>(arr: Array<T>): string | number | undefined

Gets the minimum value from an array of numbers or strings.

Parameters:

  • arr: The array to get the minimum value from.

Returns:

The minimum value in the array, or undefined if the array is empty.

Example:

min([1, 2, 3]); // 1
min(["a", "b", "c"]); // "a"

isinstance(obj: any, type: any): boolean

Checks if an object is an instance of a specified type.

Parameters:

  • obj: The object to check.
  • type: The type to check against. Can be a string (e.g., "str", "int", "float", "bool", "list", "tuple", "set", "dict", "object"), a class, or an array of types.

Returns:

true if the object is an instance of the specified type, false otherwise.

Example:

isinstance("hello", "str"); // true
isinstance(42, "int"); // true
isinstance(3.14, "float"); // true
isinstance(true, "bool"); // true
isinstance([], "list"); // true
isinstance({}, "dict"); // true
isinstance(new Set(), "set"); // true
class Car {}
class ElectricCar extends Car {}
isinstance(new Car(), Car); // true
isinstance(new ElectricCar(), Car); // true
isinstance("text", [Number, "str"]); // true

sum(numbersArr: number[], start = 0): number

Calculates the sum of an array of numbers.

Parameters:

  • numbersArr: The array of numbers to sum.
  • start: A number to add to the sum. Defaults to 0.

Returns:

The sum of the array of numbers.

Throws:

An error if the array contains non-numeric values.

Example:

sum([1, 2, 3]); // 6
sum([1, 2, 3], 4); // 10

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.