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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-pystyle

v1.4.4

Published

typescript in Python style

Downloads

102

Readme

中文说明在下方

Description

Implementing a Python style turn in Typescript This package is large, mainly because the main reason for including the debugging with the sourcemap and source files, packaging will not be packed into the actual source file size 13.6KB

import {  all, any, call, cartesian, delay, enumerate, int, list, print, range, zip, curry} from './lib';
import {input} from "./io"



call(async ()=>{
  let ff=(a,b,c:string,d:string)=>{
    print(a+b+c+d)
    return 1
  }

  let b=curry(ff)
  let cc=b(1,2,3)
  print(b);
  let a=zip(zip([[1,2,3],[2,3,4]]))
  let lst=list(a)
  for(let [i,ii,c] of cartesian(range(10),range(10),range(3),range(3))){
    print([i,ii,c])
  }
  for(;;){
    await delay(1000);
    let test=int(await input("输入数字:"))
    for(let [a,b] of enumerate(zip(zip(range(test),range(test,test*2)))) ){
      print(a,b)
    }
  }

})


async function * test(){
  yield *[1,2,3]
}

Content

  • Some common functions like enumerate,range,print,input,select,len,zip
  • data type related, such as list set map,data type capture str json int float etc.
  • Some general convenience functions such as: shuffle randint
  • Special functions.
    • delay function, asynchronous wait function via callback, combined with async await for pseudo-multi-threading.
    • cartesian, a Cartesian product that can be used to omit multiple loops, supports multiple iterators, and can be combined with zip for many effects
  • Set operation functions: any all, etc.
  • Type judgment function:
    1. assert, exception thrown on false
    2. assertType supports the judgment of types, the types that can be judged are Raw types, i.e., native types and Class types, type aliases, generic interfaces, etc. can not be judged.
  • Extension of the Iterable class to allow iterator wrapping without losing types, support for chain calls, use of iter functions to get

Platform requirements

Test platform.

  • node v14.13.0
  • typescript 4.0.3 Other platforms, please test on your own.

Next plan

  1. Add a large number of type judgment functions
  2. Organize various tool types and add them to generic.ts of ts-metacode

说明

在Typescript中实现Python风格的变成,如 本包体积较大,主要原因为包括了调试用的sourcemap和源文件,打包时不会打包进去,实际源文件大小13.6KB

import {  all, any, call, cartesian, delay, enumerate, int, list, print, range, zip, curry} from './lib';
import {input} from "./io"



call(async ()=>{
  let ff=(a,b,c:string,d:string)=>{
    print(a+b+c+d)
    return 1
  }

  let b=curry(ff)
  let cc=b(1,2,3)
  print(b);
  let a=zip(zip([[1,2,3],[2,3,4]]))
  let lst=list(a)
  for(let [i,ii,c] of cartesian(range(10),range(10),range(3),range(3))){
    print([i,ii,c])
  }
  for(;;){
    await delay(1000);
    let test=int(await input("输入数字:"))
    for(let [a,b] of enumerate(zip(zip(range(test),range(test,test*2)))) ){
      print(a,b)
    }
  }

})


async function * test(){
  yield *[1,2,3]
}

内容

  • 一些常用函数如 enumerate,range,print,input,select,len,zip
  • 数据类型相关,如 list set map,数据类型抓换 str json int float 等
  • 一些通用便利函数如: shuffle randint
  • 特殊函数:
    • delay函数,通过回调实现的异步等待函数,结合async await可实现伪多线程
    • cartesian,笛卡尔积,可用于省略多重循环,支持多个迭代器,结合zip可实现很多效果
    • error 函数,可抛出一个特定消息的错误,简化书写
  • 集合操作函数: any all 等
  • 类型判断函数:
    1. assert,false时抛出异常
    2. assertType 支持对类型进行判断,可判断的类型有 Raw类型即原生类型和Class类型,类型别名 泛型 接口等不能判断
  • 扩展Iterable类,可实现不丢失类型的迭代器包装,支持链式调用,使用iter函数得到

平台要求

测试平台:

  • node v14.13.0
  • typescript 4.0.3 其他平台请自行测试

新增功能说明

  1. curry函数,执行curry化,可让一个函数分次调用,参数足够后执行调用
     let a=(a,b,c,d:number)=>{
       print(a+b+c+d)
       return 1;
     }
    
     let b=curry(a)
     let c=b()
     let d=c(1,2,2)
     let dd=d(1);
    一旦参数类型错误,调用将直接返回never,目前无法实现带名称的参数表和错误提示
    函数调用发生在d调用之后,即当所有函数都传递完毕时调用实际函数 注意curry函数无法接受可变参数列表,请直接使用数组代替
  2. cached函数,可缓存函数调用返回值,在参数没有发生变化时不会重新调用实际函数,此函数会在每次调用时调用deepEqual操作,只有在目标函数耗时长时使用

更新说明 1.2.1-alpha

  1. 去除iter函数,功能重复与rxjs
  2. 测试并更改curry函数,目前curry函数支持简单的类型检测和报错
  3. 去除编译得到的sourcemap文件,修复若干bug

更新说明 1.3.0-alpha

  1. 破坏性更新,将input select open 等函数移动到io模块,需要改变导入方式

更新说明 1.4

  • 移除了多余的ext Iter体系,Rxjs可以很好处理这个问题
  • 移除示例代码中的iter相关内容
  • 将某些只能在nodejs环境中运行的输入输出相关函数移动到了io模块中,引入需要使用
    import {input} from "ts-pystyle/io"