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

hescript

v1.0.1

Published

helang for JavaScript

Downloads

3

Readme

hescript

helang for JavaScript

介绍

来自 kifuan/helang 的启发,我想能不能拓展一下 JavaScript 的语法。也就是说这个项目完全可以在正常写 JavaScript 的时候稍微编译一下用了 helang 的 JavaScript 代码。

使用方法

  1. 安装 hescript
pnpm i hescript -D
  1. 新建配置文件 hescript.config.ts
import type { HeScriptConfig } from 'hescript/src/index'

export default {
  rootDir: 'or-src',           // HeScript 文件根目录,将会把目录下所有 .js .ts .he 进行解析
  outDir: 'src',               // HeScript 文件输出目录,.js .he 将会输出 .js 文件,.ts 将会输出 .ts 文件,此配置仅为 rootDir 的输出
  files: ['a.js', 'b.js'],     // HeScript 文件,可同时指定多个,不限制文件后缀,除 .ts 文件输出 .ts 文件,其他后缀一律输出 .js 文件
  outFilesDir: 'files',        // HeScript 文件输出目录,此配置仅为 files 的输出
  mode: 'Array',               // 模式设置,可选值:Array 或 Abbreviation。若为 Array 在检测是传入参数时将会直接传入 Array,否则将编译成多行传递参数
} as HeScriptConfig

注:如果 mode 设置成 Abbreviation,则 pressCon(1 | 3 | 5, 10) 这样的代码将会编译成:

pressCon(1, 10)
pressCon(3, 10)
pressCon(5, 10)
  1. 执行 hescript
pnpm exec he
# or
npx exec he

也可以在 package.json 文件的 scripts 里面直接写 he

如果配置文件名不是执行目录下的 hescript.config.ts,则执行时传入配置文件目录 path/to/hescript.config.ts

  1. 直接引入 hescript

欢迎在 JavaScript / TypeScript 里直接引入 hescript 比如:

require('hescript')

console.log([1, 2, 3]) // 1 | 2 | 3

将会直接更改原型链为:

Array.prototype.toString = function() {
  return this.join(' | ')
}

console.log = function(...args) {
  logger.l(...args.map((value) => Array.isArray(value) ? value.toString() : value))
}

console.warn = function(...args) {
  logger.w(...args.map((value) => Array.isArray(value) ? value.toString() : value))
}

console.error = function(...args) {
  logger.e(...args.map((value) => Array.isArray(value) ? value.toString() : value))
}

这才是编程语言该有的样子

注意事项

  1. 由于此项目暂时是字符串解析,并不是语法解析。所以仅支持一行内书写。

正确写法:

let a = [1, 2, 3]
a[1 | 3] = 123 // 注意数组下标从 1 开始

错误写法:

let a = [1, 2, 3];a[1 | 3] = 123;pressCon(1 | 2 | 3, 10);
  1. 请按照所给的规范书写配置文件,因为配置文件的内容也是字符串解析

例子

require('hescript')
function pressCon(key, force) {
  // if (config.mode === 'Array') console.log(Array.isArray(key)) // true
  // if (config.mode === 'Abbreviation') console.log(Array.isArray(key)) // false
}

pressCon(1    |3 |35|68 |  339911, 10)

let a = [1, 2, 3]

a[1 | 3] = 233

console.log(a) // 233 | 2 | 233