first
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
|||||||
|
# binaries
|
||||||
|
*/bin/
|
||||||
|
*.exe
|
||||||
|
|
||||||
|
# Go build artifacts
|
||||||
|
*.out
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# IDE
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
# OS
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# protobuf generated
|
||||||
|
internal/grpc/pb/*.pb.go
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
GO := $(shell command -v go 2>/dev/null || echo /usr/local/go/bin/go)
|
||||||
|
BIN_DIR=bin
|
||||||
|
|
||||||
|
DAEMON=$(BIN_DIR)/daemon
|
||||||
|
CLI=$(BIN_DIR)/cli
|
||||||
|
|
||||||
|
PROTO_DIR=proto
|
||||||
|
PROTO_OUT=internal/grpc/pb
|
||||||
|
|
||||||
|
.PHONY: all build clean proto daemon cli daemon-arm64
|
||||||
|
|
||||||
|
all: build
|
||||||
|
|
||||||
|
# =========================
|
||||||
|
# BUILD
|
||||||
|
# =========================
|
||||||
|
|
||||||
|
build: daemon cli daemon-arm64
|
||||||
|
|
||||||
|
daemon:
|
||||||
|
@echo "Building daemon..."
|
||||||
|
@mkdir -p $(BIN_DIR)
|
||||||
|
@$(GO) build -o $(DAEMON) ./cmd/daemon
|
||||||
|
|
||||||
|
cli:
|
||||||
|
@echo "Building cli..."
|
||||||
|
@mkdir -p $(BIN_DIR)
|
||||||
|
@$(GO) build -o $(CLI) ./cmd/cli
|
||||||
|
|
||||||
|
daemon-arm64:
|
||||||
|
@echo "Building daemon for linux/arm64..."
|
||||||
|
@mkdir -p $(BIN_DIR)
|
||||||
|
@GOOS=linux GOARCH=arm64 CGO_ENABLED=0 $(GO) build -o $(BIN_DIR)/daemon-arm64 ./cmd/daemon
|
||||||
|
|
||||||
|
|
||||||
|
# =========================
|
||||||
|
# PROTO
|
||||||
|
# =========================
|
||||||
|
|
||||||
|
proto:
|
||||||
|
@echo "Generating protobuf..."
|
||||||
|
@mkdir -p $(PROTO_OUT)
|
||||||
|
@protoc \
|
||||||
|
--go_out=. \
|
||||||
|
--go-grpc_out=. \
|
||||||
|
-I $(PROTO_DIR) \
|
||||||
|
$(PROTO_DIR)/*.proto
|
||||||
|
|
||||||
|
|
||||||
|
# =========================
|
||||||
|
# CLEAN
|
||||||
|
# =========================
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo "Cleaning binaries..."
|
||||||
|
@rm -rf $(BIN_DIR)/*
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# SPEKTR
|
||||||
|
|
||||||
|
Минимальный Go-прототип: gRPC daemon + UART bridge + CLI discovery.
|
||||||
|
|
||||||
|
## Команды
|
||||||
|
- `av`
|
||||||
|
- `af <mhz>`
|
||||||
|
- `get`
|
||||||
|
|
||||||
|
## Запуск
|
||||||
|
- daemon: `go run ./cmd/daemon`
|
||||||
|
- cli: `go run ./cmd/cli`
|
||||||
+150
@@ -0,0 +1,150 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"spektr/internal/config"
|
||||||
|
"spektr/internal/discovery"
|
||||||
|
grpcclient "spektr/internal/grpc"
|
||||||
|
pb "spektr/internal/grpc/pb"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
configPath := flag.String("config", "configs/config.yaml", "path to config file")
|
||||||
|
addrOverride := flag.String("addr", "192.168.1.10:50051", "explicit gRPC address")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
cfg, err := config.Load(*configPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
for {
|
||||||
|
addr := resolveAddr(cfg, *addrOverride)
|
||||||
|
client, err := waitForClient(addr)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Подключено к", addr)
|
||||||
|
printHelp()
|
||||||
|
|
||||||
|
lostConnection := false
|
||||||
|
for {
|
||||||
|
fmt.Print("> ")
|
||||||
|
if !scanner.Scan() {
|
||||||
|
_ = client.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
line := strings.TrimSpace(scanner.Text())
|
||||||
|
switch {
|
||||||
|
case line == "", line == "help":
|
||||||
|
printHelp()
|
||||||
|
case line == "exit":
|
||||||
|
_ = client.Close()
|
||||||
|
return
|
||||||
|
case line == "av":
|
||||||
|
lostConnection = !sendAndPrint(client, &pb.ClientMessage{RequestId: requestID(), Payload: &pb.ClientMessage_Av{Av: &pb.AvCommand{}}})
|
||||||
|
case line == "get":
|
||||||
|
lostConnection = !sendAndPrint(client, &pb.ClientMessage{RequestId: requestID(), Payload: &pb.ClientMessage_GetFrequency{GetFrequency: &pb.GetFrequencyCommand{}}})
|
||||||
|
case strings.HasPrefix(line, "af "):
|
||||||
|
value := strings.TrimSpace(strings.TrimPrefix(line, "af "))
|
||||||
|
mhz, err := strconv.ParseUint(value, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("invalid frequency")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
lostConnection = !sendAndPrint(client, &pb.ClientMessage{RequestId: requestID(), Payload: &pb.ClientMessage_SetFrequency{SetFrequency: &pb.SetFrequencyCommand{Frequency: uint32(mhz)}}})
|
||||||
|
default:
|
||||||
|
fmt.Println("unknown command")
|
||||||
|
}
|
||||||
|
|
||||||
|
if lostConnection {
|
||||||
|
_ = client.Close()
|
||||||
|
fmt.Println("Соединение потеряно, ожидаю демон...")
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func resolveAddr(cfg config.Config, override string) string {
|
||||||
|
if override != "" {
|
||||||
|
return override
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
discovered, err := discovery.Discover(ctx, cfg.DiscoveryPort)
|
||||||
|
if err == nil && discovered != "" {
|
||||||
|
return discovered
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg.GRPCAdvertiseAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
func waitForClient(addr string) (*grpcclient.Client, error) {
|
||||||
|
for {
|
||||||
|
dialCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
client, err := grpcclient.Dial(dialCtx, addr)
|
||||||
|
cancel()
|
||||||
|
if err == nil {
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("Демон недоступен, жду подключение...")
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func printHelp() {
|
||||||
|
fmt.Println("Доступные команды:")
|
||||||
|
fmt.Println(" av - проверить связь с устройством")
|
||||||
|
fmt.Println(" af <мгц> - установить частоту, например: af 1880")
|
||||||
|
fmt.Println(" get - показать текущую частоту")
|
||||||
|
fmt.Println(" help - показать список команд")
|
||||||
|
fmt.Println(" exit - выйти из CLI")
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendAndPrint(client *grpcclient.Client, msg *pb.ClientMessage) bool {
|
||||||
|
resp, err := client.Send(msg)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("error:", err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
switch payload := resp.GetPayload().(type) {
|
||||||
|
case *pb.ServerMessage_Av:
|
||||||
|
fmt.Printf("HW: %s FW: %s\n", payload.Av.GetHw(), payload.Av.GetSw())
|
||||||
|
case *pb.ServerMessage_SetFrequency:
|
||||||
|
fmt.Println("ok")
|
||||||
|
case *pb.ServerMessage_GetFrequency:
|
||||||
|
fmt.Printf("%s\n", formatFrequencyResponse(payload.GetFrequency.GetFrequency()))
|
||||||
|
case *pb.ServerMessage_Error:
|
||||||
|
fmt.Println("error:", payload.Error.GetMessage())
|
||||||
|
default:
|
||||||
|
fmt.Println("unknown response")
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func requestID() string {
|
||||||
|
return strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatFrequencyResponse(freq uint32) string {
|
||||||
|
return fmt.Sprintf("f%07d", freq*100)
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"spektr/internal/config"
|
||||||
|
"spektr/internal/discovery"
|
||||||
|
grpcserver "spektr/internal/grpc"
|
||||||
|
"spektr/internal/service"
|
||||||
|
"spektr/internal/uart"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
configPath := flag.String("config", "./config.yaml", "path to config file")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
cfg, err := config.Load(*configPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := uart.New(cfg.UARTDevice, cfg.UARTBaud)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
log.Printf("UART opened: %s @ %d", cfg.UARTDevice, cfg.UARTBaud)
|
||||||
|
defer u.Close()
|
||||||
|
|
||||||
|
svc := service.New(u)
|
||||||
|
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
if err := discovery.Serve(ctx, cfg.DiscoveryPort, cfg.GRPCAdvertiseAddr); err != nil {
|
||||||
|
log.Println("discovery stopped:", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err := grpcserver.Serve(ctx, cfg.GRPCListenAddr, svc); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
grpc_listen_addr: ":50051"
|
||||||
|
grpc_advertise_addr: "127.0.0.1:50051"
|
||||||
|
discovery_port: 50052
|
||||||
|
uart_device: "/dev/ttyS3"
|
||||||
|
uart_baud: 115200
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
module spektr
|
||||||
|
|
||||||
|
go 1.26.4
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
|
||||||
|
github.com/wailsapp/wails/v2 v2.12.0
|
||||||
|
google.golang.org/grpc v1.81.1
|
||||||
|
google.golang.org/protobuf v1.36.11
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 // indirect
|
||||||
|
github.com/bep/debounce v1.2.1 // indirect
|
||||||
|
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||||
|
github.com/godbus/dbus/v5 v5.1.0 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
|
github.com/gorilla/websocket v1.5.3 // indirect
|
||||||
|
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
|
||||||
|
github.com/labstack/echo/v4 v4.13.3 // indirect
|
||||||
|
github.com/labstack/gommon v0.4.2 // indirect
|
||||||
|
github.com/leaanthony/go-ansi-parser v1.6.1 // indirect
|
||||||
|
github.com/leaanthony/gosod v1.0.4 // indirect
|
||||||
|
github.com/leaanthony/slicer v1.6.0 // indirect
|
||||||
|
github.com/leaanthony/u v1.1.1 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||||
|
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
|
||||||
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
|
github.com/samber/lo v1.49.1 // indirect
|
||||||
|
github.com/tkrajina/go-reflector v0.5.8 // indirect
|
||||||
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
|
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||||
|
github.com/wailsapp/go-webview2 v1.0.22 // indirect
|
||||||
|
github.com/wailsapp/mimetype v1.4.1 // indirect
|
||||||
|
golang.org/x/crypto v0.48.0 // indirect
|
||||||
|
golang.org/x/net v0.51.0 // indirect
|
||||||
|
golang.org/x/sys v0.42.0 // indirect
|
||||||
|
golang.org/x/text v0.34.0 // indirect
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 // indirect
|
||||||
|
)
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3 h1:N3IGoHHp9pb6mj1cbXbuaSXV/UMKwmbKLf53nQmtqMA=
|
||||||
|
git.sr.ht/~jackmordaunt/go-toast/v2 v2.0.3/go.mod h1:QtOLZGz8olr4qH2vWK0QH0w0O4T9fEIjMuWpKUsH7nc=
|
||||||
|
github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
|
||||||
|
github.com/bep/debounce v1.2.1/go.mod h1:H8yggRPQKLUhUoqrJC1bO2xNya7vanpDl7xR3ISbCJ0=
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||||
|
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
|
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
|
||||||
|
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
|
||||||
|
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||||
|
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||||
|
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||||
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e h1:Q3+PugElBCf4PFpxhErSzU3/PY5sFL5Z6rfv4AbGAck=
|
||||||
|
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e/go.mod h1:alcuEEnZsY1WQsagKhZDsoPCRoOijYqhZvPwLG0kzVs=
|
||||||
|
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
|
||||||
|
github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
|
||||||
|
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
||||||
|
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
|
||||||
|
github.com/leaanthony/debme v1.2.1 h1:9Tgwf+kjcrbMQ4WnPcEIUcQuIZYqdWftzZkBr+i/oOc=
|
||||||
|
github.com/leaanthony/debme v1.2.1/go.mod h1:3V+sCm5tYAgQymvSOfYQ5Xx2JCr+OXiD9Jkw3otUjiA=
|
||||||
|
github.com/leaanthony/go-ansi-parser v1.6.1 h1:xd8bzARK3dErqkPFtoF9F3/HgN8UQk0ed1YDKpEz01A=
|
||||||
|
github.com/leaanthony/go-ansi-parser v1.6.1/go.mod h1:+vva/2y4alzVmmIEpk9QDhA7vLC5zKDTRwfZGOp3IWU=
|
||||||
|
github.com/leaanthony/gosod v1.0.4 h1:YLAbVyd591MRffDgxUOU1NwLhT9T1/YiwjKZpkNFeaI=
|
||||||
|
github.com/leaanthony/gosod v1.0.4/go.mod h1:GKuIL0zzPj3O1SdWQOdgURSuhkF+Urizzxh26t9f1cw=
|
||||||
|
github.com/leaanthony/slicer v1.6.0 h1:1RFP5uiPJvT93TAHi+ipd3NACobkW53yUiBqZheE/Js=
|
||||||
|
github.com/leaanthony/slicer v1.6.0/go.mod h1:o/Iz29g7LN0GqH3aMjWAe90381nyZlDNquK+mtH2Fj8=
|
||||||
|
github.com/leaanthony/u v1.1.1 h1:TUFjwDGlNX+WuwVEzDqQwC2lOv0P4uhTQw7CMFdiK7M=
|
||||||
|
github.com/leaanthony/u v1.1.1/go.mod h1:9+o6hejoRljvZ3BzdYlVL0JYCwtnAsVuN9pVTQcaRfI=
|
||||||
|
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
|
||||||
|
github.com/matryer/is v1.4.1 h1:55ehd8zaGABKLXQUe2awZ99BD/PTc2ls+KV/dXphgEQ=
|
||||||
|
github.com/matryer/is v1.4.1/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
|
||||||
|
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||||
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
|
||||||
|
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
|
||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
|
||||||
|
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
|
||||||
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
|
||||||
|
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
||||||
|
github.com/tkrajina/go-reflector v0.5.8 h1:yPADHrwmUbMq4RGEyaOUpz2H90sRsETNVpjzo3DLVQQ=
|
||||||
|
github.com/tkrajina/go-reflector v0.5.8/go.mod h1:ECbqLgccecY5kPmPmXg1MrHW585yMcDkVl6IvJe64T4=
|
||||||
|
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||||
|
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||||
|
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||||
|
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||||
|
github.com/wailsapp/go-webview2 v1.0.22 h1:YT61F5lj+GGaat5OB96Aa3b4QA+mybD0Ggq6NZijQ58=
|
||||||
|
github.com/wailsapp/go-webview2 v1.0.22/go.mod h1:qJmWAmAmaniuKGZPWwne+uor3AHMB5PFhqiK0Bbj8kc=
|
||||||
|
github.com/wailsapp/mimetype v1.4.1 h1:pQN9ycO7uo4vsUUuPeHEYoUkLVkaRntMnHJxVwYhwHs=
|
||||||
|
github.com/wailsapp/mimetype v1.4.1/go.mod h1:9aV5k31bBOv5z6u+QP8TltzvNGJPmNJD4XlAL3U+j3o=
|
||||||
|
github.com/wailsapp/wails/v2 v2.12.0 h1:BHO/kLNWFHYjCzucxbzAYZWUjub1Tvb4cSguQozHn5c=
|
||||||
|
github.com/wailsapp/wails/v2 v2.12.0/go.mod h1:mo1bzK1DEJrobt7YrBjgxvb5Sihb1mhAY09hppbibQg=
|
||||||
|
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||||
|
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||||
|
go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=
|
||||||
|
go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0=
|
||||||
|
go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM=
|
||||||
|
go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY=
|
||||||
|
go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg=
|
||||||
|
go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg=
|
||||||
|
go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw=
|
||||||
|
go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A=
|
||||||
|
go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A=
|
||||||
|
go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0=
|
||||||
|
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
|
||||||
|
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
|
||||||
|
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
|
||||||
|
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
|
||||||
|
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo=
|
||||||
|
golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
|
||||||
|
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
|
||||||
|
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 h1:ggcbiqK8WWh6l1dnltU4BgWGIGo+EVYxCaAPih/zQXQ=
|
||||||
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||||
|
google.golang.org/grpc v1.81.1 h1:VnnIIZ88UzOOKLukQi+ImGz8O1Wdp8nAGGnvOfEIWQQ=
|
||||||
|
google.golang.org/grpc v1.81.1/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I=
|
||||||
|
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||||
|
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# README
|
||||||
|
|
||||||
|
## About
|
||||||
|
|
||||||
|
This is the official Wails Vanilla template.
|
||||||
|
|
||||||
|
You can configure the project by editing `wails.json`. More information about the project settings can be found
|
||||||
|
here: https://wails.io/docs/reference/project-config
|
||||||
|
|
||||||
|
## Live Development
|
||||||
|
|
||||||
|
To run in live development mode, run `wails dev` in the project directory. This will run a Vite development
|
||||||
|
server that will provide very fast hot reload of your frontend changes. If you want to develop in a browser
|
||||||
|
and have access to your Go methods, there is also a dev server that runs on http://localhost:34115. Connect
|
||||||
|
to this in your browser, and you can call your Go code from devtools.
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
To build a redistributable, production mode package, use `wails build`.
|
||||||
@@ -0,0 +1,287 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"strconv"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"spektr/internal/config"
|
||||||
|
"spektr/internal/discovery"
|
||||||
|
grpcclient "spektr/internal/grpc"
|
||||||
|
pb "spektr/internal/grpc/pb"
|
||||||
|
|
||||||
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
const HardAddr = "192.168.1.10:50051"
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
ctx context.Context
|
||||||
|
mu sync.Mutex
|
||||||
|
client *grpcclient.Client
|
||||||
|
currentFrequency string
|
||||||
|
connectionStatus string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApp() *App {
|
||||||
|
return &App{
|
||||||
|
currentFrequency: "145",
|
||||||
|
connectionStatus: "модуль не подключен",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) startup(ctx context.Context) {
|
||||||
|
a.ctx = ctx
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
client, status := connectClient(ctx)
|
||||||
|
a.mu.Lock()
|
||||||
|
defer a.mu.Unlock()
|
||||||
|
a.client = client
|
||||||
|
a.connectionStatus = status
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) Quit() {
|
||||||
|
a.mu.Lock()
|
||||||
|
client := a.client
|
||||||
|
a.client = nil
|
||||||
|
a.mu.Unlock()
|
||||||
|
|
||||||
|
if client != nil {
|
||||||
|
_ = client.Close()
|
||||||
|
}
|
||||||
|
runtime.Quit(a.ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeviceResponse struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Frequency string `json:"frequency"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) CheckConnection() (DeviceResponse, error) {
|
||||||
|
log.Println("CheckConnection called")
|
||||||
|
start := time.Now()
|
||||||
|
log.Println("[TIMING] CheckConnection START")
|
||||||
|
resp := DeviceResponse{
|
||||||
|
Status: "модуль не подключен",
|
||||||
|
Frequency: a.getFrequency(),
|
||||||
|
}
|
||||||
|
|
||||||
|
//клиента вызываю в другом месте теперь
|
||||||
|
//client, err := a.getClientOrConnect()
|
||||||
|
//if err != nil {
|
||||||
|
// return resp, err
|
||||||
|
//}
|
||||||
|
|
||||||
|
//avMsg, err := client.Send(&pb.ClientMessage{
|
||||||
|
// RequestId: requestID(),
|
||||||
|
// Payload: &pb.ClientMessage_Av{Av: &pb.AvCommand{}},
|
||||||
|
//})
|
||||||
|
t1 := time.Now()
|
||||||
|
avMsg, err := a.sendWithReconnect(func() *pb.ClientMessage {
|
||||||
|
return &pb.ClientMessage{
|
||||||
|
RequestId: requestID(),
|
||||||
|
Payload: &pb.ClientMessage_Av{Av: &pb.AvCommand{}},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
log.Printf("[TIMING] AV request took: %v", time.Since(t1))
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
if errMsg := avMsg.GetError(); errMsg != nil {
|
||||||
|
return resp, errors.New(errMsg.GetMessage())
|
||||||
|
}
|
||||||
|
if av := avMsg.GetAv(); av != nil {
|
||||||
|
resp.Status = fmt.Sprintf("HW: %s FW: %s", av.GetHw(), av.GetSw())
|
||||||
|
}
|
||||||
|
|
||||||
|
//freqMsg, err := client.Send(&pb.ClientMessage{
|
||||||
|
// RequestId: requestID(),
|
||||||
|
// Payload: &pb.ClientMessage_GetFrequency{GetFrequency: &pb.GetFrequencyCommand{}},
|
||||||
|
//})
|
||||||
|
t2 := time.Now()
|
||||||
|
freqMsg, err := a.sendWithReconnect(func() *pb.ClientMessage {
|
||||||
|
return &pb.ClientMessage{
|
||||||
|
RequestId: requestID(),
|
||||||
|
Payload: &pb.ClientMessage_GetFrequency{GetFrequency: &pb.GetFrequencyCommand{}},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
log.Printf("[TIMING] GetFreq request took: %v", time.Since(t2))
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
if errMsg := freqMsg.GetError(); errMsg != nil {
|
||||||
|
return resp, errors.New(errMsg.GetMessage())
|
||||||
|
}
|
||||||
|
if freq := freqMsg.GetGetFrequency(); freq != nil {
|
||||||
|
resp.Frequency = strconv.FormatUint(uint64(freq.GetFrequency()), 10)
|
||||||
|
a.setFrequency(resp.Frequency)
|
||||||
|
}
|
||||||
|
|
||||||
|
a.mu.Lock()
|
||||||
|
a.connectionStatus = resp.Status
|
||||||
|
a.mu.Unlock()
|
||||||
|
log.Printf("[TIMING] CheckConnection TOTAL: %v", time.Since(start))
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) SetFrequency(freq string) (string, error) {
|
||||||
|
val, err := strconv.Atoi(freq)
|
||||||
|
if err != nil || val < 70 || val > 8545 {
|
||||||
|
//return "", errors.New("вводимое значение должно быть целым положительным числом")
|
||||||
|
return "", errors.New(`
|
||||||
|
- значение может быть только числом
|
||||||
|
- диапазон от 70 до 8545
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|
||||||
|
//клиента я вызываю теперь в другом месте
|
||||||
|
//client, err := a.getClientOrConnect()
|
||||||
|
//if err != nil {
|
||||||
|
// return "", err
|
||||||
|
//}
|
||||||
|
|
||||||
|
//resp, err := client.Send(&pb.ClientMessage{
|
||||||
|
// RequestId: requestID(),
|
||||||
|
// Payload: &pb.ClientMessage_SetFrequency{
|
||||||
|
// SetFrequency: &pb.SetFrequencyCommand{Frequency: uint32(val)},
|
||||||
|
// },
|
||||||
|
//})
|
||||||
|
resp, err := a.sendWithReconnect(func() *pb.ClientMessage {
|
||||||
|
return &pb.ClientMessage{
|
||||||
|
RequestId: requestID(),
|
||||||
|
Payload: &pb.ClientMessage_SetFrequency{
|
||||||
|
SetFrequency: &pb.SetFrequencyCommand{Frequency: uint32(val)},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if errMsg := resp.GetError(); errMsg != nil {
|
||||||
|
return "", errors.New(errMsg.GetMessage())
|
||||||
|
}
|
||||||
|
if ack := resp.GetSetFrequency(); ack != nil && !ack.GetOk() {
|
||||||
|
return "", errors.New("не удалось установить частоту")
|
||||||
|
}
|
||||||
|
|
||||||
|
freqStr := strconv.Itoa(val)
|
||||||
|
a.setFrequency(freqStr)
|
||||||
|
return freqStr, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) getClient() *grpcclient.Client {
|
||||||
|
a.mu.Lock()
|
||||||
|
defer a.mu.Unlock()
|
||||||
|
return a.client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) getClientOrConnect() (*grpcclient.Client, error) {
|
||||||
|
client := a.getClient()
|
||||||
|
if client != nil {
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := a.ctx
|
||||||
|
if ctx == nil {
|
||||||
|
ctx = context.Background()
|
||||||
|
}
|
||||||
|
|
||||||
|
client, status := connectClient(ctx)
|
||||||
|
if client == nil {
|
||||||
|
return nil, errors.New(status)
|
||||||
|
}
|
||||||
|
|
||||||
|
a.mu.Lock()
|
||||||
|
if a.client == nil {
|
||||||
|
a.client = client
|
||||||
|
a.connectionStatus = status
|
||||||
|
a.mu.Unlock()
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
existing := a.client
|
||||||
|
a.mu.Unlock()
|
||||||
|
|
||||||
|
_ = client.Close()
|
||||||
|
return existing, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) dropClient(client *grpcclient.Client) {
|
||||||
|
a.mu.Lock()
|
||||||
|
if a.client == client {
|
||||||
|
a.client = nil
|
||||||
|
a.connectionStatus = "модуль не подключен"
|
||||||
|
}
|
||||||
|
a.mu.Unlock()
|
||||||
|
|
||||||
|
if client != nil {
|
||||||
|
_ = client.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) sendWithReconnect(build func() *pb.ClientMessage) (*pb.ServerMessage, error) {
|
||||||
|
client, err := a.getClientOrConnect()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Send(build())
|
||||||
|
if err == nil {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// stream умер (часто после рестарта демона) — сбрасываем и пробуем 1 раз заново
|
||||||
|
a.dropClient(client)
|
||||||
|
|
||||||
|
client, err = a.getClientOrConnect()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.Send(build())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) getFrequency() string {
|
||||||
|
a.mu.Lock()
|
||||||
|
defer a.mu.Unlock()
|
||||||
|
return a.currentFrequency
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) setFrequency(freq string) {
|
||||||
|
a.mu.Lock()
|
||||||
|
a.currentFrequency = freq
|
||||||
|
a.mu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func connectClient(ctx context.Context) (*grpcclient.Client, string) {
|
||||||
|
cfg := config.Default()
|
||||||
|
addr := cfg.GRPCAdvertiseAddr
|
||||||
|
|
||||||
|
discoveryCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
|
||||||
|
if discovered, err := discovery.Discover(discoveryCtx, cfg.DiscoveryPort); err == nil && discovered != "" {
|
||||||
|
addr = discovered
|
||||||
|
}
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
dialCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
//client, err := grpcclient.Dial(dialCtx, addr)
|
||||||
|
client, err := grpcclient.Dial(dialCtx, HardAddr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("gRPC connect failed: %v", err)
|
||||||
|
return nil, "gRPC-клиент недоступен"
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("connected to gRPC at %s", addr)
|
||||||
|
return client, "модуль подключен"
|
||||||
|
}
|
||||||
|
|
||||||
|
func requestID() string {
|
||||||
|
return strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"fixed": {
|
||||||
|
"file_version": "{{.Info.ProductVersion}}"
|
||||||
|
},
|
||||||
|
"info": {
|
||||||
|
"0000": {
|
||||||
|
"ProductVersion": "{{.Info.ProductVersion}}",
|
||||||
|
"CompanyName": "{{.Info.CompanyName}}",
|
||||||
|
"FileDescription": "{{.Info.ProductName}}",
|
||||||
|
"LegalCopyright": "{{.Info.Copyright}}",
|
||||||
|
"ProductName": "{{.Info.ProductName}}",
|
||||||
|
"Comments": "{{.Info.Comments}}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<assemblyIdentity type="win32" name="com.wails.{{.Name}}" version="{{.Info.ProductVersion}}.0" processorArchitecture="*"/>
|
||||||
|
<dependency>
|
||||||
|
<dependentAssembly>
|
||||||
|
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
|
||||||
|
</dependentAssembly>
|
||||||
|
</dependency>
|
||||||
|
<asmv3:application>
|
||||||
|
<asmv3:windowsSettings>
|
||||||
|
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware> <!-- fallback for Windows 7 and 8 -->
|
||||||
|
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2,permonitor</dpiAwareness> <!-- falls back to per-monitor if per-monitor v2 is not supported -->
|
||||||
|
</asmv3:windowsSettings>
|
||||||
|
</asmv3:application>
|
||||||
|
</assembly>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
*{margin:0;padding:0;box-sizing:border-box}html,body{width:100%;height:100%;display:flex;justify-content:center;align-items:center;background-color:#f0f0f0;font-family:Arial,sans-serif}#app{width:400px;background:white;border-radius:8px;box-shadow:0 2px 10px #0000001a;overflow:hidden}.tabs{display:flex;background:#e9e9e9}.tab-button{flex:1;padding:12px;background:transparent;border:none;cursor:pointer;font-size:16px;transition:background .2s}.tab-button:hover{background:#dcdcdc}.tab-button.active{background:white;border-bottom:3px solid #3498db;font-weight:700}.tab-content{display:none;padding:20px}.tab-content.active{display:block}.buttons-vertical{display:flex;flex-direction:column;gap:12px;margin-bottom:20px}.action-button{padding:12px;font-size:16px;cursor:pointer;border:1px solid #bbb;border-radius:6px;background-color:#f8f8f8;transition:background-color .2s,border-color .2s}.action-button:hover{background-color:#e2e6ea;border-color:#999}.close-button{background-color:#e74c3c;color:#fff;border-color:#c0392b}.close-button:hover{background-color:#c0392b}#frequency-panel{display:flex;justify-content:space-between;align-items:center;padding:10px 14px;background-color:#f9f9f9;border:1px solid #ddd;border-radius:6px;margin-bottom:10px}#frequency-label{font-weight:700;color:#555}#frequency-value{font-size:18px;color:#2c3e50}#status-panel{display:flex;align-items:center;gap:10px;padding:10px 14px;background-color:#f9f9f9;border:1px solid #ddd;border-radius:6px}.indicator{width:16px;height:16px;border-radius:50%;display:inline-block}.indicator-red{background-color:#e74c3c}.indicator-green{background-color:#2ecc71}#status-text{font-size:16px;color:#333}.modal{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,.4);display:flex;justify-content:center;align-items:center;z-index:100}.modal.hidden{display:none}.modal-content{background:white;padding:20px;border-radius:8px;width:300px;box-shadow:0 5px 15px #0000004d;position:relative}.close-modal{position:absolute;top:10px;right:15px;font-size:22px;cursor:pointer;color:#777}.close-modal:hover{color:#333}.modal-content h3{margin-bottom:15px;text-align:center}.freq-input-group{display:flex;align-items:center;justify-content:center;gap:10px;margin-bottom:15px}.freq-btn{width:40px;height:40px;font-size:20px;background:#3498db;color:#fff;border:none;border-radius:4px;cursor:pointer;transition:background .2s}.freq-btn:hover{background:#2980b9}#freq-input{width:100px;padding:8px;font-size:18px;text-align:center;border:1px solid #ccc;border-radius:4px}#btn-set-freq{display:block;width:100%;margin-top:10px}.error-msg{color:#e74c3c;margin-top:8px;text-align:center;font-size:14px}.error-msg.hidden{display:none}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
(function(){const i=document.createElement("link").relList;if(i&&i.supports&&i.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))a(t);new MutationObserver(t=>{for(const n of t)if(n.type==="childList")for(const s of n.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&a(s)}).observe(document,{childList:!0,subtree:!0});function m(t){const n={};return t.integrity&&(n.integrity=t.integrity),t.referrerpolicy&&(n.referrerPolicy=t.referrerpolicy),t.crossorigin==="use-credentials"?n.credentials="include":t.crossorigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function a(t){if(t.ep)return;t.ep=!0;const n=m(t);fetch(t.href,n)}})();function h(){return window.go.main.App.CheckConnection()}function b(){return window.go.main.App.Quit()}function p(d){return window.go.main.App.SetFrequency(d)}(function(){const d=document.querySelectorAll(".tab-button"),i=document.querySelectorAll(".tab-content");d.forEach(e=>{e.addEventListener("click",()=>{d.forEach(c=>c.classList.remove("active")),i.forEach(c=>c.classList.remove("active")),e.classList.add("active");const y=e.getAttribute("data-tab");document.getElementById(`tab-${y}`).classList.add("active")})});const m=document.getElementById("btn-check"),a=document.getElementById("btn-freq"),t=document.getElementById("btn-quit"),n=document.getElementById("status-indicator"),s=document.getElementById("status-text"),f=document.getElementById("frequency-label"),u=document.getElementById("frequency-value"),l=document.getElementById("freq-modal"),g=document.getElementById("close-modal"),r=document.getElementById("freq-input"),v=document.getElementById("btn-minus"),E=document.getElementById("btn-plus"),L=document.getElementById("btn-set-freq"),o=document.getElementById("modal-error");m.addEventListener("click",()=>{h().then(e=>{n.classList.remove("indicator-red"),n.classList.add("indicator-green"),s.textContent=`\u0421\u043E\u0435\u0434\u0438\u043D\u0435\u043D\u0438\u0435 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043E! ${e.status}`,f.textContent="\u0422\u0435\u043A\u0443\u0449\u0430\u044F \u0447\u0430\u0441\u0442\u043E\u0442\u0430:",u.textContent=e.frequency}).catch(e=>{console.error("\u041E\u0448\u0438\u0431\u043A\u0430 CheckConnection:",e),s.textContent="\u041E\u0448\u0438\u0431\u043A\u0430: \u043D\u0435 \u0443\u0434\u0430\u043B\u043E\u0441\u044C \u0432\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u044C \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0443"})}),a.addEventListener("click",()=>{l.classList.remove("hidden");const e=u.textContent!=="---"?u.textContent:"145";r.value=e,o.classList.add("hidden")}),g.addEventListener("click",()=>{l.classList.add("hidden")}),window.addEventListener("click",e=>{e.target===l&&l.classList.add("hidden")}),v.addEventListener("click",()=>{let e=parseInt(r.value,10)||1;e=Math.max(1,e-1),r.value=e.toString()}),E.addEventListener("click",()=>{let e=parseInt(r.value,10)||1;e+=1,r.value=e.toString()}),L.addEventListener("click",()=>{const e=r.value.trim();if(!/^\d+$/.test(e)){o.textContent="\u0412\u0432\u043E\u0434\u0438\u043C\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0446\u0435\u043B\u044B\u043C \u043F\u043E\u043B\u043E\u0436\u0438\u0442\u0435\u043B\u044C\u043D\u044B\u043C \u0447\u0438\u0441\u043B\u043E\u043C",o.classList.remove("hidden");return}if(parseInt(e,10)<=0){o.textContent="\u0412\u0432\u043E\u0434\u0438\u043C\u043E\u0435 \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u0434\u043E\u043B\u0436\u043D\u043E \u0431\u044B\u0442\u044C \u0446\u0435\u043B\u044B\u043C \u043F\u043E\u043B\u043E\u0436\u0438\u0442\u0435\u043B\u044C\u043D\u044B\u043C \u0447\u0438\u0441\u043B\u043E\u043C",o.classList.remove("hidden");return}p(e).then(c=>{f.textContent="\u0423\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043D\u0430\u044F \u0447\u0430\u0441\u0442\u043E\u0442\u0430:",u.textContent=c,l.classList.add("hidden")}).catch(c=>{o.textContent=c,o.classList.remove("hidden")})}),t.addEventListener("click",()=>{b()})})();
|
||||||
Vendored
+67
@@ -0,0 +1,67 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
|
||||||
|
<title>Тест (Спектр)</title>
|
||||||
|
<script type="module" crossorigin src="/assets/index.cb23cfd6.js"></script>
|
||||||
|
<link rel="stylesheet" href="/assets/index.448f6f10.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
<!-- Заголовки вкладок -->
|
||||||
|
<div class="tabs">
|
||||||
|
<button class="tab-button active" data-tab="receiver">Режим приемника</button>
|
||||||
|
<button class="tab-button" data-tab="detector">Режим детектора</button>
|
||||||
|
<button class="tab-button" data-tab="info">Информация</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Содержимое вкладок -->
|
||||||
|
<div class="tab-content active" id="tab-receiver">
|
||||||
|
<div class="buttons-vertical">
|
||||||
|
<button class="action-button" id="btn-check">Проверка подключения</button>
|
||||||
|
<button class="action-button" id="btn-freq">Установка частоты</button>
|
||||||
|
<button class="action-button close-button" id="btn-quit">Закрыть приложение</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Панель частоты (новая, выше статуса) -->
|
||||||
|
<div id="frequency-panel">
|
||||||
|
<span id="frequency-label">Текущая частота:</span>
|
||||||
|
<span id="frequency-value">---</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Панель состояния соединения -->
|
||||||
|
<div id="status-panel">
|
||||||
|
<span id="status-indicator" class="indicator indicator-red"></span>
|
||||||
|
<span id="status-text">Нет соединения</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-content" id="tab-detector">
|
||||||
|
<p>Здесь будет проводиться сканирование доступных частот!</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-content" id="tab-info">
|
||||||
|
<p>О программе: Версия 0.01, сделано на Wails в тэч дм!</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Модальное окно для установки частоты -->
|
||||||
|
<div id="freq-modal" class="modal hidden">
|
||||||
|
<div class="modal-content">
|
||||||
|
<span class="close-modal" id="close-modal">×</span>
|
||||||
|
<h3>Укажите желаемую частоту</h3>
|
||||||
|
<div class="freq-input-group">
|
||||||
|
<button id="btn-minus" class="freq-btn">-</button>
|
||||||
|
<input type="text" id="freq-input" value="145" />
|
||||||
|
<button id="btn-plus" class="freq-btn">+</button>
|
||||||
|
</div>
|
||||||
|
<button id="btn-set-freq" class="action-button">Установить</button>
|
||||||
|
<p id="modal-error" class="error-msg hidden"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="ru">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<link rel="stylesheet" href="./src/style.css" />
|
||||||
|
<title>Тест (Спектр)</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app">
|
||||||
|
<!-- Заголовки вкладок -->
|
||||||
|
<div class="tabs">
|
||||||
|
<button class="tab-button active" data-tab="receiver">Режим приемника</button>
|
||||||
|
<button class="tab-button" data-tab="detector">Режим детектора</button>
|
||||||
|
<button class="tab-button" data-tab="info">Информация</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Содержимое вкладок -->
|
||||||
|
<div class="tab-content active" id="tab-receiver">
|
||||||
|
<div class="buttons-vertical">
|
||||||
|
<button class="action-button" id="btn-check">Проверка подключения</button>
|
||||||
|
<button class="action-button" id="btn-freq">Установка частоты</button>
|
||||||
|
<button class="action-button close-button" id="btn-quit">Закрыть приложение</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Панель частоты (новая, выше статуса) -->
|
||||||
|
<div id="frequency-panel">
|
||||||
|
<span id="frequency-label">Текущая частота:</span>
|
||||||
|
<span id="frequency-value">---</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Панель состояния соединения -->
|
||||||
|
<div id="status-panel">
|
||||||
|
<span id="status-indicator" class="indicator indicator-red"></span>
|
||||||
|
<span id="status-text">Нет соединения</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-content" id="tab-detector">
|
||||||
|
<p>Здесь будет проводиться сканирование доступных частот!</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tab-content" id="tab-info">
|
||||||
|
<p>О программе: Версия 0.01, сделано на Wails в тэч дм!</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Модальное окно для установки частоты -->
|
||||||
|
<div id="freq-modal" class="modal hidden">
|
||||||
|
<div class="modal-content">
|
||||||
|
<span class="close-modal" id="close-modal">×</span>
|
||||||
|
<h3>Укажите желаемую частоту</h3>
|
||||||
|
<div class="freq-input-group">
|
||||||
|
<button id="btn-minus" class="freq-btn">-</button>
|
||||||
|
<input type="text" id="freq-input" value="145" />
|
||||||
|
<button id="btn-plus" class="freq-btn">+</button>
|
||||||
|
</div>
|
||||||
|
<button id="btn-set-freq" class="action-button">Установить</button>
|
||||||
|
<p id="modal-error" class="error-msg hidden"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="module" src="/src/main.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
+302
@@ -0,0 +1,302 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"lockfileVersion": 3,
|
||||||
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"node_modules/es-errors": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz",
|
||||||
|
"integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/esbuild": {
|
||||||
|
"version": "0.15.18",
|
||||||
|
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.15.18.tgz",
|
||||||
|
"integrity": "sha512-x/R72SmW3sSFRm5zrrIjAhCeQSAWoni3CmHEqfQrZIQTM3lVCdehdwuIqaOtfC2slvpdlLa62GYoN8SxT23m6Q==",
|
||||||
|
"dev": true,
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"esbuild": "bin/esbuild"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@esbuild/android-arm": "0.15.18",
|
||||||
|
"@esbuild/linux-loong64": "0.15.18",
|
||||||
|
"esbuild-android-64": "0.15.18",
|
||||||
|
"esbuild-android-arm64": "0.15.18",
|
||||||
|
"esbuild-darwin-64": "0.15.18",
|
||||||
|
"esbuild-darwin-arm64": "0.15.18",
|
||||||
|
"esbuild-freebsd-64": "0.15.18",
|
||||||
|
"esbuild-freebsd-arm64": "0.15.18",
|
||||||
|
"esbuild-linux-32": "0.15.18",
|
||||||
|
"esbuild-linux-64": "0.15.18",
|
||||||
|
"esbuild-linux-arm": "0.15.18",
|
||||||
|
"esbuild-linux-arm64": "0.15.18",
|
||||||
|
"esbuild-linux-mips64le": "0.15.18",
|
||||||
|
"esbuild-linux-ppc64le": "0.15.18",
|
||||||
|
"esbuild-linux-riscv64": "0.15.18",
|
||||||
|
"esbuild-linux-s390x": "0.15.18",
|
||||||
|
"esbuild-netbsd-64": "0.15.18",
|
||||||
|
"esbuild-openbsd-64": "0.15.18",
|
||||||
|
"esbuild-sunos-64": "0.15.18",
|
||||||
|
"esbuild-windows-32": "0.15.18",
|
||||||
|
"esbuild-windows-64": "0.15.18",
|
||||||
|
"esbuild-windows-arm64": "0.15.18"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/esbuild-linux-64": {
|
||||||
|
"version": "0.15.18",
|
||||||
|
"resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.15.18.tgz",
|
||||||
|
"integrity": "sha512-hNSeP97IviD7oxLKFuii5sDPJ+QHeiFTFLoLm7NZQligur8poNOWGIgpQ7Qf8Balb69hptMZzyOBIPtY09GZYw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/esbuild-windows-64": {
|
||||||
|
"version": "0.15.18",
|
||||||
|
"resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.15.18.tgz",
|
||||||
|
"integrity": "sha512-qinug1iTTaIIrCorAUjR0fcBk24fjzEedFYhhispP8Oc7SFvs+XeW3YpAKiKp8dRpizl4YYAhxMjlftAMJiaUw==",
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
],
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"optional": true,
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/function-bind": {
|
||||||
|
"version": "1.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
|
||||||
|
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/hasown": {
|
||||||
|
"version": "2.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz",
|
||||||
|
"integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"function-bind": "^1.1.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/is-core-module": {
|
||||||
|
"version": "2.16.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.2.tgz",
|
||||||
|
"integrity": "sha512-evOr8xfXKxE6qSR0hSXL2r3sd7ALj8+7jQEUvPYcm5sgZFdJ+AYzT6yNmJenvIYQBgIGwfwz08sL8zoL7yq2BA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"hasown": "^2.0.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/nanoid": {
|
||||||
|
"version": "3.3.15",
|
||||||
|
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.15.tgz",
|
||||||
|
"integrity": "sha512-y7Wygv/7mEOvxTuEQDB8StXdMRBWf1kR/tlhAzBRUFkB2jfcLOAxO/SHmOO2zgz1pVgK29/kyupn059/bCHdjA==",
|
||||||
|
"dev": true,
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/ai"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"nanoid": "bin/nanoid.cjs"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/path-parse": {
|
||||||
|
"version": "1.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz",
|
||||||
|
"integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/picocolors": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
|
"node_modules/postcss": {
|
||||||
|
"version": "8.5.15",
|
||||||
|
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.15.tgz",
|
||||||
|
"integrity": "sha512-FfR8sjd4em2T6fb3I2MwAJU7HWVMr9zba+enmQeeWFfCbm+UOC/0X4DS8XtpUTMwWMGbjKYP7xjfNekzyGmB3A==",
|
||||||
|
"dev": true,
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/postcss/"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tidelift",
|
||||||
|
"url": "https://tidelift.com/funding/github/npm/postcss"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/ai"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"nanoid": "^3.3.12",
|
||||||
|
"picocolors": "^1.1.1",
|
||||||
|
"source-map-js": "^1.2.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^10 || ^12 || >=14"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/resolve": {
|
||||||
|
"version": "1.22.12",
|
||||||
|
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.12.tgz",
|
||||||
|
"integrity": "sha512-TyeJ1zif53BPfHootBGwPRYT1RUt6oGWsaQr8UyZW/eAm9bKoijtvruSDEmZHm92CwS9nj7/fWttqPCgzep8CA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"es-errors": "^1.3.0",
|
||||||
|
"is-core-module": "^2.16.1",
|
||||||
|
"path-parse": "^1.0.7",
|
||||||
|
"supports-preserve-symlinks-flag": "^1.0.0"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"resolve": "bin/resolve"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/rollup": {
|
||||||
|
"version": "2.80.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.80.0.tgz",
|
||||||
|
"integrity": "sha512-cIFJOD1DESzpjOBl763Kp1AH7UE/0fcdHe6rZXUdQ9c50uvgigvW97u3IcSeBwOkgqL/PXPBktBCh0KEu5L8XQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"rollup": "dist/bin/rollup"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10.0.0"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"fsevents": "~2.3.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/source-map-js": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/supports-preserve-symlinks-flag": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/vite": {
|
||||||
|
"version": "3.2.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/vite/-/vite-3.2.11.tgz",
|
||||||
|
"integrity": "sha512-K/jGKL/PgbIgKCiJo5QbASQhFiV02X9Jh+Qq0AKCRCRKZtOTVi4t6wh75FDpGf2N9rYOnzH87OEFQNaFy6pdxQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"esbuild": "^0.15.9",
|
||||||
|
"postcss": "^8.4.18",
|
||||||
|
"resolve": "^1.22.1",
|
||||||
|
"rollup": "^2.79.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"vite": "bin/vite.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^14.18.0 || >=16.0.0"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"fsevents": "~2.3.2"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@types/node": ">= 14",
|
||||||
|
"less": "*",
|
||||||
|
"sass": "*",
|
||||||
|
"stylus": "*",
|
||||||
|
"sugarss": "*",
|
||||||
|
"terser": "^5.4.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@types/node": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"less": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"sass": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"stylus": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"sugarss": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"terser": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"root": true,
|
||||||
|
|
||||||
|
"extends": "@ljharb",
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: [ljharb]
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: npm/es-errors
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: # Replace with a single custom sponsorship URL
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [v1.3.0](https://github.com/ljharb/es-errors/compare/v1.2.1...v1.3.0) - 2024-02-05
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [New] add `EvalError` and `URIError` [`1927627`](https://github.com/ljharb/es-errors/commit/1927627ba68cb6c829d307231376c967db53acdf)
|
||||||
|
|
||||||
|
## [v1.2.1](https://github.com/ljharb/es-errors/compare/v1.2.0...v1.2.1) - 2024-02-04
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Fix] add missing `exports` entry [`5bb5f28`](https://github.com/ljharb/es-errors/commit/5bb5f280f98922701109d6ebb82eea2257cecc7e)
|
||||||
|
|
||||||
|
## [v1.2.0](https://github.com/ljharb/es-errors/compare/v1.1.0...v1.2.0) - 2024-02-04
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [New] add `ReferenceError` [`6d8cf5b`](https://github.com/ljharb/es-errors/commit/6d8cf5bbb6f3f598d02cf6f30e468ba2caa8e143)
|
||||||
|
|
||||||
|
## [v1.1.0](https://github.com/ljharb/es-errors/compare/v1.0.0...v1.1.0) - 2024-02-04
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [New] add base Error [`2983ab6`](https://github.com/ljharb/es-errors/commit/2983ab65f7bc5441276cb021dc3aa03c78881698)
|
||||||
|
|
||||||
|
## v1.0.0 - 2024-02-03
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- Initial implementation, tests, readme, type [`8f47631`](https://github.com/ljharb/es-errors/commit/8f476317e9ad76f40ad648081829b1a1a3a1288b)
|
||||||
|
- Initial commit [`ea5d099`](https://github.com/ljharb/es-errors/commit/ea5d099ef18e550509ab9e2be000526afd81c385)
|
||||||
|
- npm init [`6f5ebf9`](https://github.com/ljharb/es-errors/commit/6f5ebf9cead474dadd72b9e63dad315820a089ae)
|
||||||
|
- Only apps should have lockfiles [`e1a0aeb`](https://github.com/ljharb/es-errors/commit/e1a0aeb7b80f5cfc56be54d6b2100e915d47def8)
|
||||||
|
- [meta] add `sideEffects` flag [`a9c7d46`](https://github.com/ljharb/es-errors/commit/a9c7d460a492f1d8a241c836bc25a322a19cc043)
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2024 Jordan Harband
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
+55
@@ -0,0 +1,55 @@
|
|||||||
|
# es-errors <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
||||||
|
|
||||||
|
[![github actions][actions-image]][actions-url]
|
||||||
|
[![coverage][codecov-image]][codecov-url]
|
||||||
|
[![License][license-image]][license-url]
|
||||||
|
[![Downloads][downloads-image]][downloads-url]
|
||||||
|
|
||||||
|
[![npm badge][npm-badge-png]][package-url]
|
||||||
|
|
||||||
|
A simple cache for a few of the JS Error constructors.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```js
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
|
const Base = require('es-errors');
|
||||||
|
const Eval = require('es-errors/eval');
|
||||||
|
const Range = require('es-errors/range');
|
||||||
|
const Ref = require('es-errors/ref');
|
||||||
|
const Syntax = require('es-errors/syntax');
|
||||||
|
const Type = require('es-errors/type');
|
||||||
|
const URI = require('es-errors/uri');
|
||||||
|
|
||||||
|
assert.equal(Base, Error);
|
||||||
|
assert.equal(Eval, EvalError);
|
||||||
|
assert.equal(Range, RangeError);
|
||||||
|
assert.equal(Ref, ReferenceError);
|
||||||
|
assert.equal(Syntax, SyntaxError);
|
||||||
|
assert.equal(Type, TypeError);
|
||||||
|
assert.equal(URI, URIError);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
Simply clone the repo, `npm install`, and run `npm test`
|
||||||
|
|
||||||
|
## Security
|
||||||
|
|
||||||
|
Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
|
||||||
|
|
||||||
|
[package-url]: https://npmjs.org/package/es-errors
|
||||||
|
[npm-version-svg]: https://versionbadg.es/ljharb/es-errors.svg
|
||||||
|
[deps-svg]: https://david-dm.org/ljharb/es-errors.svg
|
||||||
|
[deps-url]: https://david-dm.org/ljharb/es-errors
|
||||||
|
[dev-deps-svg]: https://david-dm.org/ljharb/es-errors/dev-status.svg
|
||||||
|
[dev-deps-url]: https://david-dm.org/ljharb/es-errors#info=devDependencies
|
||||||
|
[npm-badge-png]: https://nodei.co/npm/es-errors.png?downloads=true&stars=true
|
||||||
|
[license-image]: https://img.shields.io/npm/l/es-errors.svg
|
||||||
|
[license-url]: LICENSE
|
||||||
|
[downloads-image]: https://img.shields.io/npm/dm/es-errors.svg
|
||||||
|
[downloads-url]: https://npm-stat.com/charts.html?package=es-errors
|
||||||
|
[codecov-image]: https://codecov.io/gh/ljharb/es-errors/branch/main/graphs/badge.svg
|
||||||
|
[codecov-url]: https://app.codecov.io/gh/ljharb/es-errors/
|
||||||
|
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/es-errors
|
||||||
|
[actions-url]: https://github.com/ljharb/es-errors/actions
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
declare const EvalError: EvalErrorConstructor;
|
||||||
|
|
||||||
|
export = EvalError;
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** @type {import('./eval')} */
|
||||||
|
module.exports = EvalError;
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
declare const Error: ErrorConstructor;
|
||||||
|
|
||||||
|
export = Error;
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** @type {import('.')} */
|
||||||
|
module.exports = Error;
|
||||||
+80
@@ -0,0 +1,80 @@
|
|||||||
|
{
|
||||||
|
"name": "es-errors",
|
||||||
|
"version": "1.3.0",
|
||||||
|
"description": "A simple cache for a few of the JS Error constructors.",
|
||||||
|
"main": "index.js",
|
||||||
|
"exports": {
|
||||||
|
".": "./index.js",
|
||||||
|
"./eval": "./eval.js",
|
||||||
|
"./range": "./range.js",
|
||||||
|
"./ref": "./ref.js",
|
||||||
|
"./syntax": "./syntax.js",
|
||||||
|
"./type": "./type.js",
|
||||||
|
"./uri": "./uri.js",
|
||||||
|
"./package.json": "./package.json"
|
||||||
|
},
|
||||||
|
"sideEffects": false,
|
||||||
|
"scripts": {
|
||||||
|
"prepack": "npmignore --auto --commentLines=autogenerated",
|
||||||
|
"prepublishOnly": "safe-publish-latest",
|
||||||
|
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||||
|
"pretest": "npm run lint",
|
||||||
|
"test": "npm run tests-only",
|
||||||
|
"tests-only": "nyc tape 'test/**/*.js'",
|
||||||
|
"posttest": "aud --production",
|
||||||
|
"prelint": "evalmd README.md",
|
||||||
|
"lint": "eslint --ext=js,mjs .",
|
||||||
|
"postlint": "tsc -p . && eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git' | grep -v dist/)",
|
||||||
|
"version": "auto-changelog && git add CHANGELOG.md",
|
||||||
|
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/ljharb/es-errors.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"javascript",
|
||||||
|
"ecmascript",
|
||||||
|
"error",
|
||||||
|
"typeerror",
|
||||||
|
"syntaxerror",
|
||||||
|
"rangeerror"
|
||||||
|
],
|
||||||
|
"author": "Jordan Harband <ljharb@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/ljharb/es-errors/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/ljharb/es-errors#readme",
|
||||||
|
"devDependencies": {
|
||||||
|
"@ljharb/eslint-config": "^21.1.0",
|
||||||
|
"@types/tape": "^5.6.4",
|
||||||
|
"aud": "^2.0.4",
|
||||||
|
"auto-changelog": "^2.4.0",
|
||||||
|
"eclint": "^2.8.1",
|
||||||
|
"eslint": "^8.8.0",
|
||||||
|
"evalmd": "^0.0.19",
|
||||||
|
"in-publish": "^2.0.1",
|
||||||
|
"npmignore": "^0.3.1",
|
||||||
|
"nyc": "^10.3.2",
|
||||||
|
"safe-publish-latest": "^2.0.0",
|
||||||
|
"tape": "^5.7.4",
|
||||||
|
"typescript": "next"
|
||||||
|
},
|
||||||
|
"auto-changelog": {
|
||||||
|
"output": "CHANGELOG.md",
|
||||||
|
"template": "keepachangelog",
|
||||||
|
"unreleased": false,
|
||||||
|
"commitLimit": false,
|
||||||
|
"backfillLimit": false,
|
||||||
|
"hideCredit": true
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"ignore": [
|
||||||
|
".github/workflows"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
declare const RangeError: RangeErrorConstructor;
|
||||||
|
|
||||||
|
export = RangeError;
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** @type {import('./range')} */
|
||||||
|
module.exports = RangeError;
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
declare const ReferenceError: ReferenceErrorConstructor;
|
||||||
|
|
||||||
|
export = ReferenceError;
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** @type {import('./ref')} */
|
||||||
|
module.exports = ReferenceError;
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
declare const SyntaxError: SyntaxErrorConstructor;
|
||||||
|
|
||||||
|
export = SyntaxError;
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** @type {import('./syntax')} */
|
||||||
|
module.exports = SyntaxError;
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var test = require('tape');
|
||||||
|
|
||||||
|
var E = require('../');
|
||||||
|
var R = require('../range');
|
||||||
|
var Ref = require('../ref');
|
||||||
|
var S = require('../syntax');
|
||||||
|
var T = require('../type');
|
||||||
|
|
||||||
|
test('errors', function (t) {
|
||||||
|
t.equal(E, Error);
|
||||||
|
t.equal(R, RangeError);
|
||||||
|
t.equal(Ref, ReferenceError);
|
||||||
|
t.equal(S, SyntaxError);
|
||||||
|
t.equal(T, TypeError);
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||||
|
|
||||||
|
/* Projects */
|
||||||
|
|
||||||
|
/* Language and Environment */
|
||||||
|
"target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||||
|
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||||
|
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||||
|
"useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||||
|
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||||
|
|
||||||
|
/* Modules */
|
||||||
|
"module": "commonjs", /* Specify what module code is generated. */
|
||||||
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||||
|
// "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||||
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||||
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||||
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||||
|
// "typeRoots": ["types"], /* Specify multiple folders that act like `./node_modules/@types`. */
|
||||||
|
"resolveJsonModule": true, /* Enable importing .json files. */
|
||||||
|
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||||
|
|
||||||
|
/* JavaScript Support */
|
||||||
|
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
|
||||||
|
"checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||||
|
"maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
|
||||||
|
|
||||||
|
/* Emit */
|
||||||
|
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||||
|
"declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||||
|
"noEmit": true, /* Disable emitting files from a compilation. */
|
||||||
|
|
||||||
|
/* Interop Constraints */
|
||||||
|
"allowSyntheticDefaultImports": true, /* Allow `import x from y` when a module doesn't have a default export. */
|
||||||
|
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
|
||||||
|
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||||
|
|
||||||
|
/* Type Checking */
|
||||||
|
"strict": true, /* Enable all strict type-checking options. */
|
||||||
|
|
||||||
|
/* Completeness */
|
||||||
|
// "skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"coverage",
|
||||||
|
],
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
declare const TypeError: TypeErrorConstructor
|
||||||
|
|
||||||
|
export = TypeError;
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** @type {import('./type')} */
|
||||||
|
module.exports = TypeError;
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
declare const URIError: URIErrorConstructor;
|
||||||
|
|
||||||
|
export = URIError;
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** @type {import('./uri')} */
|
||||||
|
module.exports = URIError;
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
# esbuild
|
||||||
|
|
||||||
|
This is the Linux 64-bit binary for esbuild, a JavaScript bundler and minifier. See https://github.com/evanw/esbuild for details.
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "esbuild-linux-64",
|
||||||
|
"version": "0.15.18",
|
||||||
|
"description": "The Linux 64-bit binary for esbuild, a JavaScript bundler.",
|
||||||
|
"repository": "https://github.com/evanw/esbuild",
|
||||||
|
"license": "MIT",
|
||||||
|
"preferUnplugged": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
]
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
# esbuild
|
||||||
|
|
||||||
|
This is the Windows 64-bit binary for esbuild, a JavaScript bundler and minifier. See https://github.com/evanw/esbuild for details.
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "esbuild-windows-64",
|
||||||
|
"version": "0.15.18",
|
||||||
|
"description": "The Windows 64-bit binary for esbuild, a JavaScript bundler.",
|
||||||
|
"repository": "https://github.com/evanw/esbuild",
|
||||||
|
"license": "MIT",
|
||||||
|
"preferUnplugged": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"os": [
|
||||||
|
"win32"
|
||||||
|
],
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
]
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 Evan Wallace
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
# esbuild
|
||||||
|
|
||||||
|
This is a JavaScript bundler and minifier. See https://github.com/evanw/esbuild and the [JavaScript API documentation](https://esbuild.github.io/api/) for details.
|
||||||
+245
@@ -0,0 +1,245 @@
|
|||||||
|
"use strict";
|
||||||
|
var __create = Object.create;
|
||||||
|
var __defProp = Object.defineProperty;
|
||||||
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||||
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||||
|
var __getProtoOf = Object.getPrototypeOf;
|
||||||
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||||
|
var __copyProps = (to, from, except, desc) => {
|
||||||
|
if (from && typeof from === "object" || typeof from === "function") {
|
||||||
|
for (let key of __getOwnPropNames(from))
|
||||||
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||||
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||||
|
}
|
||||||
|
return to;
|
||||||
|
};
|
||||||
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
||||||
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
||||||
|
mod
|
||||||
|
));
|
||||||
|
|
||||||
|
// lib/npm/node-platform.ts
|
||||||
|
var fs = require("fs");
|
||||||
|
var os = require("os");
|
||||||
|
var path = require("path");
|
||||||
|
var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
||||||
|
var knownWindowsPackages = {
|
||||||
|
"win32 arm64 LE": "esbuild-windows-arm64",
|
||||||
|
"win32 ia32 LE": "esbuild-windows-32",
|
||||||
|
"win32 x64 LE": "esbuild-windows-64"
|
||||||
|
};
|
||||||
|
var knownUnixlikePackages = {
|
||||||
|
"android arm64 LE": "esbuild-android-arm64",
|
||||||
|
"darwin arm64 LE": "esbuild-darwin-arm64",
|
||||||
|
"darwin x64 LE": "esbuild-darwin-64",
|
||||||
|
"freebsd arm64 LE": "esbuild-freebsd-arm64",
|
||||||
|
"freebsd x64 LE": "esbuild-freebsd-64",
|
||||||
|
"linux arm LE": "esbuild-linux-arm",
|
||||||
|
"linux arm64 LE": "esbuild-linux-arm64",
|
||||||
|
"linux ia32 LE": "esbuild-linux-32",
|
||||||
|
"linux mips64el LE": "esbuild-linux-mips64le",
|
||||||
|
"linux ppc64 LE": "esbuild-linux-ppc64le",
|
||||||
|
"linux riscv64 LE": "esbuild-linux-riscv64",
|
||||||
|
"linux s390x BE": "esbuild-linux-s390x",
|
||||||
|
"linux x64 LE": "esbuild-linux-64",
|
||||||
|
"linux loong64 LE": "@esbuild/linux-loong64",
|
||||||
|
"netbsd x64 LE": "esbuild-netbsd-64",
|
||||||
|
"openbsd x64 LE": "esbuild-openbsd-64",
|
||||||
|
"sunos x64 LE": "esbuild-sunos-64"
|
||||||
|
};
|
||||||
|
var knownWebAssemblyFallbackPackages = {
|
||||||
|
"android arm LE": "@esbuild/android-arm",
|
||||||
|
"android x64 LE": "esbuild-android-64"
|
||||||
|
};
|
||||||
|
function pkgAndSubpathForCurrentPlatform() {
|
||||||
|
let pkg;
|
||||||
|
let subpath;
|
||||||
|
let isWASM = false;
|
||||||
|
let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
||||||
|
if (platformKey in knownWindowsPackages) {
|
||||||
|
pkg = knownWindowsPackages[platformKey];
|
||||||
|
subpath = "esbuild.exe";
|
||||||
|
} else if (platformKey in knownUnixlikePackages) {
|
||||||
|
pkg = knownUnixlikePackages[platformKey];
|
||||||
|
subpath = "bin/esbuild";
|
||||||
|
} else if (platformKey in knownWebAssemblyFallbackPackages) {
|
||||||
|
pkg = knownWebAssemblyFallbackPackages[platformKey];
|
||||||
|
subpath = "bin/esbuild";
|
||||||
|
isWASM = true;
|
||||||
|
} else {
|
||||||
|
throw new Error(`Unsupported platform: ${platformKey}`);
|
||||||
|
}
|
||||||
|
return { pkg, subpath, isWASM };
|
||||||
|
}
|
||||||
|
function downloadedBinPath(pkg, subpath) {
|
||||||
|
const esbuildLibDir = path.dirname(require.resolve("esbuild"));
|
||||||
|
return path.join(esbuildLibDir, `downloaded-${pkg}-${path.basename(subpath)}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// lib/npm/node-install.ts
|
||||||
|
var fs2 = require("fs");
|
||||||
|
var os2 = require("os");
|
||||||
|
var path2 = require("path");
|
||||||
|
var zlib = require("zlib");
|
||||||
|
var https = require("https");
|
||||||
|
var child_process = require("child_process");
|
||||||
|
var toPath = path2.join(__dirname, "bin", "esbuild");
|
||||||
|
var isToPathJS = true;
|
||||||
|
function validateBinaryVersion(...command) {
|
||||||
|
command.push("--version");
|
||||||
|
const stdout = child_process.execFileSync(command.shift(), command, {
|
||||||
|
stdio: "pipe"
|
||||||
|
}).toString().trim();
|
||||||
|
if (stdout !== "0.15.18") {
|
||||||
|
throw new Error(`Expected ${JSON.stringify("0.15.18")} but got ${JSON.stringify(stdout)}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function isYarn() {
|
||||||
|
const { npm_config_user_agent } = process.env;
|
||||||
|
if (npm_config_user_agent) {
|
||||||
|
return /\byarn\//.test(npm_config_user_agent);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
function fetch(url) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
https.get(url, (res) => {
|
||||||
|
if ((res.statusCode === 301 || res.statusCode === 302) && res.headers.location)
|
||||||
|
return fetch(res.headers.location).then(resolve, reject);
|
||||||
|
if (res.statusCode !== 200)
|
||||||
|
return reject(new Error(`Server responded with ${res.statusCode}`));
|
||||||
|
let chunks = [];
|
||||||
|
res.on("data", (chunk) => chunks.push(chunk));
|
||||||
|
res.on("end", () => resolve(Buffer.concat(chunks)));
|
||||||
|
}).on("error", reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function extractFileFromTarGzip(buffer, subpath) {
|
||||||
|
try {
|
||||||
|
buffer = zlib.unzipSync(buffer);
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(`Invalid gzip data in archive: ${err && err.message || err}`);
|
||||||
|
}
|
||||||
|
let str = (i, n) => String.fromCharCode(...buffer.subarray(i, i + n)).replace(/\0.*$/, "");
|
||||||
|
let offset = 0;
|
||||||
|
subpath = `package/${subpath}`;
|
||||||
|
while (offset < buffer.length) {
|
||||||
|
let name = str(offset, 100);
|
||||||
|
let size = parseInt(str(offset + 124, 12), 8);
|
||||||
|
offset += 512;
|
||||||
|
if (!isNaN(size)) {
|
||||||
|
if (name === subpath)
|
||||||
|
return buffer.subarray(offset, offset + size);
|
||||||
|
offset += size + 511 & ~511;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error(`Could not find ${JSON.stringify(subpath)} in archive`);
|
||||||
|
}
|
||||||
|
function installUsingNPM(pkg, subpath, binPath) {
|
||||||
|
const env = { ...process.env, npm_config_global: void 0 };
|
||||||
|
const esbuildLibDir = path2.dirname(require.resolve("esbuild"));
|
||||||
|
const installDir = path2.join(esbuildLibDir, "npm-install");
|
||||||
|
fs2.mkdirSync(installDir);
|
||||||
|
try {
|
||||||
|
fs2.writeFileSync(path2.join(installDir, "package.json"), "{}");
|
||||||
|
child_process.execSync(
|
||||||
|
`npm install --loglevel=error --prefer-offline --no-audit --progress=false ${pkg}@${"0.15.18"}`,
|
||||||
|
{ cwd: installDir, stdio: "pipe", env }
|
||||||
|
);
|
||||||
|
const installedBinPath = path2.join(installDir, "node_modules", pkg, subpath);
|
||||||
|
fs2.renameSync(installedBinPath, binPath);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
removeRecursive(installDir);
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function removeRecursive(dir) {
|
||||||
|
for (const entry of fs2.readdirSync(dir)) {
|
||||||
|
const entryPath = path2.join(dir, entry);
|
||||||
|
let stats;
|
||||||
|
try {
|
||||||
|
stats = fs2.lstatSync(entryPath);
|
||||||
|
} catch {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (stats.isDirectory())
|
||||||
|
removeRecursive(entryPath);
|
||||||
|
else
|
||||||
|
fs2.unlinkSync(entryPath);
|
||||||
|
}
|
||||||
|
fs2.rmdirSync(dir);
|
||||||
|
}
|
||||||
|
function applyManualBinaryPathOverride(overridePath) {
|
||||||
|
const pathString = JSON.stringify(overridePath);
|
||||||
|
fs2.writeFileSync(toPath, `#!/usr/bin/env node
|
||||||
|
require('child_process').execFileSync(${pathString}, process.argv.slice(2), { stdio: 'inherit' });
|
||||||
|
`);
|
||||||
|
const libMain = path2.join(__dirname, "lib", "main.js");
|
||||||
|
const code = fs2.readFileSync(libMain, "utf8");
|
||||||
|
fs2.writeFileSync(libMain, `var ESBUILD_BINARY_PATH = ${pathString};
|
||||||
|
${code}`);
|
||||||
|
}
|
||||||
|
function maybeOptimizePackage(binPath) {
|
||||||
|
if (os2.platform() !== "win32" && !isYarn()) {
|
||||||
|
const tempPath = path2.join(__dirname, "bin-esbuild");
|
||||||
|
try {
|
||||||
|
fs2.linkSync(binPath, tempPath);
|
||||||
|
fs2.renameSync(tempPath, toPath);
|
||||||
|
isToPathJS = false;
|
||||||
|
fs2.unlinkSync(tempPath);
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function downloadDirectlyFromNPM(pkg, subpath, binPath) {
|
||||||
|
const url = `https://registry.npmjs.org/${pkg}/-/${pkg}-${"0.15.18"}.tgz`;
|
||||||
|
console.error(`[esbuild] Trying to download ${JSON.stringify(url)}`);
|
||||||
|
try {
|
||||||
|
fs2.writeFileSync(binPath, extractFileFromTarGzip(await fetch(url), subpath));
|
||||||
|
fs2.chmodSync(binPath, 493);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`[esbuild] Failed to download ${JSON.stringify(url)}: ${e && e.message || e}`);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function checkAndPreparePackage() {
|
||||||
|
if (ESBUILD_BINARY_PATH) {
|
||||||
|
applyManualBinaryPathOverride(ESBUILD_BINARY_PATH);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { pkg, subpath } = pkgAndSubpathForCurrentPlatform();
|
||||||
|
let binPath;
|
||||||
|
try {
|
||||||
|
binPath = require.resolve(`${pkg}/${subpath}`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`[esbuild] Failed to find package "${pkg}" on the file system
|
||||||
|
|
||||||
|
This can happen if you use the "--no-optional" flag. The "optionalDependencies"
|
||||||
|
package.json feature is used by esbuild to install the correct binary executable
|
||||||
|
for your current platform. This install script will now attempt to work around
|
||||||
|
this. If that fails, you need to remove the "--no-optional" flag to use esbuild.
|
||||||
|
`);
|
||||||
|
binPath = downloadedBinPath(pkg, subpath);
|
||||||
|
try {
|
||||||
|
console.error(`[esbuild] Trying to install package "${pkg}" using npm`);
|
||||||
|
installUsingNPM(pkg, subpath, binPath);
|
||||||
|
} catch (e2) {
|
||||||
|
console.error(`[esbuild] Failed to install package "${pkg}" using npm: ${e2 && e2.message || e2}`);
|
||||||
|
try {
|
||||||
|
await downloadDirectlyFromNPM(pkg, subpath, binPath);
|
||||||
|
} catch (e3) {
|
||||||
|
throw new Error(`Failed to install package "${pkg}"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maybeOptimizePackage(binPath);
|
||||||
|
}
|
||||||
|
checkAndPreparePackage().then(() => {
|
||||||
|
if (isToPathJS) {
|
||||||
|
validateBinaryVersion(process.execPath, toPath);
|
||||||
|
} else {
|
||||||
|
validateBinaryVersion(toPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
+611
@@ -0,0 +1,611 @@
|
|||||||
|
export type Platform = 'browser' | 'node' | 'neutral';
|
||||||
|
export type Format = 'iife' | 'cjs' | 'esm';
|
||||||
|
export type Loader = 'js' | 'jsx' | 'ts' | 'tsx' | 'css' | 'json' | 'text' | 'base64' | 'file' | 'dataurl' | 'binary' | 'copy' | 'default';
|
||||||
|
export type LogLevel = 'verbose' | 'debug' | 'info' | 'warning' | 'error' | 'silent';
|
||||||
|
export type Charset = 'ascii' | 'utf8';
|
||||||
|
export type Drop = 'console' | 'debugger';
|
||||||
|
|
||||||
|
interface CommonOptions {
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#sourcemap */
|
||||||
|
sourcemap?: boolean | 'linked' | 'inline' | 'external' | 'both';
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#legal-comments */
|
||||||
|
legalComments?: 'none' | 'inline' | 'eof' | 'linked' | 'external';
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#source-root */
|
||||||
|
sourceRoot?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#sources-content */
|
||||||
|
sourcesContent?: boolean;
|
||||||
|
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#format */
|
||||||
|
format?: Format;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#global-name */
|
||||||
|
globalName?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#target */
|
||||||
|
target?: string | string[];
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#supported */
|
||||||
|
supported?: Record<string, boolean>;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#platform */
|
||||||
|
platform?: Platform;
|
||||||
|
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#mangle-props */
|
||||||
|
mangleProps?: RegExp;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#mangle-props */
|
||||||
|
reserveProps?: RegExp;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#mangle-props */
|
||||||
|
mangleQuoted?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#mangle-props */
|
||||||
|
mangleCache?: Record<string, string | false>;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#drop */
|
||||||
|
drop?: Drop[];
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#minify */
|
||||||
|
minify?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#minify */
|
||||||
|
minifyWhitespace?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#minify */
|
||||||
|
minifyIdentifiers?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#minify */
|
||||||
|
minifySyntax?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#charset */
|
||||||
|
charset?: Charset;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#tree-shaking */
|
||||||
|
treeShaking?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#ignore-annotations */
|
||||||
|
ignoreAnnotations?: boolean;
|
||||||
|
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#jsx */
|
||||||
|
jsx?: 'transform' | 'preserve' | 'automatic';
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#jsx-factory */
|
||||||
|
jsxFactory?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#jsx-fragment */
|
||||||
|
jsxFragment?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#jsx-import-source */
|
||||||
|
jsxImportSource?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#jsx-development */
|
||||||
|
jsxDev?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#jsx-side-effects */
|
||||||
|
jsxSideEffects?: boolean;
|
||||||
|
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#define */
|
||||||
|
define?: { [key: string]: string };
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#pure */
|
||||||
|
pure?: string[];
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#keep-names */
|
||||||
|
keepNames?: boolean;
|
||||||
|
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#color */
|
||||||
|
color?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#log-level */
|
||||||
|
logLevel?: LogLevel;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#log-limit */
|
||||||
|
logLimit?: number;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#log-override */
|
||||||
|
logOverride?: Record<string, LogLevel>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BuildOptions extends CommonOptions {
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#bundle */
|
||||||
|
bundle?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#splitting */
|
||||||
|
splitting?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#preserve-symlinks */
|
||||||
|
preserveSymlinks?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#outfile */
|
||||||
|
outfile?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#metafile */
|
||||||
|
metafile?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#outdir */
|
||||||
|
outdir?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#outbase */
|
||||||
|
outbase?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#external */
|
||||||
|
external?: string[];
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#alias */
|
||||||
|
alias?: Record<string, string>;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#loader */
|
||||||
|
loader?: { [ext: string]: Loader };
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#resolve-extensions */
|
||||||
|
resolveExtensions?: string[];
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#main-fields */
|
||||||
|
mainFields?: string[];
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#conditions */
|
||||||
|
conditions?: string[];
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#write */
|
||||||
|
write?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#allow-overwrite */
|
||||||
|
allowOverwrite?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#tsconfig */
|
||||||
|
tsconfig?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#out-extension */
|
||||||
|
outExtension?: { [ext: string]: string };
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#public-path */
|
||||||
|
publicPath?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#entry-names */
|
||||||
|
entryNames?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#chunk-names */
|
||||||
|
chunkNames?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#asset-names */
|
||||||
|
assetNames?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#inject */
|
||||||
|
inject?: string[];
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#banner */
|
||||||
|
banner?: { [type: string]: string };
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#footer */
|
||||||
|
footer?: { [type: string]: string };
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#incremental */
|
||||||
|
incremental?: boolean;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#entry-points */
|
||||||
|
entryPoints?: string[] | Record<string, string>;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#stdin */
|
||||||
|
stdin?: StdinOptions;
|
||||||
|
/** Documentation: https://esbuild.github.io/plugins/ */
|
||||||
|
plugins?: Plugin[];
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#working-directory */
|
||||||
|
absWorkingDir?: string;
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#node-paths */
|
||||||
|
nodePaths?: string[]; // The "NODE_PATH" variable from Node.js
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#watch */
|
||||||
|
watch?: boolean | WatchMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface WatchMode {
|
||||||
|
onRebuild?: (error: BuildFailure | null, result: BuildResult | null) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StdinOptions {
|
||||||
|
contents: string | Uint8Array;
|
||||||
|
resolveDir?: string;
|
||||||
|
sourcefile?: string;
|
||||||
|
loader?: Loader;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Message {
|
||||||
|
id: string;
|
||||||
|
pluginName: string;
|
||||||
|
text: string;
|
||||||
|
location: Location | null;
|
||||||
|
notes: Note[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optional user-specified data that is passed through unmodified. You can
|
||||||
|
* use this to stash the original error, for example.
|
||||||
|
*/
|
||||||
|
detail: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Note {
|
||||||
|
text: string;
|
||||||
|
location: Location | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Location {
|
||||||
|
file: string;
|
||||||
|
namespace: string;
|
||||||
|
/** 1-based */
|
||||||
|
line: number;
|
||||||
|
/** 0-based, in bytes */
|
||||||
|
column: number;
|
||||||
|
/** in bytes */
|
||||||
|
length: number;
|
||||||
|
lineText: string;
|
||||||
|
suggestion: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OutputFile {
|
||||||
|
path: string;
|
||||||
|
/** "text" as bytes */
|
||||||
|
contents: Uint8Array;
|
||||||
|
/** "contents" as text */
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BuildInvalidate {
|
||||||
|
(): Promise<BuildIncremental>;
|
||||||
|
dispose(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BuildIncremental extends BuildResult {
|
||||||
|
rebuild: BuildInvalidate;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BuildResult {
|
||||||
|
errors: Message[];
|
||||||
|
warnings: Message[];
|
||||||
|
/** Only when "write: false" */
|
||||||
|
outputFiles?: OutputFile[];
|
||||||
|
/** Only when "incremental: true" */
|
||||||
|
rebuild?: BuildInvalidate;
|
||||||
|
/** Only when "watch: true" */
|
||||||
|
stop?: () => void;
|
||||||
|
/** Only when "metafile: true" */
|
||||||
|
metafile?: Metafile;
|
||||||
|
/** Only when "mangleCache" is present */
|
||||||
|
mangleCache?: Record<string, string | false>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BuildFailure extends Error {
|
||||||
|
errors: Message[];
|
||||||
|
warnings: Message[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#serve-arguments */
|
||||||
|
export interface ServeOptions {
|
||||||
|
port?: number;
|
||||||
|
host?: string;
|
||||||
|
servedir?: string;
|
||||||
|
onRequest?: (args: ServeOnRequestArgs) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServeOnRequestArgs {
|
||||||
|
remoteAddress: string;
|
||||||
|
method: string;
|
||||||
|
path: string;
|
||||||
|
status: number;
|
||||||
|
/** The time to generate the response, not to send it */
|
||||||
|
timeInMS: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Documentation: https://esbuild.github.io/api/#serve-return-values */
|
||||||
|
export interface ServeResult {
|
||||||
|
port: number;
|
||||||
|
host: string;
|
||||||
|
wait: Promise<void>;
|
||||||
|
stop: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TransformOptions extends CommonOptions {
|
||||||
|
tsconfigRaw?: string | {
|
||||||
|
compilerOptions?: {
|
||||||
|
alwaysStrict?: boolean,
|
||||||
|
importsNotUsedAsValues?: 'remove' | 'preserve' | 'error',
|
||||||
|
jsx?: 'react' | 'react-jsx' | 'react-jsxdev' | 'preserve',
|
||||||
|
jsxFactory?: string,
|
||||||
|
jsxFragmentFactory?: string,
|
||||||
|
jsxImportSource?: string,
|
||||||
|
preserveValueImports?: boolean,
|
||||||
|
target?: string,
|
||||||
|
useDefineForClassFields?: boolean,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
sourcefile?: string;
|
||||||
|
loader?: Loader;
|
||||||
|
banner?: string;
|
||||||
|
footer?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TransformResult {
|
||||||
|
code: string;
|
||||||
|
map: string;
|
||||||
|
warnings: Message[];
|
||||||
|
/** Only when "mangleCache" is present */
|
||||||
|
mangleCache?: Record<string, string | false>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TransformFailure extends Error {
|
||||||
|
errors: Message[];
|
||||||
|
warnings: Message[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Plugin {
|
||||||
|
name: string;
|
||||||
|
setup: (build: PluginBuild) => (void | Promise<void>);
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PluginBuild {
|
||||||
|
initialOptions: BuildOptions;
|
||||||
|
resolve(path: string, options?: ResolveOptions): Promise<ResolveResult>;
|
||||||
|
|
||||||
|
onStart(callback: () =>
|
||||||
|
(OnStartResult | null | void | Promise<OnStartResult | null | void>)): void;
|
||||||
|
onEnd(callback: (result: BuildResult) =>
|
||||||
|
(void | Promise<void>)): void;
|
||||||
|
onResolve(options: OnResolveOptions, callback: (args: OnResolveArgs) =>
|
||||||
|
(OnResolveResult | null | undefined | Promise<OnResolveResult | null | undefined>)): void;
|
||||||
|
onLoad(options: OnLoadOptions, callback: (args: OnLoadArgs) =>
|
||||||
|
(OnLoadResult | null | undefined | Promise<OnLoadResult | null | undefined>)): void;
|
||||||
|
|
||||||
|
// This is a full copy of the esbuild library in case you need it
|
||||||
|
esbuild: {
|
||||||
|
serve: typeof serve,
|
||||||
|
build: typeof build,
|
||||||
|
buildSync: typeof buildSync,
|
||||||
|
transform: typeof transform,
|
||||||
|
transformSync: typeof transformSync,
|
||||||
|
formatMessages: typeof formatMessages,
|
||||||
|
formatMessagesSync: typeof formatMessagesSync,
|
||||||
|
analyzeMetafile: typeof analyzeMetafile,
|
||||||
|
analyzeMetafileSync: typeof analyzeMetafileSync,
|
||||||
|
initialize: typeof initialize,
|
||||||
|
version: typeof version,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResolveOptions {
|
||||||
|
pluginName?: string;
|
||||||
|
importer?: string;
|
||||||
|
namespace?: string;
|
||||||
|
resolveDir?: string;
|
||||||
|
kind?: ImportKind;
|
||||||
|
pluginData?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ResolveResult {
|
||||||
|
errors: Message[];
|
||||||
|
warnings: Message[];
|
||||||
|
|
||||||
|
path: string;
|
||||||
|
external: boolean;
|
||||||
|
sideEffects: boolean;
|
||||||
|
namespace: string;
|
||||||
|
suffix: string;
|
||||||
|
pluginData: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OnStartResult {
|
||||||
|
errors?: PartialMessage[];
|
||||||
|
warnings?: PartialMessage[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OnResolveOptions {
|
||||||
|
filter: RegExp;
|
||||||
|
namespace?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OnResolveArgs {
|
||||||
|
path: string;
|
||||||
|
importer: string;
|
||||||
|
namespace: string;
|
||||||
|
resolveDir: string;
|
||||||
|
kind: ImportKind;
|
||||||
|
pluginData: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ImportKind =
|
||||||
|
| 'entry-point'
|
||||||
|
|
||||||
|
// JS
|
||||||
|
| 'import-statement'
|
||||||
|
| 'require-call'
|
||||||
|
| 'dynamic-import'
|
||||||
|
| 'require-resolve'
|
||||||
|
|
||||||
|
// CSS
|
||||||
|
| 'import-rule'
|
||||||
|
| 'url-token'
|
||||||
|
|
||||||
|
export interface OnResolveResult {
|
||||||
|
pluginName?: string;
|
||||||
|
|
||||||
|
errors?: PartialMessage[];
|
||||||
|
warnings?: PartialMessage[];
|
||||||
|
|
||||||
|
path?: string;
|
||||||
|
external?: boolean;
|
||||||
|
sideEffects?: boolean;
|
||||||
|
namespace?: string;
|
||||||
|
suffix?: string;
|
||||||
|
pluginData?: any;
|
||||||
|
|
||||||
|
watchFiles?: string[];
|
||||||
|
watchDirs?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OnLoadOptions {
|
||||||
|
filter: RegExp;
|
||||||
|
namespace?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OnLoadArgs {
|
||||||
|
path: string;
|
||||||
|
namespace: string;
|
||||||
|
suffix: string;
|
||||||
|
pluginData: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OnLoadResult {
|
||||||
|
pluginName?: string;
|
||||||
|
|
||||||
|
errors?: PartialMessage[];
|
||||||
|
warnings?: PartialMessage[];
|
||||||
|
|
||||||
|
contents?: string | Uint8Array;
|
||||||
|
resolveDir?: string;
|
||||||
|
loader?: Loader;
|
||||||
|
pluginData?: any;
|
||||||
|
|
||||||
|
watchFiles?: string[];
|
||||||
|
watchDirs?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PartialMessage {
|
||||||
|
id?: string;
|
||||||
|
pluginName?: string;
|
||||||
|
text?: string;
|
||||||
|
location?: Partial<Location> | null;
|
||||||
|
notes?: PartialNote[];
|
||||||
|
detail?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PartialNote {
|
||||||
|
text?: string;
|
||||||
|
location?: Partial<Location> | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Metafile {
|
||||||
|
inputs: {
|
||||||
|
[path: string]: {
|
||||||
|
bytes: number
|
||||||
|
imports: {
|
||||||
|
path: string
|
||||||
|
kind: ImportKind
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
outputs: {
|
||||||
|
[path: string]: {
|
||||||
|
bytes: number
|
||||||
|
inputs: {
|
||||||
|
[path: string]: {
|
||||||
|
bytesInOutput: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
imports: {
|
||||||
|
path: string
|
||||||
|
kind: ImportKind
|
||||||
|
}[]
|
||||||
|
exports: string[]
|
||||||
|
entryPoint?: string
|
||||||
|
cssBundle?: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FormatMessagesOptions {
|
||||||
|
kind: 'error' | 'warning';
|
||||||
|
color?: boolean;
|
||||||
|
terminalWidth?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AnalyzeMetafileOptions {
|
||||||
|
color?: boolean;
|
||||||
|
verbose?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function invokes the "esbuild" command-line tool for you. It returns a
|
||||||
|
* promise that either resolves with a "BuildResult" object or rejects with a
|
||||||
|
* "BuildFailure" object.
|
||||||
|
*
|
||||||
|
* - Works in node: yes
|
||||||
|
* - Works in browser: yes
|
||||||
|
*
|
||||||
|
* Documentation: https://esbuild.github.io/api/#build-api
|
||||||
|
*/
|
||||||
|
export declare function build(options: BuildOptions & { write: false }): Promise<BuildResult & { outputFiles: OutputFile[] }>;
|
||||||
|
export declare function build(options: BuildOptions & { incremental: true, metafile: true }): Promise<BuildIncremental & { metafile: Metafile }>;
|
||||||
|
export declare function build(options: BuildOptions & { incremental: true }): Promise<BuildIncremental>;
|
||||||
|
export declare function build(options: BuildOptions & { metafile: true }): Promise<BuildResult & { metafile: Metafile }>;
|
||||||
|
export declare function build(options: BuildOptions): Promise<BuildResult>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function is similar to "build" but it serves the resulting files over
|
||||||
|
* HTTP on a localhost address with the specified port.
|
||||||
|
*
|
||||||
|
* - Works in node: yes
|
||||||
|
* - Works in browser: no
|
||||||
|
*
|
||||||
|
* Documentation: https://esbuild.github.io/api/#serve
|
||||||
|
*/
|
||||||
|
export declare function serve(serveOptions: ServeOptions, buildOptions: BuildOptions): Promise<ServeResult>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function transforms a single JavaScript file. It can be used to minify
|
||||||
|
* JavaScript, convert TypeScript/JSX to JavaScript, or convert newer JavaScript
|
||||||
|
* to older JavaScript. It returns a promise that is either resolved with a
|
||||||
|
* "TransformResult" object or rejected with a "TransformFailure" object.
|
||||||
|
*
|
||||||
|
* - Works in node: yes
|
||||||
|
* - Works in browser: yes
|
||||||
|
*
|
||||||
|
* Documentation: https://esbuild.github.io/api/#transform-api
|
||||||
|
*/
|
||||||
|
export declare function transform(input: string | Uint8Array, options?: TransformOptions): Promise<TransformResult>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts log messages to formatted message strings suitable for printing in
|
||||||
|
* the terminal. This allows you to reuse the built-in behavior of esbuild's
|
||||||
|
* log message formatter. This is a batch-oriented API for efficiency.
|
||||||
|
*
|
||||||
|
* - Works in node: yes
|
||||||
|
* - Works in browser: yes
|
||||||
|
*/
|
||||||
|
export declare function formatMessages(messages: PartialMessage[], options: FormatMessagesOptions): Promise<string[]>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pretty-prints an analysis of the metafile JSON to a string. This is just for
|
||||||
|
* convenience to be able to match esbuild's pretty-printing exactly. If you want
|
||||||
|
* to customize it, you can just inspect the data in the metafile yourself.
|
||||||
|
*
|
||||||
|
* - Works in node: yes
|
||||||
|
* - Works in browser: yes
|
||||||
|
*
|
||||||
|
* Documentation: https://esbuild.github.io/api/#analyze
|
||||||
|
*/
|
||||||
|
export declare function analyzeMetafile(metafile: Metafile | string, options?: AnalyzeMetafileOptions): Promise<string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A synchronous version of "build".
|
||||||
|
*
|
||||||
|
* - Works in node: yes
|
||||||
|
* - Works in browser: no
|
||||||
|
*
|
||||||
|
* Documentation: https://esbuild.github.io/api/#build-api
|
||||||
|
*/
|
||||||
|
export declare function buildSync(options: BuildOptions & { write: false }): BuildResult & { outputFiles: OutputFile[] };
|
||||||
|
export declare function buildSync(options: BuildOptions): BuildResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A synchronous version of "transform".
|
||||||
|
*
|
||||||
|
* - Works in node: yes
|
||||||
|
* - Works in browser: no
|
||||||
|
*
|
||||||
|
* Documentation: https://esbuild.github.io/api/#transform-api
|
||||||
|
*/
|
||||||
|
export declare function transformSync(input: string, options?: TransformOptions): TransformResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A synchronous version of "formatMessages".
|
||||||
|
*
|
||||||
|
* - Works in node: yes
|
||||||
|
* - Works in browser: no
|
||||||
|
*/
|
||||||
|
export declare function formatMessagesSync(messages: PartialMessage[], options: FormatMessagesOptions): string[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A synchronous version of "analyzeMetafile".
|
||||||
|
*
|
||||||
|
* - Works in node: yes
|
||||||
|
* - Works in browser: no
|
||||||
|
*
|
||||||
|
* Documentation: https://esbuild.github.io/api/#analyze
|
||||||
|
*/
|
||||||
|
export declare function analyzeMetafileSync(metafile: Metafile | string, options?: AnalyzeMetafileOptions): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This configures the browser-based version of esbuild. It is necessary to
|
||||||
|
* call this first and wait for the returned promise to be resolved before
|
||||||
|
* making other API calls when using esbuild in the browser.
|
||||||
|
*
|
||||||
|
* - Works in node: yes
|
||||||
|
* - Works in browser: yes ("options" is required)
|
||||||
|
*
|
||||||
|
* Documentation: https://esbuild.github.io/api/#running-in-the-browser
|
||||||
|
*/
|
||||||
|
export declare function initialize(options: InitializeOptions): Promise<void>;
|
||||||
|
|
||||||
|
export interface InitializeOptions {
|
||||||
|
/**
|
||||||
|
* The URL of the "esbuild.wasm" file. This must be provided when running
|
||||||
|
* esbuild in the browser.
|
||||||
|
*/
|
||||||
|
wasmURL?: string | URL
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The result of calling "new WebAssembly.Module(buffer)" where "buffer"
|
||||||
|
* is a typed array or ArrayBuffer containing the binary code of the
|
||||||
|
* "esbuild.wasm" file.
|
||||||
|
*
|
||||||
|
* You can use this as an alternative to "wasmURL" for environments where it's
|
||||||
|
* not possible to download the WebAssembly module.
|
||||||
|
*/
|
||||||
|
wasmModule?: WebAssembly.Module
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default esbuild runs the WebAssembly-based browser API in a web worker
|
||||||
|
* to avoid blocking the UI thread. This can be disabled by setting "worker"
|
||||||
|
* to false.
|
||||||
|
*/
|
||||||
|
worker?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export let version: string;
|
||||||
+2318
File diff suppressed because it is too large
Load Diff
+42
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"name": "esbuild",
|
||||||
|
"version": "0.15.18",
|
||||||
|
"description": "An extremely fast JavaScript and CSS bundler and minifier.",
|
||||||
|
"repository": "https://github.com/evanw/esbuild",
|
||||||
|
"scripts": {
|
||||||
|
"postinstall": "node install.js"
|
||||||
|
},
|
||||||
|
"main": "lib/main.js",
|
||||||
|
"types": "lib/main.d.ts",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"esbuild": "bin/esbuild"
|
||||||
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@esbuild/android-arm": "0.15.18",
|
||||||
|
"@esbuild/linux-loong64": "0.15.18",
|
||||||
|
"esbuild-android-64": "0.15.18",
|
||||||
|
"esbuild-android-arm64": "0.15.18",
|
||||||
|
"esbuild-darwin-64": "0.15.18",
|
||||||
|
"esbuild-darwin-arm64": "0.15.18",
|
||||||
|
"esbuild-freebsd-64": "0.15.18",
|
||||||
|
"esbuild-freebsd-arm64": "0.15.18",
|
||||||
|
"esbuild-linux-32": "0.15.18",
|
||||||
|
"esbuild-linux-64": "0.15.18",
|
||||||
|
"esbuild-linux-arm": "0.15.18",
|
||||||
|
"esbuild-linux-arm64": "0.15.18",
|
||||||
|
"esbuild-linux-mips64le": "0.15.18",
|
||||||
|
"esbuild-linux-ppc64le": "0.15.18",
|
||||||
|
"esbuild-linux-riscv64": "0.15.18",
|
||||||
|
"esbuild-linux-s390x": "0.15.18",
|
||||||
|
"esbuild-netbsd-64": "0.15.18",
|
||||||
|
"esbuild-openbsd-64": "0.15.18",
|
||||||
|
"esbuild-sunos-64": "0.15.18",
|
||||||
|
"esbuild-windows-32": "0.15.18",
|
||||||
|
"esbuild-windows-64": "0.15.18",
|
||||||
|
"esbuild-windows-arm64": "0.15.18"
|
||||||
|
},
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"root": true,
|
||||||
|
|
||||||
|
"extends": "@ljharb",
|
||||||
|
|
||||||
|
"rules": {
|
||||||
|
"func-name-matching": 0,
|
||||||
|
"indent": [2, 4],
|
||||||
|
"no-new-func": [1],
|
||||||
|
},
|
||||||
|
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": "test/**",
|
||||||
|
"rules": {
|
||||||
|
"max-lines-per-function": 0,
|
||||||
|
"strict": [0]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: [ljharb]
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: npm/function-bind
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
# Security
|
||||||
|
|
||||||
|
Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"all": true,
|
||||||
|
"check-coverage": false,
|
||||||
|
"reporter": ["text-summary", "text", "html", "json"],
|
||||||
|
"lines": 86,
|
||||||
|
"statements": 85.93,
|
||||||
|
"functions": 82.43,
|
||||||
|
"branches": 76.06,
|
||||||
|
"exclude": [
|
||||||
|
"coverage",
|
||||||
|
"test"
|
||||||
|
]
|
||||||
|
}
|
||||||
+136
@@ -0,0 +1,136 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [v1.1.2](https://github.com/ljharb/function-bind/compare/v1.1.1...v1.1.2) - 2023-10-12
|
||||||
|
|
||||||
|
### Merged
|
||||||
|
|
||||||
|
- Point to the correct file [`#16`](https://github.com/ljharb/function-bind/pull/16)
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Tests] migrate tests to Github Actions [`4f8b57c`](https://github.com/ljharb/function-bind/commit/4f8b57c02f2011fe9ae353d5e74e8745f0988af8)
|
||||||
|
- [Tests] remove `jscs` [`90eb2ed`](https://github.com/ljharb/function-bind/commit/90eb2edbeefd5b76cd6c3a482ea3454db169b31f)
|
||||||
|
- [meta] update `.gitignore` [`53fcdc3`](https://github.com/ljharb/function-bind/commit/53fcdc371cd66634d6e9b71c836a50f437e89fed)
|
||||||
|
- [Tests] up to `node` `v11.10`, `v10.15`, `v9.11`, `v8.15`, `v6.16`, `v4.9`; use `nvm install-latest-npm`; run audit script in tests [`1fe8f6e`](https://github.com/ljharb/function-bind/commit/1fe8f6e9aed0dfa8d8b3cdbd00c7f5ea0cd2b36e)
|
||||||
|
- [meta] add `auto-changelog` [`1921fcb`](https://github.com/ljharb/function-bind/commit/1921fcb5b416b63ffc4acad051b6aad5722f777d)
|
||||||
|
- [Robustness] remove runtime dependency on all builtins except `.apply` [`f743e61`](https://github.com/ljharb/function-bind/commit/f743e61aa6bb2360358c04d4884c9db853d118b7)
|
||||||
|
- Docs: enable badges; update wording [`503cb12`](https://github.com/ljharb/function-bind/commit/503cb12d998b5f91822776c73332c7adcd6355dd)
|
||||||
|
- [readme] update badges [`290c5db`](https://github.com/ljharb/function-bind/commit/290c5dbbbda7264efaeb886552a374b869a4bb48)
|
||||||
|
- [Tests] switch to nyc for coverage [`ea360ba`](https://github.com/ljharb/function-bind/commit/ea360ba907fc2601ed18d01a3827fa2d3533cdf8)
|
||||||
|
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape` [`cae5e9e`](https://github.com/ljharb/function-bind/commit/cae5e9e07a5578dc6df26c03ee22851ce05b943c)
|
||||||
|
- [meta] add `funding` field; create FUNDING.yml [`c9f4274`](https://github.com/ljharb/function-bind/commit/c9f4274aa80ea3aae9657a3938fdba41a3b04ca6)
|
||||||
|
- [Tests] fix eslint errors from #15 [`f69aaa2`](https://github.com/ljharb/function-bind/commit/f69aaa2beb2fdab4415bfb885760a699d0b9c964)
|
||||||
|
- [actions] fix permissions [`99a0cd9`](https://github.com/ljharb/function-bind/commit/99a0cd9f3b5bac223a0d572f081834cd73314be7)
|
||||||
|
- [meta] use `npmignore` to autogenerate an npmignore file [`f03b524`](https://github.com/ljharb/function-bind/commit/f03b524ca91f75a109a5d062f029122c86ecd1ae)
|
||||||
|
- [Dev Deps] update `@ljharb/eslint‑config`, `eslint`, `tape` [`7af9300`](https://github.com/ljharb/function-bind/commit/7af930023ae2ce7645489532821e4fbbcd7a2280)
|
||||||
|
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `covert`, `tape` [`64a9127`](https://github.com/ljharb/function-bind/commit/64a9127ab0bd331b93d6572eaf6e9971967fc08c)
|
||||||
|
- [Tests] use `aud` instead of `npm audit` [`e75069c`](https://github.com/ljharb/function-bind/commit/e75069c50010a8fcce2a9ce2324934c35fdb4386)
|
||||||
|
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape` [`d03555c`](https://github.com/ljharb/function-bind/commit/d03555ca59dea3b71ce710045e4303b9e2619e28)
|
||||||
|
- [meta] add `safe-publish-latest` [`9c8f809`](https://github.com/ljharb/function-bind/commit/9c8f8092aed027d7e80c94f517aa892385b64f09)
|
||||||
|
- [Dev Deps] update `@ljharb/eslint-config`, `tape` [`baf6893`](https://github.com/ljharb/function-bind/commit/baf6893e27f5b59abe88bc1995e6f6ed1e527397)
|
||||||
|
- [meta] create SECURITY.md [`4db1779`](https://github.com/ljharb/function-bind/commit/4db17799f1f28ae294cb95e0081ca2b591c3911b)
|
||||||
|
- [Tests] add `npm run audit` [`c8b38ec`](https://github.com/ljharb/function-bind/commit/c8b38ec40ed3f85dabdee40ed4148f1748375bc2)
|
||||||
|
- Revert "Point to the correct file" [`05cdf0f`](https://github.com/ljharb/function-bind/commit/05cdf0fa205c6a3c5ba40bbedd1dfa9874f915c9)
|
||||||
|
|
||||||
|
## [v1.1.1](https://github.com/ljharb/function-bind/compare/v1.1.0...v1.1.1) - 2017-08-28
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Tests] up to `node` `v8`; newer npm breaks on older node; fix scripts [`817f7d2`](https://github.com/ljharb/function-bind/commit/817f7d28470fdbff8ef608d4d565dd4d1430bc5e)
|
||||||
|
- [Dev Deps] update `eslint`, `jscs`, `tape`, `@ljharb/eslint-config` [`854288b`](https://github.com/ljharb/function-bind/commit/854288b1b6f5c555f89aceb9eff1152510262084)
|
||||||
|
- [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config` [`83e639f`](https://github.com/ljharb/function-bind/commit/83e639ff74e6cd6921285bccec22c1bcf72311bd)
|
||||||
|
- Only apps should have lockfiles [`5ed97f5`](https://github.com/ljharb/function-bind/commit/5ed97f51235c17774e0832e122abda0f3229c908)
|
||||||
|
- Use a SPDX-compliant “license” field. [`5feefea`](https://github.com/ljharb/function-bind/commit/5feefea0dc0193993e83e5df01ded424403a5381)
|
||||||
|
|
||||||
|
## [v1.1.0](https://github.com/ljharb/function-bind/compare/v1.0.2...v1.1.0) - 2016-02-14
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- Update `eslint`, `tape`; use my personal shared `eslint` config [`9c9062a`](https://github.com/ljharb/function-bind/commit/9c9062abbe9dd70b59ea2c3a3c3a81f29b457097)
|
||||||
|
- Add `npm run eslint` [`dd96c56`](https://github.com/ljharb/function-bind/commit/dd96c56720034a3c1ffee10b8a59a6f7c53e24ad)
|
||||||
|
- [New] return the native `bind` when available. [`82186e0`](https://github.com/ljharb/function-bind/commit/82186e03d73e580f95ff167e03f3582bed90ed72)
|
||||||
|
- [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config` [`a3dd767`](https://github.com/ljharb/function-bind/commit/a3dd76720c795cb7f4586b0544efabf8aa107b8b)
|
||||||
|
- Update `eslint` [`3dae2f7`](https://github.com/ljharb/function-bind/commit/3dae2f7423de30a2d20313ddb1edc19660142fe9)
|
||||||
|
- Update `tape`, `covert`, `jscs` [`a181eee`](https://github.com/ljharb/function-bind/commit/a181eee0cfa24eb229c6e843a971f36e060a2f6a)
|
||||||
|
- [Tests] up to `node` `v5.6`, `v4.3` [`964929a`](https://github.com/ljharb/function-bind/commit/964929a6a4ddb36fb128de2bcc20af5e4f22e1ed)
|
||||||
|
- Test up to `io.js` `v2.1` [`2be7310`](https://github.com/ljharb/function-bind/commit/2be7310f2f74886a7124ca925be411117d41d5ea)
|
||||||
|
- Update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config` [`45f3d68`](https://github.com/ljharb/function-bind/commit/45f3d6865c6ca93726abcef54febe009087af101)
|
||||||
|
- [Dev Deps] update `tape`, `jscs` [`6e1340d`](https://github.com/ljharb/function-bind/commit/6e1340d94642deaecad3e717825db641af4f8b1f)
|
||||||
|
- [Tests] up to `io.js` `v3.3`, `node` `v4.1` [`d9bad2b`](https://github.com/ljharb/function-bind/commit/d9bad2b778b1b3a6dd2876087b88b3acf319f8cc)
|
||||||
|
- Update `eslint` [`935590c`](https://github.com/ljharb/function-bind/commit/935590caa024ab356102e4858e8fc315b2ccc446)
|
||||||
|
- [Dev Deps] update `jscs`, `eslint`, `@ljharb/eslint-config` [`8c9a1ef`](https://github.com/ljharb/function-bind/commit/8c9a1efd848e5167887aa8501857a0940a480c57)
|
||||||
|
- Test on `io.js` `v2.2` [`9a3a38c`](https://github.com/ljharb/function-bind/commit/9a3a38c92013aed6e108666e7bd40969b84ac86e)
|
||||||
|
- Run `travis-ci` tests on `iojs` and `node` v0.12; speed up builds; allow 0.8 failures. [`69afc26`](https://github.com/ljharb/function-bind/commit/69afc2617405b147dd2a8d8ae73ca9e9283f18b4)
|
||||||
|
- [Dev Deps] Update `tape`, `eslint` [`36c1be0`](https://github.com/ljharb/function-bind/commit/36c1be0ab12b45fe5df6b0fdb01a5d5137fd0115)
|
||||||
|
- Update `tape`, `jscs` [`98d8303`](https://github.com/ljharb/function-bind/commit/98d8303cd5ca1c6b8f985469f86b0d44d7d45f6e)
|
||||||
|
- Update `jscs` [`9633a4e`](https://github.com/ljharb/function-bind/commit/9633a4e9fbf82051c240855166e468ba8ba0846f)
|
||||||
|
- Update `tape`, `jscs` [`c80ef0f`](https://github.com/ljharb/function-bind/commit/c80ef0f46efc9791e76fa50de4414092ac147831)
|
||||||
|
- Test up to `io.js` `v3.0` [`7e2c853`](https://github.com/ljharb/function-bind/commit/7e2c8537d52ab9cf5a655755561d8917684c0df4)
|
||||||
|
- Test on `io.js` `v2.4` [`5a199a2`](https://github.com/ljharb/function-bind/commit/5a199a27ba46795ba5eaf0845d07d4b8232895c9)
|
||||||
|
- Test on `io.js` `v2.3` [`a511b88`](https://github.com/ljharb/function-bind/commit/a511b8896de0bddf3b56862daa416c701f4d0453)
|
||||||
|
- Fixing a typo from 822b4e1938db02dc9584aa434fd3a45cb20caf43 [`732d6b6`](https://github.com/ljharb/function-bind/commit/732d6b63a9b33b45230e630dbcac7a10855d3266)
|
||||||
|
- Update `jscs` [`da52a48`](https://github.com/ljharb/function-bind/commit/da52a4886c06d6490f46ae30b15e4163ba08905d)
|
||||||
|
- Lock covert to v1.0.0. [`d6150fd`](https://github.com/ljharb/function-bind/commit/d6150fda1e6f486718ebdeff823333d9e48e7430)
|
||||||
|
|
||||||
|
## [v1.0.2](https://github.com/ljharb/function-bind/compare/v1.0.1...v1.0.2) - 2014-10-04
|
||||||
|
|
||||||
|
## [v1.0.1](https://github.com/ljharb/function-bind/compare/v1.0.0...v1.0.1) - 2014-10-03
|
||||||
|
|
||||||
|
### Merged
|
||||||
|
|
||||||
|
- make CI build faster [`#3`](https://github.com/ljharb/function-bind/pull/3)
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- Using my standard jscs.json [`d8ee94c`](https://github.com/ljharb/function-bind/commit/d8ee94c993eff0a84cf5744fe6a29627f5cffa1a)
|
||||||
|
- Adding `npm run lint` [`7571ab7`](https://github.com/ljharb/function-bind/commit/7571ab7dfdbd99b25a1dbb2d232622bd6f4f9c10)
|
||||||
|
- Using consistent indentation [`e91a1b1`](https://github.com/ljharb/function-bind/commit/e91a1b13a61e99ec1e530e299b55508f74218a95)
|
||||||
|
- Updating jscs [`7e17892`](https://github.com/ljharb/function-bind/commit/7e1789284bc629bc9c1547a61c9b227bbd8c7a65)
|
||||||
|
- Using consistent quotes [`c50b57f`](https://github.com/ljharb/function-bind/commit/c50b57fcd1c5ec38320979c837006069ebe02b77)
|
||||||
|
- Adding keywords [`cb94631`](https://github.com/ljharb/function-bind/commit/cb946314eed35f21186a25fb42fc118772f9ee00)
|
||||||
|
- Directly export a function expression instead of using a declaration, and relying on hoisting. [`5a33c5f`](https://github.com/ljharb/function-bind/commit/5a33c5f45642de180e0d207110bf7d1843ceb87c)
|
||||||
|
- Naming npm URL and badge in README; use SVG [`2aef8fc`](https://github.com/ljharb/function-bind/commit/2aef8fcb79d54e63a58ae557c4e60949e05d5e16)
|
||||||
|
- Naming deps URLs in README [`04228d7`](https://github.com/ljharb/function-bind/commit/04228d766670ee45ca24e98345c1f6a7621065b5)
|
||||||
|
- Naming travis-ci URLs in README; using SVG [`62c810c`](https://github.com/ljharb/function-bind/commit/62c810c2f54ced956cd4d4ab7b793055addfe36e)
|
||||||
|
- Make sure functions are invoked correctly (also passing coverage tests) [`2b289b4`](https://github.com/ljharb/function-bind/commit/2b289b4dfbf037ffcfa4dc95eb540f6165e9e43a)
|
||||||
|
- Removing the strict mode pragmas; they make tests fail. [`1aa701d`](https://github.com/ljharb/function-bind/commit/1aa701d199ddc3782476e8f7eef82679be97b845)
|
||||||
|
- Adding myself as a contributor [`85fd57b`](https://github.com/ljharb/function-bind/commit/85fd57b0860e5a7af42de9a287f3f265fc6d72fc)
|
||||||
|
- Adding strict mode pragmas [`915b08e`](https://github.com/ljharb/function-bind/commit/915b08e084c86a722eafe7245e21db74aa21ca4c)
|
||||||
|
- Adding devDeps URLs to README [`4ccc731`](https://github.com/ljharb/function-bind/commit/4ccc73112c1769859e4ca3076caf4086b3cba2cd)
|
||||||
|
- Fixing the description. [`a7a472c`](https://github.com/ljharb/function-bind/commit/a7a472cf649af515c635cf560fc478fbe48999c8)
|
||||||
|
- Using a function expression instead of a function declaration. [`b5d3e4e`](https://github.com/ljharb/function-bind/commit/b5d3e4ea6aaffc63888953eeb1fbc7ff45f1fa14)
|
||||||
|
- Updating tape [`f086be6`](https://github.com/ljharb/function-bind/commit/f086be6029fb56dde61a258c1340600fa174d1e0)
|
||||||
|
- Updating jscs [`5f9bdb3`](https://github.com/ljharb/function-bind/commit/5f9bdb375ab13ba48f30852aab94029520c54d71)
|
||||||
|
- Updating jscs [`9b409ba`](https://github.com/ljharb/function-bind/commit/9b409ba6118e23395a4e5d83ef39152aab9d3bfc)
|
||||||
|
- Run coverage as part of tests. [`8e1b6d4`](https://github.com/ljharb/function-bind/commit/8e1b6d459f047d1bd4fee814e01247c984c80bd0)
|
||||||
|
- Run linter as part of tests [`c1ca83f`](https://github.com/ljharb/function-bind/commit/c1ca83f832df94587d09e621beba682fabfaa987)
|
||||||
|
- Updating covert [`701e837`](https://github.com/ljharb/function-bind/commit/701e83774b57b4d3ef631e1948143f43a72f4bb9)
|
||||||
|
|
||||||
|
## [v1.0.0](https://github.com/ljharb/function-bind/compare/v0.2.0...v1.0.0) - 2014-08-09
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- Make sure old and unstable nodes don't fail Travis [`27adca3`](https://github.com/ljharb/function-bind/commit/27adca34a4ab6ad67b6dfde43942a1b103ce4d75)
|
||||||
|
- Fixing an issue when the bound function is called as a constructor in ES3. [`e20122d`](https://github.com/ljharb/function-bind/commit/e20122d267d92ce553859b280cbbea5d27c07731)
|
||||||
|
- Adding `npm run coverage` [`a2e29c4`](https://github.com/ljharb/function-bind/commit/a2e29c4ecaef9e2f6cd1603e868c139073375502)
|
||||||
|
- Updating tape [`b741168`](https://github.com/ljharb/function-bind/commit/b741168b12b235b1717ff696087645526b69213c)
|
||||||
|
- Upgrading tape [`63631a0`](https://github.com/ljharb/function-bind/commit/63631a04c7fbe97cc2fa61829cc27246d6986f74)
|
||||||
|
- Updating tape [`363cb46`](https://github.com/ljharb/function-bind/commit/363cb46dafb23cb3e347729a22f9448051d78464)
|
||||||
|
|
||||||
|
## v0.2.0 - 2014-03-23
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- Updating test coverage to match es5-shim. [`aa94d44`](https://github.com/ljharb/function-bind/commit/aa94d44b8f9d7f69f10e060db7709aa7a694e5d4)
|
||||||
|
- initial [`942ee07`](https://github.com/ljharb/function-bind/commit/942ee07e94e542d91798137bc4b80b926137e066)
|
||||||
|
- Setting the bound function's length properly. [`079f46a`](https://github.com/ljharb/function-bind/commit/079f46a2d3515b7c0b308c2c13fceb641f97ca25)
|
||||||
|
- Ensuring that some older browsers will throw when given a regex. [`36ac55b`](https://github.com/ljharb/function-bind/commit/36ac55b87f460d4330253c92870aa26fbfe8227f)
|
||||||
|
- Removing npm scripts that don't have dependencies [`9d2be60`](https://github.com/ljharb/function-bind/commit/9d2be600002cb8bc8606f8f3585ad3e05868c750)
|
||||||
|
- Updating tape [`297a4ac`](https://github.com/ljharb/function-bind/commit/297a4acc5464db381940aafb194d1c88f4e678f3)
|
||||||
|
- Skipping length tests for now. [`d9891ea`](https://github.com/ljharb/function-bind/commit/d9891ea4d2aaffa69f408339cdd61ff740f70565)
|
||||||
|
- don't take my tea [`dccd930`](https://github.com/ljharb/function-bind/commit/dccd930bfd60ea10cb178d28c97550c3bc8c1e07)
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
Copyright (c) 2013 Raynos.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
# function-bind <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
||||||
|
|
||||||
|
[![github actions][actions-image]][actions-url]
|
||||||
|
<!--[![coverage][codecov-image]][codecov-url]-->
|
||||||
|
[![dependency status][deps-svg]][deps-url]
|
||||||
|
[![dev dependency status][dev-deps-svg]][dev-deps-url]
|
||||||
|
[![License][license-image]][license-url]
|
||||||
|
[![Downloads][downloads-image]][downloads-url]
|
||||||
|
|
||||||
|
[![npm badge][npm-badge-png]][package-url]
|
||||||
|
|
||||||
|
Implementation of function.prototype.bind
|
||||||
|
|
||||||
|
Old versions of phantomjs, Internet Explorer < 9, and node < 0.6 don't support `Function.prototype.bind`.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```js
|
||||||
|
Function.prototype.bind = require("function-bind")
|
||||||
|
```
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
`npm install function-bind`
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
- Raynos
|
||||||
|
|
||||||
|
## MIT Licenced
|
||||||
|
|
||||||
|
[package-url]: https://npmjs.org/package/function-bind
|
||||||
|
[npm-version-svg]: https://versionbadg.es/Raynos/function-bind.svg
|
||||||
|
[deps-svg]: https://david-dm.org/Raynos/function-bind.svg
|
||||||
|
[deps-url]: https://david-dm.org/Raynos/function-bind
|
||||||
|
[dev-deps-svg]: https://david-dm.org/Raynos/function-bind/dev-status.svg
|
||||||
|
[dev-deps-url]: https://david-dm.org/Raynos/function-bind#info=devDependencies
|
||||||
|
[npm-badge-png]: https://nodei.co/npm/function-bind.png?downloads=true&stars=true
|
||||||
|
[license-image]: https://img.shields.io/npm/l/function-bind.svg
|
||||||
|
[license-url]: LICENSE
|
||||||
|
[downloads-image]: https://img.shields.io/npm/dm/function-bind.svg
|
||||||
|
[downloads-url]: https://npm-stat.com/charts.html?package=function-bind
|
||||||
|
[codecov-image]: https://codecov.io/gh/Raynos/function-bind/branch/main/graphs/badge.svg
|
||||||
|
[codecov-url]: https://app.codecov.io/gh/Raynos/function-bind/
|
||||||
|
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/Raynos/function-bind
|
||||||
|
[actions-url]: https://github.com/Raynos/function-bind/actions
|
||||||
+84
@@ -0,0 +1,84 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/* eslint no-invalid-this: 1 */
|
||||||
|
|
||||||
|
var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
|
||||||
|
var toStr = Object.prototype.toString;
|
||||||
|
var max = Math.max;
|
||||||
|
var funcType = '[object Function]';
|
||||||
|
|
||||||
|
var concatty = function concatty(a, b) {
|
||||||
|
var arr = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < a.length; i += 1) {
|
||||||
|
arr[i] = a[i];
|
||||||
|
}
|
||||||
|
for (var j = 0; j < b.length; j += 1) {
|
||||||
|
arr[j + a.length] = b[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
};
|
||||||
|
|
||||||
|
var slicy = function slicy(arrLike, offset) {
|
||||||
|
var arr = [];
|
||||||
|
for (var i = offset || 0, j = 0; i < arrLike.length; i += 1, j += 1) {
|
||||||
|
arr[j] = arrLike[i];
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
};
|
||||||
|
|
||||||
|
var joiny = function (arr, joiner) {
|
||||||
|
var str = '';
|
||||||
|
for (var i = 0; i < arr.length; i += 1) {
|
||||||
|
str += arr[i];
|
||||||
|
if (i + 1 < arr.length) {
|
||||||
|
str += joiner;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = function bind(that) {
|
||||||
|
var target = this;
|
||||||
|
if (typeof target !== 'function' || toStr.apply(target) !== funcType) {
|
||||||
|
throw new TypeError(ERROR_MESSAGE + target);
|
||||||
|
}
|
||||||
|
var args = slicy(arguments, 1);
|
||||||
|
|
||||||
|
var bound;
|
||||||
|
var binder = function () {
|
||||||
|
if (this instanceof bound) {
|
||||||
|
var result = target.apply(
|
||||||
|
this,
|
||||||
|
concatty(args, arguments)
|
||||||
|
);
|
||||||
|
if (Object(result) === result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
return target.apply(
|
||||||
|
that,
|
||||||
|
concatty(args, arguments)
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
var boundLength = max(0, target.length - args.length);
|
||||||
|
var boundArgs = [];
|
||||||
|
for (var i = 0; i < boundLength; i++) {
|
||||||
|
boundArgs[i] = '$' + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
bound = Function('binder', 'return function (' + joiny(boundArgs, ',') + '){ return binder.apply(this,arguments); }')(binder);
|
||||||
|
|
||||||
|
if (target.prototype) {
|
||||||
|
var Empty = function Empty() {};
|
||||||
|
Empty.prototype = target.prototype;
|
||||||
|
bound.prototype = new Empty();
|
||||||
|
Empty.prototype = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bound;
|
||||||
|
};
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var implementation = require('./implementation');
|
||||||
|
|
||||||
|
module.exports = Function.prototype.bind || implementation;
|
||||||
+87
@@ -0,0 +1,87 @@
|
|||||||
|
{
|
||||||
|
"name": "function-bind",
|
||||||
|
"version": "1.1.2",
|
||||||
|
"description": "Implementation of Function.prototype.bind",
|
||||||
|
"keywords": [
|
||||||
|
"function",
|
||||||
|
"bind",
|
||||||
|
"shim",
|
||||||
|
"es5"
|
||||||
|
],
|
||||||
|
"author": "Raynos <raynos2@gmail.com>",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/Raynos/function-bind.git"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
},
|
||||||
|
"main": "index",
|
||||||
|
"homepage": "https://github.com/Raynos/function-bind",
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "Raynos"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Jordan Harband",
|
||||||
|
"url": "https://github.com/ljharb"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/Raynos/function-bind/issues",
|
||||||
|
"email": "raynos2@gmail.com"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@ljharb/eslint-config": "^21.1.0",
|
||||||
|
"aud": "^2.0.3",
|
||||||
|
"auto-changelog": "^2.4.0",
|
||||||
|
"eslint": "=8.8.0",
|
||||||
|
"in-publish": "^2.0.1",
|
||||||
|
"npmignore": "^0.3.0",
|
||||||
|
"nyc": "^10.3.2",
|
||||||
|
"safe-publish-latest": "^2.0.0",
|
||||||
|
"tape": "^5.7.1"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"scripts": {
|
||||||
|
"prepublishOnly": "safe-publish-latest",
|
||||||
|
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||||
|
"prepack": "npmignore --auto --commentLines=autogenerated",
|
||||||
|
"pretest": "npm run lint",
|
||||||
|
"test": "npm run tests-only",
|
||||||
|
"posttest": "aud --production",
|
||||||
|
"tests-only": "nyc tape 'test/**/*.js'",
|
||||||
|
"lint": "eslint --ext=js,mjs .",
|
||||||
|
"version": "auto-changelog && git add CHANGELOG.md",
|
||||||
|
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
|
||||||
|
},
|
||||||
|
"testling": {
|
||||||
|
"files": "test/index.js",
|
||||||
|
"browsers": [
|
||||||
|
"ie/8..latest",
|
||||||
|
"firefox/16..latest",
|
||||||
|
"firefox/nightly",
|
||||||
|
"chrome/22..latest",
|
||||||
|
"chrome/canary",
|
||||||
|
"opera/12..latest",
|
||||||
|
"opera/next",
|
||||||
|
"safari/5.1..latest",
|
||||||
|
"ipad/6.0..latest",
|
||||||
|
"iphone/6.0..latest",
|
||||||
|
"android-browser/4.2..latest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"auto-changelog": {
|
||||||
|
"output": "CHANGELOG.md",
|
||||||
|
"template": "keepachangelog",
|
||||||
|
"unreleased": false,
|
||||||
|
"commitLimit": false,
|
||||||
|
"backfillLimit": false,
|
||||||
|
"hideCredit": true
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"ignore": [
|
||||||
|
".github/workflows"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"rules": {
|
||||||
|
"array-bracket-newline": 0,
|
||||||
|
"array-element-newline": 0,
|
||||||
|
"max-statements-per-line": [2, { "max": 2 }],
|
||||||
|
"no-invalid-this": 0,
|
||||||
|
"no-magic-numbers": 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
+252
@@ -0,0 +1,252 @@
|
|||||||
|
// jscs:disable requireUseStrict
|
||||||
|
|
||||||
|
var test = require('tape');
|
||||||
|
|
||||||
|
var functionBind = require('../implementation');
|
||||||
|
var getCurrentContext = function () { return this; };
|
||||||
|
|
||||||
|
test('functionBind is a function', function (t) {
|
||||||
|
t.equal(typeof functionBind, 'function');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('non-functions', function (t) {
|
||||||
|
var nonFunctions = [true, false, [], {}, 42, 'foo', NaN, /a/g];
|
||||||
|
t.plan(nonFunctions.length);
|
||||||
|
for (var i = 0; i < nonFunctions.length; ++i) {
|
||||||
|
try { functionBind.call(nonFunctions[i]); } catch (ex) {
|
||||||
|
t.ok(ex instanceof TypeError, 'throws when given ' + String(nonFunctions[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('without a context', function (t) {
|
||||||
|
t.test('binds properly', function (st) {
|
||||||
|
var args, context;
|
||||||
|
var namespace = {
|
||||||
|
func: functionBind.call(function () {
|
||||||
|
args = Array.prototype.slice.call(arguments);
|
||||||
|
context = this;
|
||||||
|
})
|
||||||
|
};
|
||||||
|
namespace.func(1, 2, 3);
|
||||||
|
st.deepEqual(args, [1, 2, 3]);
|
||||||
|
st.equal(context, getCurrentContext.call());
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('binds properly, and still supplies bound arguments', function (st) {
|
||||||
|
var args, context;
|
||||||
|
var namespace = {
|
||||||
|
func: functionBind.call(function () {
|
||||||
|
args = Array.prototype.slice.call(arguments);
|
||||||
|
context = this;
|
||||||
|
}, undefined, 1, 2, 3)
|
||||||
|
};
|
||||||
|
namespace.func(4, 5, 6);
|
||||||
|
st.deepEqual(args, [1, 2, 3, 4, 5, 6]);
|
||||||
|
st.equal(context, getCurrentContext.call());
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('returns properly', function (st) {
|
||||||
|
var args;
|
||||||
|
var namespace = {
|
||||||
|
func: functionBind.call(function () {
|
||||||
|
args = Array.prototype.slice.call(arguments);
|
||||||
|
return this;
|
||||||
|
}, null)
|
||||||
|
};
|
||||||
|
var context = namespace.func(1, 2, 3);
|
||||||
|
st.equal(context, getCurrentContext.call(), 'returned context is namespaced context');
|
||||||
|
st.deepEqual(args, [1, 2, 3], 'passed arguments are correct');
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('returns properly with bound arguments', function (st) {
|
||||||
|
var args;
|
||||||
|
var namespace = {
|
||||||
|
func: functionBind.call(function () {
|
||||||
|
args = Array.prototype.slice.call(arguments);
|
||||||
|
return this;
|
||||||
|
}, null, 1, 2, 3)
|
||||||
|
};
|
||||||
|
var context = namespace.func(4, 5, 6);
|
||||||
|
st.equal(context, getCurrentContext.call(), 'returned context is namespaced context');
|
||||||
|
st.deepEqual(args, [1, 2, 3, 4, 5, 6], 'passed arguments are correct');
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('called as a constructor', function (st) {
|
||||||
|
var thunkify = function (value) {
|
||||||
|
return function () { return value; };
|
||||||
|
};
|
||||||
|
st.test('returns object value', function (sst) {
|
||||||
|
var expectedReturnValue = [1, 2, 3];
|
||||||
|
var Constructor = functionBind.call(thunkify(expectedReturnValue), null);
|
||||||
|
var result = new Constructor();
|
||||||
|
sst.equal(result, expectedReturnValue);
|
||||||
|
sst.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
st.test('does not return primitive value', function (sst) {
|
||||||
|
var Constructor = functionBind.call(thunkify(42), null);
|
||||||
|
var result = new Constructor();
|
||||||
|
sst.notEqual(result, 42);
|
||||||
|
sst.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
st.test('object from bound constructor is instance of original and bound constructor', function (sst) {
|
||||||
|
var A = function (x) {
|
||||||
|
this.name = x || 'A';
|
||||||
|
};
|
||||||
|
var B = functionBind.call(A, null, 'B');
|
||||||
|
|
||||||
|
var result = new B();
|
||||||
|
sst.ok(result instanceof B, 'result is instance of bound constructor');
|
||||||
|
sst.ok(result instanceof A, 'result is instance of original constructor');
|
||||||
|
sst.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('with a context', function (t) {
|
||||||
|
t.test('with no bound arguments', function (st) {
|
||||||
|
var args, context;
|
||||||
|
var boundContext = {};
|
||||||
|
var namespace = {
|
||||||
|
func: functionBind.call(function () {
|
||||||
|
args = Array.prototype.slice.call(arguments);
|
||||||
|
context = this;
|
||||||
|
}, boundContext)
|
||||||
|
};
|
||||||
|
namespace.func(1, 2, 3);
|
||||||
|
st.equal(context, boundContext, 'binds a context properly');
|
||||||
|
st.deepEqual(args, [1, 2, 3], 'supplies passed arguments');
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('with bound arguments', function (st) {
|
||||||
|
var args, context;
|
||||||
|
var boundContext = {};
|
||||||
|
var namespace = {
|
||||||
|
func: functionBind.call(function () {
|
||||||
|
args = Array.prototype.slice.call(arguments);
|
||||||
|
context = this;
|
||||||
|
}, boundContext, 1, 2, 3)
|
||||||
|
};
|
||||||
|
namespace.func(4, 5, 6);
|
||||||
|
st.equal(context, boundContext, 'binds a context properly');
|
||||||
|
st.deepEqual(args, [1, 2, 3, 4, 5, 6], 'supplies bound and passed arguments');
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('returns properly', function (st) {
|
||||||
|
var boundContext = {};
|
||||||
|
var args;
|
||||||
|
var namespace = {
|
||||||
|
func: functionBind.call(function () {
|
||||||
|
args = Array.prototype.slice.call(arguments);
|
||||||
|
return this;
|
||||||
|
}, boundContext)
|
||||||
|
};
|
||||||
|
var context = namespace.func(1, 2, 3);
|
||||||
|
st.equal(context, boundContext, 'returned context is bound context');
|
||||||
|
st.notEqual(context, getCurrentContext.call(), 'returned context is not lexical context');
|
||||||
|
st.deepEqual(args, [1, 2, 3], 'passed arguments are correct');
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('returns properly with bound arguments', function (st) {
|
||||||
|
var boundContext = {};
|
||||||
|
var args;
|
||||||
|
var namespace = {
|
||||||
|
func: functionBind.call(function () {
|
||||||
|
args = Array.prototype.slice.call(arguments);
|
||||||
|
return this;
|
||||||
|
}, boundContext, 1, 2, 3)
|
||||||
|
};
|
||||||
|
var context = namespace.func(4, 5, 6);
|
||||||
|
st.equal(context, boundContext, 'returned context is bound context');
|
||||||
|
st.notEqual(context, getCurrentContext.call(), 'returned context is not lexical context');
|
||||||
|
st.deepEqual(args, [1, 2, 3, 4, 5, 6], 'passed arguments are correct');
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('passes the correct arguments when called as a constructor', function (st) {
|
||||||
|
var expected = { name: 'Correct' };
|
||||||
|
var namespace = {
|
||||||
|
Func: functionBind.call(function (arg) {
|
||||||
|
return arg;
|
||||||
|
}, { name: 'Incorrect' })
|
||||||
|
};
|
||||||
|
var returned = new namespace.Func(expected);
|
||||||
|
st.equal(returned, expected, 'returns the right arg when called as a constructor');
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('has the new instance\'s context when called as a constructor', function (st) {
|
||||||
|
var actualContext;
|
||||||
|
var expectedContext = { foo: 'bar' };
|
||||||
|
var namespace = {
|
||||||
|
Func: functionBind.call(function () {
|
||||||
|
actualContext = this;
|
||||||
|
}, expectedContext)
|
||||||
|
};
|
||||||
|
var result = new namespace.Func();
|
||||||
|
st.equal(result instanceof namespace.Func, true);
|
||||||
|
st.notEqual(actualContext, expectedContext);
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('bound function length', function (t) {
|
||||||
|
t.test('sets a correct length without thisArg', function (st) {
|
||||||
|
var subject = functionBind.call(function (a, b, c) { return a + b + c; });
|
||||||
|
st.equal(subject.length, 3);
|
||||||
|
st.equal(subject(1, 2, 3), 6);
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('sets a correct length with thisArg', function (st) {
|
||||||
|
var subject = functionBind.call(function (a, b, c) { return a + b + c; }, {});
|
||||||
|
st.equal(subject.length, 3);
|
||||||
|
st.equal(subject(1, 2, 3), 6);
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('sets a correct length without thisArg and first argument', function (st) {
|
||||||
|
var subject = functionBind.call(function (a, b, c) { return a + b + c; }, undefined, 1);
|
||||||
|
st.equal(subject.length, 2);
|
||||||
|
st.equal(subject(2, 3), 6);
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('sets a correct length with thisArg and first argument', function (st) {
|
||||||
|
var subject = functionBind.call(function (a, b, c) { return a + b + c; }, {}, 1);
|
||||||
|
st.equal(subject.length, 2);
|
||||||
|
st.equal(subject(2, 3), 6);
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('sets a correct length without thisArg and too many arguments', function (st) {
|
||||||
|
var subject = functionBind.call(function (a, b, c) { return a + b + c; }, undefined, 1, 2, 3, 4);
|
||||||
|
st.equal(subject.length, 0);
|
||||||
|
st.equal(subject(), 6);
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('sets a correct length with thisArg and too many arguments', function (st) {
|
||||||
|
var subject = functionBind.call(function (a, b, c) { return a + b + c; }, {}, 1, 2, 3, 4);
|
||||||
|
st.equal(subject.length, 0);
|
||||||
|
st.equal(subject(), 6);
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
});
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: [ljharb]
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: npm/hasown
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: # Replace with a single custom sponsorship URL
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"all": true,
|
||||||
|
"check-coverage": false,
|
||||||
|
"reporter": ["text-summary", "text", "html", "json"],
|
||||||
|
"lines": 86,
|
||||||
|
"statements": 85.93,
|
||||||
|
"functions": 82.43,
|
||||||
|
"branches": 76.06,
|
||||||
|
"exclude": [
|
||||||
|
"coverage",
|
||||||
|
"test"
|
||||||
|
]
|
||||||
|
}
|
||||||
+58
@@ -0,0 +1,58 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [v2.0.4](https://github.com/inspect-js/hasOwn/compare/v2.0.3...v2.0.4) - 2026-05-28
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [types] drop the dead key-narrowing overload [`fdab00e`](https://github.com/inspect-js/hasOwn/commit/fdab00e2703e65411424e19bf86a7e72a8f10da9)
|
||||||
|
- [Dev Deps] update `@ljharb/eslint-config`, `auto-changelog`, `eslint` [`91f6247`](https://github.com/inspect-js/hasOwn/commit/91f624768dd0f7db0d019b89d4d86bd66e20ec30)
|
||||||
|
|
||||||
|
## [v2.0.3](https://github.com/inspect-js/hasOwn/compare/v2.0.2...v2.0.3) - 2026-04-17
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [actions] update workflows [`fb837b8`](https://github.com/inspect-js/hasOwn/commit/fb837b849bcdb8416fdc8fd344edfacd5574696c)
|
||||||
|
- [Dev Deps] update `@arethetypeswrong/cli`, `@ljharb/eslint-config`, `@ljharb/tsconfig`, `@types/tape`, `auto-changelog`, `eslint`, `mock-property`, `npmignore`, `tape` [`f4b279b`](https://github.com/inspect-js/hasOwn/commit/f4b279bd682be34b3f0ede2a58d4e8acb58d6d47)
|
||||||
|
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`; migrate to flat config [`7e415ce`](https://github.com/inspect-js/hasOwn/commit/7e415cee55ebf43b3c34d7fd86db73a9928b05f7)
|
||||||
|
- [Dev Deps] update `eslint` [`ef313da`](https://github.com/inspect-js/hasOwn/commit/ef313da342d33b60e23e738b9f5a86f6065f39ef)
|
||||||
|
- [meta] use `npm audit` instead of `aud` [`d5c6d4d`](https://github.com/inspect-js/hasOwn/commit/d5c6d4d7a19c6ca4f14ac173b30d8bf25abcabee)
|
||||||
|
- [types] add overload that narrows the key [`cc03a09`](https://github.com/inspect-js/hasOwn/commit/cc03a097e9402fb8b86d413050e67f790dd6c8c5)
|
||||||
|
|
||||||
|
## [v2.0.2](https://github.com/inspect-js/hasOwn/compare/v2.0.1...v2.0.2) - 2024-03-10
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [types] use shared config [`68e9d4d`](https://github.com/inspect-js/hasOwn/commit/68e9d4dab6facb4f05f02c6baea94a3f2a4e44b2)
|
||||||
|
- [actions] remove redundant finisher; use reusable workflow [`241a68e`](https://github.com/inspect-js/hasOwn/commit/241a68e13ea1fe52bec5ba7f74144befc31fae7b)
|
||||||
|
- [Tests] increase coverage [`4125c0d`](https://github.com/inspect-js/hasOwn/commit/4125c0d6121db56ae30e38346dfb0c000b04f0a7)
|
||||||
|
- [Tests] skip `npm ls` in old node due to TS [`01b9282`](https://github.com/inspect-js/hasOwn/commit/01b92822f9971dea031eafdd14767df41d61c202)
|
||||||
|
- [types] improve predicate type [`d340f85`](https://github.com/inspect-js/hasOwn/commit/d340f85ce02e286ef61096cbbb6697081d40a12b)
|
||||||
|
- [Dev Deps] update `tape` [`70089fc`](https://github.com/inspect-js/hasOwn/commit/70089fcf544e64acc024cbe60f5a9b00acad86de)
|
||||||
|
- [Tests] use `@arethetypeswrong/cli` [`50b272c`](https://github.com/inspect-js/hasOwn/commit/50b272c829f40d053a3dd91c9796e0ac0b2af084)
|
||||||
|
|
||||||
|
## [v2.0.1](https://github.com/inspect-js/hasOwn/compare/v2.0.0...v2.0.1) - 2024-02-10
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [types] use a handwritten d.ts file; fix exported type [`012b989`](https://github.com/inspect-js/hasOwn/commit/012b9898ccf91dc441e2ebf594ff70270a5fda58)
|
||||||
|
- [Dev Deps] update `@types/function-bind`, `@types/mock-property`, `@types/tape`, `aud`, `mock-property`, `npmignore`, `tape`, `typescript` [`977a56f`](https://github.com/inspect-js/hasOwn/commit/977a56f51a1f8b20566f3c471612137894644025)
|
||||||
|
- [meta] add `sideEffects` flag [`3a60b7b`](https://github.com/inspect-js/hasOwn/commit/3a60b7bf42fccd8c605e5f145a6fcc83b13cb46f)
|
||||||
|
|
||||||
|
## [v2.0.0](https://github.com/inspect-js/hasOwn/compare/v1.0.1...v2.0.0) - 2023-10-19
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- revamped implementation, tests, readme [`72bf8b3`](https://github.com/inspect-js/hasOwn/commit/72bf8b338e77a638f0a290c63ffaed18339c36b4)
|
||||||
|
- [meta] revamp package.json [`079775f`](https://github.com/inspect-js/hasOwn/commit/079775fb1ec72c1c6334069593617a0be3847458)
|
||||||
|
- Only apps should have lockfiles [`6640e23`](https://github.com/inspect-js/hasOwn/commit/6640e233d1bb8b65260880f90787637db157d215)
|
||||||
|
|
||||||
|
## v1.0.1 - 2023-10-10
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- Initial commit [`8dbfde6`](https://github.com/inspect-js/hasOwn/commit/8dbfde6e8fb0ebb076fab38d138f2984eb340a62)
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Jordan Harband and contributors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
# hasown <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
||||||
|
|
||||||
|
[![github actions][actions-image]][actions-url]
|
||||||
|
[![coverage][codecov-image]][codecov-url]
|
||||||
|
[![License][license-image]][license-url]
|
||||||
|
[![Downloads][downloads-image]][downloads-url]
|
||||||
|
|
||||||
|
[![npm badge][npm-badge-png]][package-url]
|
||||||
|
|
||||||
|
A robust, ES3 compatible, "has own property" predicate.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```js
|
||||||
|
const assert = require('assert');
|
||||||
|
const hasOwn = require('hasown');
|
||||||
|
|
||||||
|
assert.equal(hasOwn({}, 'toString'), false);
|
||||||
|
assert.equal(hasOwn([], 'length'), true);
|
||||||
|
assert.equal(hasOwn({ a: 42 }, 'a'), true);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
Simply clone the repo, `npm install`, and run `npm test`
|
||||||
|
|
||||||
|
[package-url]: https://npmjs.org/package/hasown
|
||||||
|
[npm-version-svg]: https://versionbadg.es/inspect-js/hasown.svg
|
||||||
|
[deps-svg]: https://david-dm.org/inspect-js/hasOwn.svg
|
||||||
|
[deps-url]: https://david-dm.org/inspect-js/hasOwn
|
||||||
|
[dev-deps-svg]: https://david-dm.org/inspect-js/hasOwn/dev-status.svg
|
||||||
|
[dev-deps-url]: https://david-dm.org/inspect-js/hasOwn#info=devDependencies
|
||||||
|
[npm-badge-png]: https://nodei.co/npm/hasown.png?downloads=true&stars=true
|
||||||
|
[license-image]: https://img.shields.io/npm/l/hasown.svg
|
||||||
|
[license-url]: LICENSE
|
||||||
|
[downloads-image]: https://img.shields.io/npm/dm/hasown.svg
|
||||||
|
[downloads-url]: https://npm-stat.com/charts.html?package=hasown
|
||||||
|
[codecov-image]: https://codecov.io/gh/inspect-js/hasOwn/branch/main/graphs/badge.svg
|
||||||
|
[codecov-url]: https://app.codecov.io/gh/inspect-js/hasOwn/
|
||||||
|
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/inspect-js/hasOwn
|
||||||
|
[actions-url]: https://github.com/inspect-js/hasOwn/actions
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
import ljharbConfig from '@ljharb/eslint-config/flat';
|
||||||
|
|
||||||
|
export default [
|
||||||
|
...ljharbConfig,
|
||||||
|
{ rules: { 'no-extra-parens': 'off' } },
|
||||||
|
];
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
declare function hasOwn<O, K extends PropertyKey, V = unknown>(o: O, p: K): o is O & Record<K, V>;
|
||||||
|
|
||||||
|
export = hasOwn;
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var call = Function.prototype.call;
|
||||||
|
var $hasOwn = Object.prototype.hasOwnProperty;
|
||||||
|
var bind = require('function-bind');
|
||||||
|
|
||||||
|
/** @type {import('.')} */
|
||||||
|
module.exports = bind.call(call, $hasOwn);
|
||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
{
|
||||||
|
"name": "hasown",
|
||||||
|
"version": "2.0.4",
|
||||||
|
"description": "A robust, ES3 compatible, \"has own property\" predicate.",
|
||||||
|
"main": "index.js",
|
||||||
|
"exports": {
|
||||||
|
".": "./index.js",
|
||||||
|
"./package.json": "./package.json"
|
||||||
|
},
|
||||||
|
"types": "index.d.ts",
|
||||||
|
"sideEffects": false,
|
||||||
|
"scripts": {
|
||||||
|
"prepack": "npmignore --auto --commentLines=autogenerated",
|
||||||
|
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||||
|
"prepublishOnly": "safe-publish-latest",
|
||||||
|
"prelint": "evalmd README.md",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"postlint": "npm run tsc",
|
||||||
|
"pretest": "npm run lint",
|
||||||
|
"tsc": "tsc -p .",
|
||||||
|
"posttsc": "attw -P",
|
||||||
|
"tests-only": "nyc tape 'test/**/*.js'",
|
||||||
|
"test": "npm run tests-only",
|
||||||
|
"posttest": "npx npm@\">= 10.2\" audit --production",
|
||||||
|
"version": "auto-changelog && git add CHANGELOG.md",
|
||||||
|
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/inspect-js/hasOwn.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"has",
|
||||||
|
"hasOwnProperty",
|
||||||
|
"hasOwn",
|
||||||
|
"has-own",
|
||||||
|
"own",
|
||||||
|
"has",
|
||||||
|
"property",
|
||||||
|
"in",
|
||||||
|
"javascript",
|
||||||
|
"ecmascript"
|
||||||
|
],
|
||||||
|
"author": "Jordan Harband <ljharb@gmail.com>",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/inspect-js/hasOwn/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/inspect-js/hasOwn#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"function-bind": "^1.1.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@arethetypeswrong/cli": "^0.18.2",
|
||||||
|
"@ljharb/eslint-config": "^22.2.3",
|
||||||
|
"@ljharb/tsconfig": "^0.3.2",
|
||||||
|
"@types/function-bind": "^1.1.10",
|
||||||
|
"@types/tape": "^5.8.1",
|
||||||
|
"auto-changelog": "^2.5.1",
|
||||||
|
"eslint": "^10.4.0",
|
||||||
|
"evalmd": "^0.0.19",
|
||||||
|
"in-publish": "^2.0.1",
|
||||||
|
"jiti": "^0.0.0",
|
||||||
|
"mock-property": "^1.1.0",
|
||||||
|
"npmignore": "^0.3.5",
|
||||||
|
"nyc": "^10.3.2",
|
||||||
|
"safe-publish-latest": "^2.0.0",
|
||||||
|
"tape": "^5.9.0",
|
||||||
|
"typescript": "next"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
},
|
||||||
|
"testling": {
|
||||||
|
"files": "test/index.js"
|
||||||
|
},
|
||||||
|
"auto-changelog": {
|
||||||
|
"output": "CHANGELOG.md",
|
||||||
|
"template": "keepachangelog",
|
||||||
|
"unreleased": false,
|
||||||
|
"commitLimit": false,
|
||||||
|
"backfillLimit": false,
|
||||||
|
"hideCredit": true
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"ignore": [
|
||||||
|
".github/workflows",
|
||||||
|
"test"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"extends": "@ljharb/tsconfig",
|
||||||
|
"exclude": [
|
||||||
|
"coverage",
|
||||||
|
],
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"extends": "@ljharb",
|
||||||
|
"root": true,
|
||||||
|
"rules": {
|
||||||
|
"func-style": 1,
|
||||||
|
},
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": "test/**",
|
||||||
|
"rules": {
|
||||||
|
"global-require": 0,
|
||||||
|
"max-depth": 0,
|
||||||
|
"max-lines-per-function": 0,
|
||||||
|
"no-negated-condition": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"all": true,
|
||||||
|
"check-coverage": false,
|
||||||
|
"reporter": ["text-summary", "text", "html", "json"],
|
||||||
|
"exclude": [
|
||||||
|
"coverage",
|
||||||
|
"test"
|
||||||
|
]
|
||||||
|
}
|
||||||
+349
@@ -0,0 +1,349 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||||
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [v2.16.2](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.16.1...v2.16.2) - 2026-05-05
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Tests] increase coverage [`1fc59fe`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/1fc59fe685f0b9590b571384db1383ab8e1096a3)
|
||||||
|
- [actions] update workflows [`0f6217b`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/0f6217b97a166fcaa4a02b0a34e0a186c40df660)
|
||||||
|
- [Fix] node 26 drops _stream_* modules [`3acff68`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/3acff68b25b44c9ae6fee1a1dc236ebb7c5338af)
|
||||||
|
- [Dev Deps] update `@ljharb/eslint-config`, `eslint`, `npmignore` [`f06678c`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/f06678ce7f4df97e691a8d285d4aacb5da4a9790)
|
||||||
|
- [Deps] update `hasown` [`d9eae68`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/d9eae68fd912c2268260e52714719d1799e9a08b)
|
||||||
|
- [Dev Deps] update `@ljharb/eslint-config` [`8273701`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/82737010e7f3ed26c6f6183ee082e66a045125b6)
|
||||||
|
- [readme] replace runkit CI badge with shields.io check-runs badge [`6b86754`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/6b867544789c82a40db44031a30612d89978b2d9)
|
||||||
|
|
||||||
|
## [v2.16.1](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.16.0...v2.16.1) - 2024-12-21
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- [Fix] `node:sqlite` is available in node ^22.13 [`#17`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/issues/17)
|
||||||
|
|
||||||
|
## [v2.16.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.15.1...v2.16.0) - 2024-12-13
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [New] add `node:sqlite` [`1ee94d2`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/1ee94d20857e22cdb24e9b4bb1a2097f2e03e26f)
|
||||||
|
- [Dev Deps] update `auto-changelog`, `tape` [`aa84aa3`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/aa84aa34face677f14e08ec1c737f0c4bba27260)
|
||||||
|
|
||||||
|
## [v2.15.1](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.15.0...v2.15.1) - 2024-08-21
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Tests] add `process.getBuiltinModule` tests [`28c7791`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/28c7791c196d58c64cfdf638b7e68ed1b62a4da0)
|
||||||
|
- [Fix] `test/mock_loader` is no longer exposed as of v22.7 [`68b08b0`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/68b08b0d7963447dbffa5142e8810dca550383af)
|
||||||
|
- [Tests] replace `aud` with `npm audit` [`32f8060`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/32f806026dac14f9016be4401a643851240c76b9)
|
||||||
|
- [Dev Deps] update `mock-property` [`f7d3c8f`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/f7d3c8f01e922be49621683eb41477c4f50522e1)
|
||||||
|
- [Dev Deps] add missing peer dep [`eaee885`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/eaee885b67238819e9c8ed5bd2098766e1d05331)
|
||||||
|
|
||||||
|
## [v2.15.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.14.0...v2.15.0) - 2024-07-17
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [New] add `node:sea` [`2819fb3`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/2819fb3eae312fa64643bc5430ebd06ec0f3fb88)
|
||||||
|
|
||||||
|
## [v2.14.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.13.1...v2.14.0) - 2024-06-20
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `mock-property`, `npmignore`, `tape` [`0e43200`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/0e432006d97237cc082d41e6a593e87c81068364)
|
||||||
|
- [meta] add missing `engines.node` [`4ea3af8`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/4ea3af88891a1d4f96026f0ec0ef08c67cd1bd24)
|
||||||
|
- [New] add `test/mock_loader` [`e9fbd29`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/e9fbd2951383be070aeffb9ebbf3715237282610)
|
||||||
|
- [Deps] update `hasown` [`57f1940`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/57f1940947b3e368abdf529232d2f17d88909358)
|
||||||
|
|
||||||
|
## [v2.13.1](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.13.0...v2.13.1) - 2023-10-20
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Refactor] use `hasown` instead of `has` [`0e52096`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/0e520968b0a725276b67420ab4b877486b243ae0)
|
||||||
|
- [Dev Deps] update `mock-property`, `tape` [`8736b35`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/8736b35464d0f297b55da2c6b30deee04b8303c5)
|
||||||
|
|
||||||
|
## [v2.13.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.12.1...v2.13.0) - 2023-08-05
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `semver`, `tape` [`c75b263`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/c75b263d047cb53430c3970107e5eb64d6cd6c0c)
|
||||||
|
- [New] `node:test/reporters` and `wasi`/`node:wasi` are in v18.17 [`d76cbf8`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/d76cbf8e9b208acfd98913fed5a5f45cb15fe5dc)
|
||||||
|
|
||||||
|
## [v2.12.1](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.12.0...v2.12.1) - 2023-05-16
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Fix] `test/reporters` now requires the `node:` prefix as of v20.2 [`12183d0`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/12183d0d8e4edf56b6ce18a1b3be54bfce10175b)
|
||||||
|
|
||||||
|
## [v2.12.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.11.0...v2.12.0) - 2023-04-10
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [actions] update rebase action to use reusable workflow [`c0a7251`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/c0a7251f734f3c621932c5fcdfd1bf966b42ca32)
|
||||||
|
- [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape` [`9ae8b7f`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/9ae8b7fac03c369861d0991b4a2ce8d4848e6a7d)
|
||||||
|
- [New] `test/reporters` added in v19.9, `wasi` added in v20 [`9d5341a`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/9d5341ab32053f25b7fa7db3c0e18461db24a79c)
|
||||||
|
- [Dev Deps] add missing `in-publish` dep [`5980245`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/59802456e9ac919fa748f53be9d8fbf304a197df)
|
||||||
|
|
||||||
|
## [v2.11.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.10.0...v2.11.0) - 2022-10-18
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [meta] use `npmignore` to autogenerate an npmignore file [`3360011`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/33600118857b46177178072fba2affcdeb009d12)
|
||||||
|
- [Dev Deps] update `aud`, `tape` [`651c6b0`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/651c6b0cc2799d4130866cf43ad333dcade3d26c)
|
||||||
|
- [New] `inspector/promises` and `node:inspector/promises` is now available in node 19 [`22d332f`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/22d332fe22ac050305444e0781ff85af819abcb0)
|
||||||
|
|
||||||
|
## [v2.10.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.9.0...v2.10.0) - 2022-08-03
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [New] `node:test` is now available in node ^16.17 [`e8fd36e`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/e8fd36e9b86c917775a07cc473b62a3294f459f2)
|
||||||
|
- [Tests] improve skip message [`c014a4c`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/c014a4c0cd6eb15fff573ae4709191775e70cab4)
|
||||||
|
|
||||||
|
## [v2.9.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.8.1...v2.9.0) - 2022-04-19
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [New] add `node:test`, in node 18+ [`f853eca`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/f853eca801d0a7d4e1dbb670f1b6d9837d9533c5)
|
||||||
|
- [Tests] use `mock-property` [`03b3644`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/03b3644dff4417f4ba5a7d0aa0138f5f6b3e5c46)
|
||||||
|
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `auto-changelog`, `tape` [`7c0e2d0`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/7c0e2d06ed2a89acf53abe2ab34d703ed5b03455)
|
||||||
|
- [meta] simplify "exports" [`d6ed201`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/d6ed201eba7fbba0e59814a9050fc49a6e9878c8)
|
||||||
|
|
||||||
|
## [v2.8.1](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.8.0...v2.8.1) - 2022-01-05
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [actions] reuse common workflows [`cd2cf9b`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/cd2cf9b3b66c8d328f65610efe41e9325db7716d)
|
||||||
|
- [Fix] update node 0.4 results [`062195d`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/062195d89f0876a88b95d378b43f7fcc1205bc5b)
|
||||||
|
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `safe-publish-latest`, `tape` [`0790b62`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/0790b6222848c6167132f9f73acc3520fa8d1298)
|
||||||
|
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape` [`7d139a6`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/7d139a6d767709eabf0a0251e074ec1fb230c06e)
|
||||||
|
- [Tests] run `nyc` in `tests-only`, not `test` [`780e8a0`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/780e8a049951c71cf78b1707f0871c48a28bde14)
|
||||||
|
|
||||||
|
## [v2.8.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.7.0...v2.8.0) - 2021-10-14
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [actions] update codecov uploader [`0cfe94e`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/0cfe94e106a7d005ea03e008c0a21dec13a77904)
|
||||||
|
- [New] add `readline/promises` to node v17+ [`4f78c30`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/4f78c3008b1b58b4db6dc91d99610b1bc859da7e)
|
||||||
|
- [Tests] node ^14.18 supports `node:` prefixes for CJS [`43e2f17`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/43e2f177452cea2f0eaf34f61b5407217bbdb6f4)
|
||||||
|
|
||||||
|
## [v2.7.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.6.0...v2.7.0) - 2021-09-27
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [New] node `v14.18` added `node:`-prefixed core modules to `require` [`6d943ab`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/6d943abe81382b9bbe344384d80fbfebe1cc0526)
|
||||||
|
- [Tests] add coverage for Object.prototype pollution [`c6baf5f`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/c6baf5f942311a1945c1af41167bb80b84df2af7)
|
||||||
|
- [Dev Deps] update `@ljharb/eslint-config` [`6717f00`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/6717f000d063ea57beb772bded36c2f056ac404c)
|
||||||
|
- [eslint] fix linter warning [`594c10b`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/594c10bb7d39d7eb00925c90924199ff596184b2)
|
||||||
|
- [meta] add `sideEffects` flag [`c32cfa5`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/c32cfa5195632944c4dd4284a142b8476e75be13)
|
||||||
|
|
||||||
|
## [v2.6.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.5.0...v2.6.0) - 2021-08-17
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Dev Deps] update `eslint`, `tape` [`6cc928f`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/6cc928f8a4bba66aeeccc4f6beeac736d4bd3081)
|
||||||
|
- [New] add `stream/consumers` to node `>= 16.7` [`a1a423e`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/a1a423e467e4cc27df180234fad5bab45943e67d)
|
||||||
|
- [Refactor] Remove duplicated `&&` operand [`86faea7`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/86faea738213a2433c62d1098488dc9314dca832)
|
||||||
|
- [Tests] include prereleases [`a4da7a6`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/a4da7a6abf7568e2aa4fd98e69452179f1850963)
|
||||||
|
|
||||||
|
## [v2.5.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.4.0...v2.5.0) - 2021-07-12
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Dev Deps] update `auto-changelog`, `eslint` [`6334cc9`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/6334cc94f3af7469685bd8f236740991baaf2705)
|
||||||
|
- [New] add `stream/web` to node v16.5+ [`17ac59b`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/17ac59b662d63e220a2e5728625f005c24f177b2)
|
||||||
|
|
||||||
|
## [v2.4.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.3.0...v2.4.0) - 2021-05-09
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [readme] add actions and codecov badges [`82b7faa`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/82b7faa12b56dbe47fbea67e1a5b9e447027ba40)
|
||||||
|
- [Dev Deps] update `@ljharb/eslint-config`, `aud` [`8096868`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/8096868c024a161ccd4d44110b136763e92eace8)
|
||||||
|
- [Dev Deps] update `eslint` [`6726824`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/67268249b88230018c510f6532a8046d7326346f)
|
||||||
|
- [New] add `diagnostics_channel` to node `^14.17` [`86c6563`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/86c65634201b8ff9b3e48a9a782594579c7f5c3c)
|
||||||
|
- [meta] fix prepublish script [`697a01e`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/697a01e3c9c0be074066520954f30fb28532ec57)
|
||||||
|
|
||||||
|
## [v2.3.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.2.0...v2.3.0) - 2021-04-24
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [meta] do not publish github action workflow files [`060d4bb`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/060d4bb971a29451c19ff336eb56bee27f9fa95a)
|
||||||
|
- [New] add support for `node:` prefix, in node 16+ [`7341223`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/73412230a769f6e81c05eea50b6520cebf54ed2f)
|
||||||
|
- [actions] use `node/install` instead of `node/run`; use `codecov` action [`016269a`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/016269abae9f6657a5254adfbb813f09a05067f9)
|
||||||
|
- [patch] remove unneeded `.0` in version ranges [`cb466a6`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/cb466a6d89e52b8389e5c12715efcd550c41cea3)
|
||||||
|
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`, `tape` [`c9f9c39`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/c9f9c396ace60ef81906f98059c064e6452473ed)
|
||||||
|
- [actions] update workflows [`3ee4a89`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/3ee4a89fd5a02fccd43882d905448ea6a98e9a3c)
|
||||||
|
- [Dev Deps] update `eslint`, `@ljharb/eslint-config` [`dee4fed`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/dee4fed79690c1d43a22f7fa9426abebdc6d727f)
|
||||||
|
- [Dev Deps] update `eslint`, `@ljharb/eslint-config` [`7d046ba`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/7d046ba07ae8c9292e43652694ca808d7b309de8)
|
||||||
|
- [meta] use `prepublishOnly` script for npm 7+ [`149e677`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/149e6771a5ede6d097e71785b467a9c4b4977cc7)
|
||||||
|
- [readme] remove travis badge [`903b51d`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/903b51d6b69b98abeabfbc3695c345b02646f19c)
|
||||||
|
|
||||||
|
## [v2.2.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.1.0...v2.2.0) - 2020-11-26
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Tests] migrate tests to Github Actions [`c919f57`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/c919f573c0a92d10a0acad0b650b5aecb033d426)
|
||||||
|
- [patch] `core.json`: %s/ /\t/g [`db3f685`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/db3f68581f53e73cc09cd675955eb1bdd6a5a39b)
|
||||||
|
- [Tests] run `nyc` on all tests [`b2f925f`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/b2f925f8866f210ef441f39fcc8cc42692ab89b1)
|
||||||
|
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `aud`; add `safe-publish-latest` [`89f02a2`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/89f02a2b4162246dea303a6ee31bb9a550b05c72)
|
||||||
|
- [New] add `path/posix`, `path/win32`, `util/types` [`77f94f1`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/77f94f1e90ffd7c0be2a3f1aa8574ebf7fd981b3)
|
||||||
|
|
||||||
|
## [v2.1.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v2.0.0...v2.1.0) - 2020-11-04
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- [Dev Deps] update `eslint` [`5e0034e`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/5e0034eae57c09c8f1bd769f502486a00f56c6e4)
|
||||||
|
- [New] Add `diagnostics_channel` [`c2d83d0`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/c2d83d0a0225a1a658945d9bab7036ea347d29ec)
|
||||||
|
|
||||||
|
## [v2.0.0](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v1.0.2...v2.0.0) - 2020-09-29
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- v2 implementation [`865aeb5`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/865aeb5ca0e90248a3dfff5d7622e4751fdeb9cd)
|
||||||
|
- Only apps should have lockfiles [`5a5e660`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/5a5e660d568e37eb44e17fb1ebb12a105205fc2b)
|
||||||
|
- Initial commit for v2 [`5a51524`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/5a51524e06f92adece5fbb138c69b7b9748a2348)
|
||||||
|
- Tests [`116eae4`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/116eae4fccd01bc72c1fd3cc4b7561c387afc496)
|
||||||
|
- [meta] add `auto-changelog` [`c24388b`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/c24388bee828d223040519d1f5b226ca35beee63)
|
||||||
|
- [actions] add "Automatic Rebase" and "require allow edits" actions [`34292db`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/34292dbcbadae0868aff03c22dbd8b7b8a11558a)
|
||||||
|
- [Tests] add `npm run lint` [`4f9eeee`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/4f9eeee7ddff10698bbf528620f4dc8d4fa3e697)
|
||||||
|
- [readme] fix travis badges, https all URLs [`e516a73`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/e516a73b0dccce20938c432b1ba512eae8eff9e9)
|
||||||
|
- [meta] create FUNDING.yml [`1aabebc`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/1aabebca98d01f8a04e46bc2e2520fa93cf21ac6)
|
||||||
|
- [Fix] `domain`: domain landed sometime > v0.7.7 and <= v0.7.12 [`2df7d37`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/2df7d37595d41b15eeada732b706b926c2771655)
|
||||||
|
- [Fix] `sys`: worked in 0.6, not 0.7, and 0.8+ [`a75c134`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/a75c134229e1e9441801f6b73f6a52489346eb65)
|
||||||
|
|
||||||
|
## [v1.0.2](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v1.0.1...v1.0.2) - 2014-09-28
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- simpler [`66fe90f`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/66fe90f9771581b9adc0c3900baa52c21b5baea2)
|
||||||
|
|
||||||
|
## [v1.0.1](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/compare/v1.0.0...v1.0.1) - 2014-09-28
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- remove stupid [`f21f906`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/f21f906f882c2bd656a5fc5ed6fbe48ddaffb2ac)
|
||||||
|
- update readme [`1eff0ec`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/1eff0ec69798d1ec65771552d1562911e90a8027)
|
||||||
|
|
||||||
|
## v1.0.0 - 2014-09-28
|
||||||
|
|
||||||
|
### Commits
|
||||||
|
|
||||||
|
- init [`48e5e76`](https://github.com/inspect-js/is-core-module.git
|
||||||
|
/commit/48e5e76cac378fddb8c1f7d4055b8dfc943d6b96)
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2014 Dave Justice
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
# is-core-module <sup>[![Version Badge][2]][1]</sup>
|
||||||
|
|
||||||
|
[![github actions][actions-image]][actions-url]
|
||||||
|
[![coverage][codecov-image]][codecov-url]
|
||||||
|
[![dependency status][5]][6]
|
||||||
|
[![dev dependency status][7]][8]
|
||||||
|
[![License][license-image]][license-url]
|
||||||
|
[![Downloads][downloads-image]][downloads-url]
|
||||||
|
|
||||||
|
[![npm badge][11]][1]
|
||||||
|
|
||||||
|
Is this specifier a node.js core module? Optionally provide a node version to check; defaults to the current node version.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```js
|
||||||
|
var isCore = require('is-core-module');
|
||||||
|
var assert = require('assert');
|
||||||
|
assert(isCore('fs'));
|
||||||
|
assert(!isCore('butts'));
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tests
|
||||||
|
Clone the repo, `npm install`, and run `npm test`
|
||||||
|
|
||||||
|
[1]: https://npmjs.org/package/is-core-module
|
||||||
|
[2]: https://versionbadg.es/inspect-js/is-core-module.svg
|
||||||
|
[5]: https://david-dm.org/inspect-js/is-core-module.svg
|
||||||
|
[6]: https://david-dm.org/inspect-js/is-core-module
|
||||||
|
[7]: https://david-dm.org/inspect-js/is-core-module/dev-status.svg
|
||||||
|
[8]: https://david-dm.org/inspect-js/is-core-module#info=devDependencies
|
||||||
|
[11]: https://nodei.co/npm/is-core-module.png?downloads=true&stars=true
|
||||||
|
[license-image]: https://img.shields.io/npm/l/is-core-module.svg
|
||||||
|
[license-url]: LICENSE
|
||||||
|
[downloads-image]: https://img.shields.io/npm/dm/is-core-module.svg
|
||||||
|
[downloads-url]: https://npm-stat.com/charts.html?package=is-core-module
|
||||||
|
[codecov-image]: https://codecov.io/gh/inspect-js/is-core-module/branch/main/graphs/badge.svg
|
||||||
|
[codecov-url]: https://app.codecov.io/gh/inspect-js/is-core-module/
|
||||||
|
[actions-image]: https://img.shields.io/github/check-runs/inspect-js/is-core-module/main
|
||||||
|
[actions-url]: https://github.com/inspect-js/is-core-module/actions
|
||||||
+162
@@ -0,0 +1,162 @@
|
|||||||
|
{
|
||||||
|
"assert": true,
|
||||||
|
"node:assert": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"assert/strict": ">= 15",
|
||||||
|
"node:assert/strict": ">= 16",
|
||||||
|
"async_hooks": ">= 8",
|
||||||
|
"node:async_hooks": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"buffer_ieee754": ">= 0.5 && < 0.9.7",
|
||||||
|
"buffer": true,
|
||||||
|
"node:buffer": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"child_process": true,
|
||||||
|
"node:child_process": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"cluster": ">= 0.5",
|
||||||
|
"node:cluster": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"console": true,
|
||||||
|
"node:console": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"constants": true,
|
||||||
|
"node:constants": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"crypto": true,
|
||||||
|
"node:crypto": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"_debug_agent": ">= 1 && < 8",
|
||||||
|
"_debugger": "< 8",
|
||||||
|
"dgram": true,
|
||||||
|
"node:dgram": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"diagnostics_channel": [">= 14.17 && < 15", ">= 15.1"],
|
||||||
|
"node:diagnostics_channel": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"dns": true,
|
||||||
|
"node:dns": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"dns/promises": ">= 15",
|
||||||
|
"node:dns/promises": ">= 16",
|
||||||
|
"domain": ">= 0.7.12",
|
||||||
|
"node:domain": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"events": true,
|
||||||
|
"node:events": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"freelist": "< 6",
|
||||||
|
"fs": true,
|
||||||
|
"node:fs": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"fs/promises": [">= 10 && < 10.1", ">= 14"],
|
||||||
|
"node:fs/promises": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"_http_agent": ">= 0.11.1",
|
||||||
|
"node:_http_agent": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"_http_client": ">= 0.11.1",
|
||||||
|
"node:_http_client": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"_http_common": ">= 0.11.1",
|
||||||
|
"node:_http_common": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"_http_incoming": ">= 0.11.1",
|
||||||
|
"node:_http_incoming": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"_http_outgoing": ">= 0.11.1",
|
||||||
|
"node:_http_outgoing": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"_http_server": ">= 0.11.1",
|
||||||
|
"node:_http_server": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"http": true,
|
||||||
|
"node:http": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"http2": ">= 8.8",
|
||||||
|
"node:http2": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"https": true,
|
||||||
|
"node:https": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"inspector": ">= 8",
|
||||||
|
"node:inspector": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"inspector/promises": [">= 19"],
|
||||||
|
"node:inspector/promises": [">= 19"],
|
||||||
|
"_linklist": "< 8",
|
||||||
|
"module": true,
|
||||||
|
"node:module": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"net": true,
|
||||||
|
"node:net": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"node-inspect/lib/_inspect": ">= 7.6 && < 12",
|
||||||
|
"node-inspect/lib/internal/inspect_client": ">= 7.6 && < 12",
|
||||||
|
"node-inspect/lib/internal/inspect_repl": ">= 7.6 && < 12",
|
||||||
|
"os": true,
|
||||||
|
"node:os": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"path": true,
|
||||||
|
"node:path": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"path/posix": ">= 15.3",
|
||||||
|
"node:path/posix": ">= 16",
|
||||||
|
"path/win32": ">= 15.3",
|
||||||
|
"node:path/win32": ">= 16",
|
||||||
|
"perf_hooks": ">= 8.5",
|
||||||
|
"node:perf_hooks": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"process": ">= 1",
|
||||||
|
"node:process": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"punycode": ">= 0.5",
|
||||||
|
"node:punycode": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"querystring": true,
|
||||||
|
"node:querystring": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"readline": true,
|
||||||
|
"node:readline": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"readline/promises": ">= 17",
|
||||||
|
"node:readline/promises": ">= 17",
|
||||||
|
"repl": true,
|
||||||
|
"node:repl": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"node:sea": [">= 20.12 && < 21", ">= 21.7"],
|
||||||
|
"smalloc": ">= 0.11.5 && < 3",
|
||||||
|
"node:sqlite": [">= 22.13 && < 23", ">= 23.4"],
|
||||||
|
"_stream_duplex": ">= 0.9.4 && < 26",
|
||||||
|
"node:_stream_duplex": [">= 14.18 && < 15", ">= 16 && < 26"],
|
||||||
|
"_stream_transform": ">= 0.9.4 && < 26",
|
||||||
|
"node:_stream_transform": [">= 14.18 && < 15", ">= 16 && < 26"],
|
||||||
|
"_stream_wrap": ">= 1.4.1 && < 26",
|
||||||
|
"node:_stream_wrap": [">= 14.18 && < 15", ">= 16 && < 26"],
|
||||||
|
"_stream_passthrough": ">= 0.9.4 && < 26",
|
||||||
|
"node:_stream_passthrough": [">= 14.18 && < 15", ">= 16 && < 26"],
|
||||||
|
"_stream_readable": ">= 0.9.4 && < 26",
|
||||||
|
"node:_stream_readable": [">= 14.18 && < 15", ">= 16 && < 26"],
|
||||||
|
"_stream_writable": ">= 0.9.4 && < 26",
|
||||||
|
"node:_stream_writable": [">= 14.18 && < 15", ">= 16 && < 26"],
|
||||||
|
"stream": true,
|
||||||
|
"node:stream": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"stream/consumers": ">= 16.7",
|
||||||
|
"node:stream/consumers": ">= 16.7",
|
||||||
|
"stream/promises": ">= 15",
|
||||||
|
"node:stream/promises": ">= 16",
|
||||||
|
"stream/web": ">= 16.5",
|
||||||
|
"node:stream/web": ">= 16.5",
|
||||||
|
"string_decoder": true,
|
||||||
|
"node:string_decoder": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"sys": [">= 0.4 && < 0.7", ">= 0.8"],
|
||||||
|
"node:sys": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"test/reporters": ">= 19.9 && < 20.2",
|
||||||
|
"node:test/reporters": [">= 18.17 && < 19", ">= 19.9", ">= 20"],
|
||||||
|
"test/mock_loader": ">= 22.3 && < 22.7",
|
||||||
|
"node:test/mock_loader": ">= 22.3 && < 22.7",
|
||||||
|
"node:test": [">= 16.17 && < 17", ">= 18"],
|
||||||
|
"timers": true,
|
||||||
|
"node:timers": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"timers/promises": ">= 15",
|
||||||
|
"node:timers/promises": ">= 16",
|
||||||
|
"_tls_common": ">= 0.11.13",
|
||||||
|
"node:_tls_common": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"_tls_legacy": ">= 0.11.3 && < 10",
|
||||||
|
"_tls_wrap": ">= 0.11.3",
|
||||||
|
"node:_tls_wrap": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"tls": true,
|
||||||
|
"node:tls": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"trace_events": ">= 10",
|
||||||
|
"node:trace_events": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"tty": true,
|
||||||
|
"node:tty": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"url": true,
|
||||||
|
"node:url": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"util": true,
|
||||||
|
"node:util": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"util/types": ">= 15.3",
|
||||||
|
"node:util/types": ">= 16",
|
||||||
|
"v8/tools/arguments": ">= 10 && < 12",
|
||||||
|
"v8/tools/codemap": [">= 4.4 && < 5", ">= 5.2 && < 12"],
|
||||||
|
"v8/tools/consarray": [">= 4.4 && < 5", ">= 5.2 && < 12"],
|
||||||
|
"v8/tools/csvparser": [">= 4.4 && < 5", ">= 5.2 && < 12"],
|
||||||
|
"v8/tools/logreader": [">= 4.4 && < 5", ">= 5.2 && < 12"],
|
||||||
|
"v8/tools/profile_view": [">= 4.4 && < 5", ">= 5.2 && < 12"],
|
||||||
|
"v8/tools/splaytree": [">= 4.4 && < 5", ">= 5.2 && < 12"],
|
||||||
|
"v8": ">= 1",
|
||||||
|
"node:v8": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"vm": true,
|
||||||
|
"node:vm": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"wasi": [">= 13.4 && < 13.5", ">= 18.17 && < 19", ">= 20"],
|
||||||
|
"node:wasi": [">= 18.17 && < 19", ">= 20"],
|
||||||
|
"worker_threads": ">= 11.7",
|
||||||
|
"node:worker_threads": [">= 14.18 && < 15", ">= 16"],
|
||||||
|
"zlib": ">= 0.5",
|
||||||
|
"node:zlib": [">= 14.18 && < 15", ">= 16"]
|
||||||
|
}
|
||||||
+69
@@ -0,0 +1,69 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var hasOwn = require('hasown');
|
||||||
|
|
||||||
|
function specifierIncluded(current, specifier) {
|
||||||
|
var nodeParts = current.split('.');
|
||||||
|
var parts = specifier.split(' ');
|
||||||
|
var op = parts.length > 1 ? parts[0] : '=';
|
||||||
|
var versionParts = (parts.length > 1 ? parts[1] : parts[0]).split('.');
|
||||||
|
|
||||||
|
for (var i = 0; i < 3; ++i) {
|
||||||
|
var cur = parseInt(nodeParts[i] || 0, 10);
|
||||||
|
var ver = parseInt(versionParts[i] || 0, 10);
|
||||||
|
if (cur === ver) {
|
||||||
|
continue; // eslint-disable-line no-restricted-syntax, no-continue
|
||||||
|
}
|
||||||
|
if (op === '<') {
|
||||||
|
return cur < ver;
|
||||||
|
}
|
||||||
|
if (op === '>=') {
|
||||||
|
return cur >= ver;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return op === '>=';
|
||||||
|
}
|
||||||
|
|
||||||
|
function matchesRange(current, range) {
|
||||||
|
var specifiers = range.split(/ ?&& ?/);
|
||||||
|
if (specifiers.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < specifiers.length; ++i) {
|
||||||
|
if (!specifierIncluded(current, specifiers[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function versionIncluded(nodeVersion, specifierValue) {
|
||||||
|
if (typeof specifierValue === 'boolean') {
|
||||||
|
return specifierValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var current = typeof nodeVersion === 'undefined'
|
||||||
|
? process.versions && process.versions.node
|
||||||
|
: nodeVersion;
|
||||||
|
|
||||||
|
if (typeof current !== 'string') {
|
||||||
|
throw new TypeError(typeof nodeVersion === 'undefined' ? 'Unable to determine current node version' : 'If provided, a valid node version is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (specifierValue && typeof specifierValue === 'object') {
|
||||||
|
for (var i = 0; i < specifierValue.length; ++i) {
|
||||||
|
if (matchesRange(current, specifierValue[i])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return matchesRange(current, specifierValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = require('./core.json');
|
||||||
|
|
||||||
|
module.exports = function isCore(x, nodeVersion) {
|
||||||
|
return hasOwn(data, x) && versionIncluded(nodeVersion, data[x]);
|
||||||
|
};
|
||||||
+76
@@ -0,0 +1,76 @@
|
|||||||
|
{
|
||||||
|
"name": "is-core-module",
|
||||||
|
"version": "2.16.2",
|
||||||
|
"description": "Is this specifier a node.js core module?",
|
||||||
|
"main": "index.js",
|
||||||
|
"sideEffects": false,
|
||||||
|
"exports": {
|
||||||
|
".": "./index.js",
|
||||||
|
"./package.json": "./package.json"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"prepack": "npmignore --auto --commentLines=autogenerated",
|
||||||
|
"prepublish": "not-in-publish || npm run prepublishOnly",
|
||||||
|
"prepublishOnly": "safe-publish-latest",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"pretest": "npm run lint",
|
||||||
|
"tests-only": "nyc tape 'test/**/*.js'",
|
||||||
|
"test": "npm run tests-only",
|
||||||
|
"posttest": "npx npm@'>=10.2' audit --production",
|
||||||
|
"version": "auto-changelog && git add CHANGELOG.md",
|
||||||
|
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/inspect-js/is-core-module.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"core",
|
||||||
|
"modules",
|
||||||
|
"module",
|
||||||
|
"npm",
|
||||||
|
"node",
|
||||||
|
"dependencies"
|
||||||
|
],
|
||||||
|
"author": "Jordan Harband <ljharb@gmail.com>",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/inspect-js/is-core-module/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/inspect-js/is-core-module",
|
||||||
|
"dependencies": {
|
||||||
|
"hasown": "^2.0.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@ljharb/eslint-config": "^22.2.3",
|
||||||
|
"auto-changelog": "^2.5.0",
|
||||||
|
"encoding": "^0.1.13",
|
||||||
|
"eslint": "^8.57.1",
|
||||||
|
"in-publish": "^2.0.1",
|
||||||
|
"mock-property": "^1.1.0",
|
||||||
|
"npmignore": "^0.3.5",
|
||||||
|
"nyc": "^10.3.2",
|
||||||
|
"safe-publish-latest": "^2.0.0",
|
||||||
|
"semver": "^6.3.1",
|
||||||
|
"tape": "^5.9.0"
|
||||||
|
},
|
||||||
|
"auto-changelog": {
|
||||||
|
"output": "CHANGELOG.md",
|
||||||
|
"template": "keepachangelog",
|
||||||
|
"unreleased": false,
|
||||||
|
"commitLimit": false,
|
||||||
|
"backfillLimit": false,
|
||||||
|
"hideCredit": true
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"ignore": [
|
||||||
|
".github"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
+258
@@ -0,0 +1,258 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var test = require('tape');
|
||||||
|
var keys = require('object-keys');
|
||||||
|
var semver = require('semver');
|
||||||
|
var mockProperty = require('mock-property');
|
||||||
|
|
||||||
|
var isCore = require('../');
|
||||||
|
var data = require('../core.json');
|
||||||
|
|
||||||
|
var supportsNodePrefix = semver.satisfies(process.versions.node, '^14.18 || >= 16', { includePrerelease: true });
|
||||||
|
|
||||||
|
test('core modules', function (t) {
|
||||||
|
t.test('isCore()', function (st) {
|
||||||
|
st.ok(isCore('fs'));
|
||||||
|
st.ok(isCore('net'));
|
||||||
|
st.ok(isCore('http'));
|
||||||
|
|
||||||
|
st.ok(!isCore('seq'));
|
||||||
|
st.ok(!isCore('../'));
|
||||||
|
|
||||||
|
st.ok(!isCore('toString'));
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('core list', function (st) {
|
||||||
|
var cores = keys(data);
|
||||||
|
st.plan(cores.length);
|
||||||
|
|
||||||
|
for (var i = 0; i < cores.length; ++i) {
|
||||||
|
var mod = cores[i];
|
||||||
|
var requireFunc = function () { require(mod); }; // eslint-disable-line no-loop-func
|
||||||
|
if (isCore(mod)) {
|
||||||
|
st.doesNotThrow(requireFunc, mod + ' supported; requiring does not throw');
|
||||||
|
} else {
|
||||||
|
st['throws'](requireFunc, mod + ' not supported; requiring throws');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('core via repl module', { skip: !data.repl }, function (st) {
|
||||||
|
var libs = require('repl')._builtinLibs; // eslint-disable-line no-underscore-dangle
|
||||||
|
if (!libs) {
|
||||||
|
st.skip('repl._builtinLibs does not exist');
|
||||||
|
} else {
|
||||||
|
for (var i = 0; i < libs.length; ++i) {
|
||||||
|
var mod = libs[i];
|
||||||
|
st.ok(data[mod], mod + ' is a core module');
|
||||||
|
st.doesNotThrow(
|
||||||
|
function () { require(mod); }, // eslint-disable-line no-loop-func
|
||||||
|
'requiring ' + mod + ' does not throw'
|
||||||
|
);
|
||||||
|
if (mod.slice(0, 5) !== 'node:') {
|
||||||
|
if (supportsNodePrefix) {
|
||||||
|
st.doesNotThrow(
|
||||||
|
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
|
||||||
|
'requiring node:' + mod + ' does not throw'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
st['throws'](
|
||||||
|
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
|
||||||
|
'requiring node:' + mod + ' throws'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('core via builtinModules list', { skip: !data.module }, function (st) {
|
||||||
|
var Module = require('module');
|
||||||
|
var libs = Module.builtinModules;
|
||||||
|
if (!libs) {
|
||||||
|
st.skip('module.builtinModules does not exist');
|
||||||
|
} else {
|
||||||
|
var excludeList = [
|
||||||
|
'_debug_agent',
|
||||||
|
'v8/tools/tickprocessor-driver',
|
||||||
|
'v8/tools/SourceMap',
|
||||||
|
'v8/tools/tickprocessor',
|
||||||
|
'v8/tools/profile'
|
||||||
|
];
|
||||||
|
|
||||||
|
// see https://github.com/nodejs/node/issues/42785
|
||||||
|
if (semver.satisfies(process.version, '>= 18')) {
|
||||||
|
libs = libs.concat('node:test');
|
||||||
|
}
|
||||||
|
if (semver.satisfies(process.version, '^20.12 || >= 21.7')) {
|
||||||
|
libs = libs.concat('node:sea');
|
||||||
|
}
|
||||||
|
if (semver.satisfies(process.version, '>= 23.4')) {
|
||||||
|
libs = libs.concat('node:sqlite');
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < libs.length; ++i) {
|
||||||
|
var mod = libs[i];
|
||||||
|
if (excludeList.indexOf(mod) === -1) {
|
||||||
|
st.ok(data[mod], mod + ' is a core module');
|
||||||
|
|
||||||
|
if (Module.isBuiltin) {
|
||||||
|
st.ok(Module.isBuiltin(mod), 'module.isBuiltin(' + mod + ') is true');
|
||||||
|
}
|
||||||
|
|
||||||
|
st.doesNotThrow(
|
||||||
|
function () { require(mod); }, // eslint-disable-line no-loop-func
|
||||||
|
'requiring ' + mod + ' does not throw'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (process.getBuiltinModule) {
|
||||||
|
st.equal(
|
||||||
|
process.getBuiltinModule(mod),
|
||||||
|
require(mod),
|
||||||
|
'process.getBuiltinModule(' + mod + ') === require(' + mod + ')'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mod.slice(0, 5) !== 'node:') {
|
||||||
|
if (supportsNodePrefix) {
|
||||||
|
st.doesNotThrow(
|
||||||
|
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
|
||||||
|
'requiring node:' + mod + ' does not throw'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
st['throws'](
|
||||||
|
function () { require('node:' + mod); }, // eslint-disable-line no-loop-func
|
||||||
|
'requiring node:' + mod + ' throws'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('isCore with explicit nodeVersion', function (st) {
|
||||||
|
st.ok(isCore('async_hooks', '8.0.0'), 'async_hooks is core in 8.0.0 (exact match on >= specifier)');
|
||||||
|
st.ok(isCore('buffer_ieee754', '0.5.0'), 'buffer_ieee754 is core in 0.5.0');
|
||||||
|
st.ok(!isCore('buffer_ieee754', '0.9.7'), 'buffer_ieee754 is not core in 0.9.7');
|
||||||
|
st.ok(!isCore('buffer_ieee754', '1.0.0'), 'buffer_ieee754 is not core in 1.0.0');
|
||||||
|
st.ok(isCore('buffer_ieee754', '0.8.0'), 'buffer_ieee754 is core in 0.8.0');
|
||||||
|
|
||||||
|
st['throws'](
|
||||||
|
function () { isCore('async_hooks', null); },
|
||||||
|
TypeError,
|
||||||
|
'isCore with non-string non-undefined nodeVersion throws TypeError'
|
||||||
|
);
|
||||||
|
st['throws'](
|
||||||
|
function () { isCore('async_hooks', 123); },
|
||||||
|
TypeError,
|
||||||
|
'isCore with numeric nodeVersion throws TypeError'
|
||||||
|
);
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('isCore with non-boolean specifier and invalid nodeVersion', function (st) {
|
||||||
|
st['throws'](
|
||||||
|
function () { isCore('async_hooks', null); },
|
||||||
|
TypeError,
|
||||||
|
'isCore with null nodeVersion on non-boolean module throws TypeError'
|
||||||
|
);
|
||||||
|
st['throws'](
|
||||||
|
function () { isCore('async_hooks', 123); },
|
||||||
|
TypeError,
|
||||||
|
'isCore with numeric nodeVersion on non-boolean module throws TypeError'
|
||||||
|
);
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('isCore with undefined nodeVersion and non-string process.versions.node', function (st) {
|
||||||
|
st.teardown(mockProperty(process, 'versions', { value: { node: null } }));
|
||||||
|
|
||||||
|
st['throws'](
|
||||||
|
function () { isCore('async_hooks'); },
|
||||||
|
TypeError,
|
||||||
|
'isCore throws when process.versions.node is not a string'
|
||||||
|
);
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('isCore with undefined nodeVersion and falsy process.versions', function (st) {
|
||||||
|
st.teardown(mockProperty(process, 'versions', { value: null }));
|
||||||
|
|
||||||
|
st['throws'](
|
||||||
|
function () { isCore('async_hooks'); },
|
||||||
|
TypeError,
|
||||||
|
'isCore throws when process.versions is falsy'
|
||||||
|
);
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('specifierIncluded with = operator (bare version)', function (st) {
|
||||||
|
var testKey = '__test_equal_op';
|
||||||
|
data[testKey] = '14.18';
|
||||||
|
st.teardown(function () { delete data[testKey]; });
|
||||||
|
|
||||||
|
st.ok(!isCore(testKey, '14.17.0'), 'returns false when minor version does not match with = op');
|
||||||
|
st.ok(!isCore(testKey, '15.0.0'), 'returns false when major version does not match with = op');
|
||||||
|
st.ok(!isCore(testKey, '14.18.0'), 'returns false for exact match with = op (= is not >=)');
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('isCore with short version strings', function (st) {
|
||||||
|
st.ok(isCore('async_hooks', '8'), 'async_hooks is core with single-part version "8"');
|
||||||
|
st.ok(!isCore('async_hooks', '7'), 'async_hooks is not core with single-part version "7"');
|
||||||
|
st.ok(isCore('cluster', '0.5'), 'cluster is core with two-part version "0.5"');
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('matchesRange with empty specifiers array', function (st) {
|
||||||
|
var testKey = '__test_empty_split';
|
||||||
|
var testRange = '__test_range__';
|
||||||
|
data[testKey] = testRange;
|
||||||
|
st.teardown(function () { delete data[testKey]; });
|
||||||
|
|
||||||
|
var origSplit = String.prototype.split;
|
||||||
|
st.teardown(mockProperty(String.prototype, 'split', {
|
||||||
|
value: function () {
|
||||||
|
if (String(this) === testRange) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return origSplit.apply(this, arguments);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
st.ok(!isCore(testKey, '8.0.0'), 'returns false when specifiers array is empty');
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.test('Object.prototype pollution', function (st) {
|
||||||
|
var nonKey = 'not a core module';
|
||||||
|
st.teardown(mockProperty(Object.prototype, 'fs', { value: false }));
|
||||||
|
st.teardown(mockProperty(Object.prototype, 'path', { value: '>= 999999999' }));
|
||||||
|
st.teardown(mockProperty(Object.prototype, 'http', { value: data.http }));
|
||||||
|
st.teardown(mockProperty(Object.prototype, nonKey, { value: true }));
|
||||||
|
|
||||||
|
st.equal(isCore('fs'), true, 'fs is a core module even if Object.prototype lies');
|
||||||
|
st.equal(isCore('path'), true, 'path is a core module even if Object.prototype lies');
|
||||||
|
st.equal(isCore('http'), true, 'path is a core module even if Object.prototype matches data');
|
||||||
|
st.equal(isCore(nonKey), false, '"' + nonKey + '" is not a core module even if Object.prototype lies');
|
||||||
|
|
||||||
|
st.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
# Nano ID
|
||||||
|
|
||||||
|
<img src="https://ai.github.io/nanoid/logo.svg" align="right"
|
||||||
|
alt="Nano ID logo by Anton Lovchikov" width="180" height="94">
|
||||||
|
|
||||||
|
**English** | [Русский](./README.ru.md) | [简体中文](./README.zh-CN.md) | [Bahasa Indonesia](./README.id-ID.md)
|
||||||
|
|
||||||
|
A tiny, secure, URL-friendly, unique string ID generator for JavaScript.
|
||||||
|
|
||||||
|
> “An amazing level of senseless perfectionism,
|
||||||
|
> which is simply impossible not to respect.”
|
||||||
|
|
||||||
|
* **Small.** 130 bytes (minified and gzipped). No dependencies.
|
||||||
|
[Size Limit] controls the size.
|
||||||
|
* **Fast.** It is 2 times faster than UUID.
|
||||||
|
* **Safe.** It uses hardware random generator. Can be used in clusters.
|
||||||
|
* **Short IDs.** It uses a larger alphabet than UUID (`A-Za-z0-9_-`).
|
||||||
|
So ID size was reduced from 36 to 21 symbols.
|
||||||
|
* **Portable.** Nano ID was ported
|
||||||
|
to [20 programming languages](#other-programming-languages).
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { nanoid } from 'nanoid'
|
||||||
|
model.id = nanoid() //=> "V1StGXR8_Z5jdHi6B-myT"
|
||||||
|
```
|
||||||
|
|
||||||
|
Supports modern browsers, IE [with Babel], Node.js and React Native.
|
||||||
|
|
||||||
|
[online tool]: https://gitpod.io/#https://github.com/ai/nanoid/
|
||||||
|
[with Babel]: https://developer.epages.com/blog/coding/how-to-transpile-node-modules-with-babel-and-webpack-in-a-monorepo/
|
||||||
|
[Size Limit]: https://github.com/ai/size-limit
|
||||||
|
|
||||||
|
<a href="https://evilmartians.com/?utm_source=nanoid">
|
||||||
|
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg"
|
||||||
|
alt="Sponsored by Evil Martians" width="236" height="54">
|
||||||
|
</a>
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
||||||
|
|
||||||
|
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||||
|
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
||||||
|
|
||||||
|
return async (size = defaultSize) => {
|
||||||
|
let id = ''
|
||||||
|
while (true) {
|
||||||
|
let bytes = crypto.getRandomValues(new Uint8Array(step))
|
||||||
|
let i = step | 0
|
||||||
|
while (i--) {
|
||||||
|
id += alphabet[bytes[i] & mask] || ''
|
||||||
|
if (id.length === size) return id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let nanoid = async (size = 21) => {
|
||||||
|
let id = ''
|
||||||
|
let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))
|
||||||
|
|
||||||
|
while (size--) {
|
||||||
|
let byte = bytes[size] & 63
|
||||||
|
if (byte < 36) {
|
||||||
|
id += byte.toString(36)
|
||||||
|
} else if (byte < 62) {
|
||||||
|
id += (byte - 26).toString(36).toUpperCase()
|
||||||
|
} else if (byte < 63) {
|
||||||
|
id += '_'
|
||||||
|
} else {
|
||||||
|
id += '-'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { nanoid, customAlphabet, random }
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
||||||
|
|
||||||
|
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||||
|
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
||||||
|
|
||||||
|
return async (size = defaultSize) => {
|
||||||
|
let id = ''
|
||||||
|
while (true) {
|
||||||
|
let bytes = crypto.getRandomValues(new Uint8Array(step))
|
||||||
|
let i = step | 0
|
||||||
|
while (i--) {
|
||||||
|
id += alphabet[bytes[i] & mask] || ''
|
||||||
|
if (id.length === size) return id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let nanoid = async (size = 21) => {
|
||||||
|
let id = ''
|
||||||
|
let bytes = crypto.getRandomValues(new Uint8Array((size |= 0)))
|
||||||
|
|
||||||
|
while (size--) {
|
||||||
|
let byte = bytes[size] & 63
|
||||||
|
if (byte < 36) {
|
||||||
|
id += byte.toString(36)
|
||||||
|
} else if (byte < 62) {
|
||||||
|
id += (byte - 26).toString(36).toUpperCase()
|
||||||
|
} else if (byte < 63) {
|
||||||
|
id += '_'
|
||||||
|
} else {
|
||||||
|
id += '-'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
export { nanoid, customAlphabet, random }
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
let crypto = require('crypto')
|
||||||
|
|
||||||
|
let { urlAlphabet } = require('../url-alphabet/index.cjs')
|
||||||
|
|
||||||
|
let random = bytes =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err)
|
||||||
|
} else {
|
||||||
|
resolve(buf)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||||
|
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
||||||
|
|
||||||
|
|
||||||
|
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
||||||
|
|
||||||
|
let tick = (id, size = defaultSize) =>
|
||||||
|
random(step).then(bytes => {
|
||||||
|
let i = step
|
||||||
|
while (i--) {
|
||||||
|
id += alphabet[bytes[i] & mask] || ''
|
||||||
|
if (id.length >= size) return id
|
||||||
|
}
|
||||||
|
return tick(id, size)
|
||||||
|
})
|
||||||
|
|
||||||
|
return size => tick('', size)
|
||||||
|
}
|
||||||
|
|
||||||
|
let nanoid = (size = 21) =>
|
||||||
|
random((size |= 0)).then(bytes => {
|
||||||
|
let id = ''
|
||||||
|
while (size--) {
|
||||||
|
id += urlAlphabet[bytes[size] & 63]
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = { nanoid, customAlphabet, random }
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* Generate secure URL-friendly unique ID. The non-blocking version.
|
||||||
|
*
|
||||||
|
* By default, the ID will have 21 symbols to have a collision probability
|
||||||
|
* similar to UUID v4.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* import { nanoid } from 'nanoid/async'
|
||||||
|
* nanoid().then(id => {
|
||||||
|
* model.id = id
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param size Size of the ID. The default size is 21.
|
||||||
|
* @returns A promise with a random string.
|
||||||
|
*/
|
||||||
|
export function nanoid(size?: number): Promise<string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A low-level function.
|
||||||
|
* Generate secure unique ID with custom alphabet. The non-blocking version.
|
||||||
|
*
|
||||||
|
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||||
|
* will not be secure.
|
||||||
|
*
|
||||||
|
* @param alphabet Alphabet used to generate the ID.
|
||||||
|
* @param defaultSize Size of the ID. The default size is 21.
|
||||||
|
* @returns A function that returns a promise with a random string.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* import { customAlphabet } from 'nanoid/async'
|
||||||
|
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
||||||
|
* nanoid().then(id => {
|
||||||
|
* model.id = id //=> "8ё56а"
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export function customAlphabet(
|
||||||
|
alphabet: string,
|
||||||
|
defaultSize?: number
|
||||||
|
): (size?: number) => Promise<string>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an array of random bytes collected from hardware noise.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* import { random } from 'nanoid/async'
|
||||||
|
* random(5).then(bytes => {
|
||||||
|
* bytes //=> [10, 67, 212, 67, 89]
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param bytes Size of the array.
|
||||||
|
* @returns A promise with a random bytes array.
|
||||||
|
*/
|
||||||
|
export function random(bytes: number): Promise<Uint8Array>
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
import crypto from 'crypto'
|
||||||
|
|
||||||
|
import { urlAlphabet } from '../url-alphabet/index.js'
|
||||||
|
|
||||||
|
let random = bytes =>
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err)
|
||||||
|
} else {
|
||||||
|
resolve(buf)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||||
|
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
||||||
|
|
||||||
|
|
||||||
|
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
||||||
|
|
||||||
|
let tick = (id, size = defaultSize) =>
|
||||||
|
random(step).then(bytes => {
|
||||||
|
let i = step
|
||||||
|
while (i--) {
|
||||||
|
id += alphabet[bytes[i] & mask] || ''
|
||||||
|
if (id.length >= size) return id
|
||||||
|
}
|
||||||
|
return tick(id, size)
|
||||||
|
})
|
||||||
|
|
||||||
|
return size => tick('', size)
|
||||||
|
}
|
||||||
|
|
||||||
|
let nanoid = (size = 21) =>
|
||||||
|
random((size |= 0)).then(bytes => {
|
||||||
|
let id = ''
|
||||||
|
while (size--) {
|
||||||
|
id += urlAlphabet[bytes[size] & 63]
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
})
|
||||||
|
|
||||||
|
export { nanoid, customAlphabet, random }
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
import { getRandomBytesAsync } from 'expo-random'
|
||||||
|
|
||||||
|
import { urlAlphabet } from '../url-alphabet/index.js'
|
||||||
|
|
||||||
|
let random = getRandomBytesAsync
|
||||||
|
|
||||||
|
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||||
|
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
||||||
|
|
||||||
|
|
||||||
|
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
||||||
|
|
||||||
|
let tick = (id, size = defaultSize) =>
|
||||||
|
random(step).then(bytes => {
|
||||||
|
let i = step
|
||||||
|
while (i--) {
|
||||||
|
id += alphabet[bytes[i] & mask] || ''
|
||||||
|
if (id.length >= size) return id
|
||||||
|
}
|
||||||
|
return tick(id, size)
|
||||||
|
})
|
||||||
|
|
||||||
|
return size => tick('', size)
|
||||||
|
}
|
||||||
|
|
||||||
|
let nanoid = (size = 21) =>
|
||||||
|
random((size |= 0)).then(bytes => {
|
||||||
|
let id = ''
|
||||||
|
while (size--) {
|
||||||
|
id += urlAlphabet[bytes[size] & 63]
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
})
|
||||||
|
|
||||||
|
export { nanoid, customAlphabet, random }
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"type": "module",
|
||||||
|
"main": "index.cjs",
|
||||||
|
"module": "index.js",
|
||||||
|
"react-native": {
|
||||||
|
"./index.js": "./index.native.js"
|
||||||
|
},
|
||||||
|
"browser": {
|
||||||
|
"./index.js": "./index.browser.js",
|
||||||
|
"./index.cjs": "./index.browser.cjs"
|
||||||
|
}
|
||||||
|
}
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
let { urlAlphabet } = require('./url-alphabet/index.cjs')
|
||||||
|
|
||||||
|
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
||||||
|
|
||||||
|
let customRandom = (alphabet, defaultSize, getRandom) => {
|
||||||
|
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
||||||
|
|
||||||
|
return (size = defaultSize) => {
|
||||||
|
let id = ''
|
||||||
|
while (true) {
|
||||||
|
let bytes = getRandom(step)
|
||||||
|
let j = step | 0
|
||||||
|
while (j--) {
|
||||||
|
id += alphabet[bytes[j] & mask] || ''
|
||||||
|
if (id.length === size) return id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let customAlphabet = (alphabet, size = 21) =>
|
||||||
|
customRandom(alphabet, size, random)
|
||||||
|
|
||||||
|
let nanoid = (size = 21) =>
|
||||||
|
crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
||||||
|
byte &= 63
|
||||||
|
if (byte < 36) {
|
||||||
|
id += byte.toString(36)
|
||||||
|
} else if (byte < 62) {
|
||||||
|
id += (byte - 26).toString(36).toUpperCase()
|
||||||
|
} else if (byte > 62) {
|
||||||
|
id += '-'
|
||||||
|
} else {
|
||||||
|
id += '_'
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}, '')
|
||||||
|
|
||||||
|
module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|
||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
|
||||||
|
import { urlAlphabet } from './url-alphabet/index.js'
|
||||||
|
|
||||||
|
let random = bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
||||||
|
|
||||||
|
let customRandom = (alphabet, defaultSize, getRandom) => {
|
||||||
|
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
||||||
|
|
||||||
|
return (size = defaultSize) => {
|
||||||
|
let id = ''
|
||||||
|
while (true) {
|
||||||
|
let bytes = getRandom(step)
|
||||||
|
let j = step | 0
|
||||||
|
while (j--) {
|
||||||
|
id += alphabet[bytes[j] & mask] || ''
|
||||||
|
if (id.length === size) return id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let customAlphabet = (alphabet, size = 21) =>
|
||||||
|
customRandom(alphabet, size, random)
|
||||||
|
|
||||||
|
let nanoid = (size = 21) =>
|
||||||
|
crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => {
|
||||||
|
byte &= 63
|
||||||
|
if (byte < 36) {
|
||||||
|
id += byte.toString(36)
|
||||||
|
} else if (byte < 62) {
|
||||||
|
id += (byte - 26).toString(36).toUpperCase()
|
||||||
|
} else if (byte > 62) {
|
||||||
|
id += '-'
|
||||||
|
} else {
|
||||||
|
id += '_'
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}, '')
|
||||||
|
|
||||||
|
export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|
||||||
+57
@@ -0,0 +1,57 @@
|
|||||||
|
let crypto = require('crypto')
|
||||||
|
|
||||||
|
let { urlAlphabet } = require('./url-alphabet/index.cjs')
|
||||||
|
|
||||||
|
const POOL_SIZE_MULTIPLIER = 128
|
||||||
|
let pool, poolOffset
|
||||||
|
|
||||||
|
let fillPool = bytes => {
|
||||||
|
if (bytes < 0 || bytes > 1024) throw new RangeError('Wrong ID size')
|
||||||
|
if (!pool || pool.length < bytes) {
|
||||||
|
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)
|
||||||
|
crypto.randomFillSync(pool)
|
||||||
|
poolOffset = 0
|
||||||
|
} else if (poolOffset + bytes > pool.length) {
|
||||||
|
crypto.randomFillSync(pool)
|
||||||
|
poolOffset = 0
|
||||||
|
}
|
||||||
|
poolOffset += bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
let random = bytes => {
|
||||||
|
fillPool((bytes |= 0))
|
||||||
|
return pool.subarray(poolOffset - bytes, poolOffset)
|
||||||
|
}
|
||||||
|
|
||||||
|
let customRandom = (alphabet, defaultSize, getRandom) => {
|
||||||
|
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
||||||
|
|
||||||
|
|
||||||
|
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
||||||
|
|
||||||
|
return (size = defaultSize) => {
|
||||||
|
let id = ''
|
||||||
|
while (true) {
|
||||||
|
let bytes = getRandom(step)
|
||||||
|
let i = step
|
||||||
|
while (i--) {
|
||||||
|
id += alphabet[bytes[i] & mask] || ''
|
||||||
|
if (id.length === size) return id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let customAlphabet = (alphabet, size = 21) =>
|
||||||
|
customRandom(alphabet, size, random)
|
||||||
|
|
||||||
|
let nanoid = (size = 21) => {
|
||||||
|
fillPool((size |= 0))
|
||||||
|
let id = ''
|
||||||
|
for (let i = poolOffset - size; i < poolOffset; i++) {
|
||||||
|
id += urlAlphabet[pool[i] & 63]
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|
||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
/**
|
||||||
|
* Generate secure URL-friendly unique ID.
|
||||||
|
*
|
||||||
|
* By default, the ID will have 21 symbols to have a collision probability
|
||||||
|
* similar to UUID v4.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* import { nanoid } from 'nanoid'
|
||||||
|
* model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param size Size of the ID. The default size is 21.
|
||||||
|
* @returns A random string.
|
||||||
|
*/
|
||||||
|
export function nanoid(size?: number): string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate secure unique ID with custom alphabet.
|
||||||
|
*
|
||||||
|
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||||
|
* will not be secure.
|
||||||
|
*
|
||||||
|
* @param alphabet Alphabet used to generate the ID.
|
||||||
|
* @param defaultSize Size of the ID. The default size is 21.
|
||||||
|
* @returns A random string generator.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const { customAlphabet } = require('nanoid')
|
||||||
|
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
||||||
|
* nanoid() //=> "8ё56а"
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export function customAlphabet(
|
||||||
|
alphabet: string,
|
||||||
|
defaultSize?: number
|
||||||
|
): (size?: number) => string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate unique ID with custom random generator and alphabet.
|
||||||
|
*
|
||||||
|
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||||
|
* will not be secure.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* import { customRandom } from 'nanoid/format'
|
||||||
|
*
|
||||||
|
* const nanoid = customRandom('abcdef', 5, size => {
|
||||||
|
* const random = []
|
||||||
|
* for (let i = 0; i < size; i++) {
|
||||||
|
* random.push(randomByte())
|
||||||
|
* }
|
||||||
|
* return random
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* nanoid() //=> "fbaef"
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param alphabet Alphabet used to generate a random string.
|
||||||
|
* @param size Size of the random string.
|
||||||
|
* @param random A random bytes generator.
|
||||||
|
* @returns A random string generator.
|
||||||
|
*/
|
||||||
|
export function customRandom(
|
||||||
|
alphabet: string,
|
||||||
|
size: number,
|
||||||
|
random: (bytes: number) => Uint8Array
|
||||||
|
): () => string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL safe symbols.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* import { urlAlphabet } from 'nanoid'
|
||||||
|
* const nanoid = customAlphabet(urlAlphabet, 10)
|
||||||
|
* nanoid() //=> "Uakgb_J5m9"
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export const urlAlphabet: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an array of random bytes collected from hardware noise.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* import { customRandom, random } from 'nanoid'
|
||||||
|
* const nanoid = customRandom("abcdef", 5, random)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param bytes Size of the array.
|
||||||
|
* @returns An array of random bytes.
|
||||||
|
*/
|
||||||
|
export function random(bytes: number): Uint8Array
|
||||||
+91
@@ -0,0 +1,91 @@
|
|||||||
|
/**
|
||||||
|
* Generate secure URL-friendly unique ID.
|
||||||
|
*
|
||||||
|
* By default, the ID will have 21 symbols to have a collision probability
|
||||||
|
* similar to UUID v4.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* import { nanoid } from 'nanoid'
|
||||||
|
* model.id = nanoid() //=> "Uakgb_J5m9g-0JDMbcJqL"
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param size Size of the ID. The default size is 21.
|
||||||
|
* @returns A random string.
|
||||||
|
*/
|
||||||
|
export function nanoid(size?: number): string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate secure unique ID with custom alphabet.
|
||||||
|
*
|
||||||
|
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||||
|
* will not be secure.
|
||||||
|
*
|
||||||
|
* @param alphabet Alphabet used to generate the ID.
|
||||||
|
* @param defaultSize Size of the ID. The default size is 21.
|
||||||
|
* @returns A random string generator.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* const { customAlphabet } = require('nanoid')
|
||||||
|
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
||||||
|
* nanoid() //=> "8ё56а"
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export function customAlphabet(
|
||||||
|
alphabet: string,
|
||||||
|
defaultSize?: number
|
||||||
|
): (size?: number) => string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate unique ID with custom random generator and alphabet.
|
||||||
|
*
|
||||||
|
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
||||||
|
* will not be secure.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* import { customRandom } from 'nanoid/format'
|
||||||
|
*
|
||||||
|
* const nanoid = customRandom('abcdef', 5, size => {
|
||||||
|
* const random = []
|
||||||
|
* for (let i = 0; i < size; i++) {
|
||||||
|
* random.push(randomByte())
|
||||||
|
* }
|
||||||
|
* return random
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* nanoid() //=> "fbaef"
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param alphabet Alphabet used to generate a random string.
|
||||||
|
* @param size Size of the random string.
|
||||||
|
* @param random A random bytes generator.
|
||||||
|
* @returns A random string generator.
|
||||||
|
*/
|
||||||
|
export function customRandom(
|
||||||
|
alphabet: string,
|
||||||
|
size: number,
|
||||||
|
random: (bytes: number) => Uint8Array
|
||||||
|
): () => string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL safe symbols.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* import { urlAlphabet } from 'nanoid'
|
||||||
|
* const nanoid = customAlphabet(urlAlphabet, 10)
|
||||||
|
* nanoid() //=> "Uakgb_J5m9"
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
export const urlAlphabet: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate an array of random bytes collected from hardware noise.
|
||||||
|
*
|
||||||
|
* ```js
|
||||||
|
* import { customRandom, random } from 'nanoid'
|
||||||
|
* const nanoid = customRandom("abcdef", 5, random)
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* @param bytes Size of the array.
|
||||||
|
* @returns An array of random bytes.
|
||||||
|
*/
|
||||||
|
export function random(bytes: number): Uint8Array
|
||||||
+62
@@ -0,0 +1,62 @@
|
|||||||
|
import crypto from 'crypto'
|
||||||
|
|
||||||
|
import { urlAlphabet } from './url-alphabet/index.js'
|
||||||
|
|
||||||
|
const POOL_SIZE_MULTIPLIER = 128
|
||||||
|
let pool, poolOffset
|
||||||
|
|
||||||
|
let fillPool = bytes => {
|
||||||
|
if (bytes < 0) throw new RangeError('Wrong ID size')
|
||||||
|
try {
|
||||||
|
if (!pool || pool.length < bytes) {
|
||||||
|
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER)
|
||||||
|
crypto.randomFillSync(pool)
|
||||||
|
poolOffset = 0
|
||||||
|
} else if (poolOffset + bytes > pool.length) {
|
||||||
|
crypto.randomFillSync(pool)
|
||||||
|
poolOffset = 0
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
pool = undefined
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
poolOffset += bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
let random = bytes => {
|
||||||
|
fillPool((bytes |= 0))
|
||||||
|
return pool.subarray(poolOffset - bytes, poolOffset)
|
||||||
|
}
|
||||||
|
|
||||||
|
let customRandom = (alphabet, defaultSize, getRandom) => {
|
||||||
|
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
||||||
|
|
||||||
|
|
||||||
|
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
||||||
|
|
||||||
|
return (size = defaultSize) => {
|
||||||
|
let id = ''
|
||||||
|
while (true) {
|
||||||
|
let bytes = getRandom(step)
|
||||||
|
let i = step
|
||||||
|
while (i--) {
|
||||||
|
id += alphabet[bytes[i] & mask] || ''
|
||||||
|
if (id.length === size) return id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let customAlphabet = (alphabet, size = 21) =>
|
||||||
|
customRandom(alphabet, size, random)
|
||||||
|
|
||||||
|
let nanoid = (size = 21) => {
|
||||||
|
fillPool((size |= 0))
|
||||||
|
let id = ''
|
||||||
|
for (let i = poolOffset - size; i < poolOffset; i++) {
|
||||||
|
id += urlAlphabet[pool[i] & 63]
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
export { nanoid, customAlphabet, customRandom, urlAlphabet, random }
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export let nanoid=(t=21)=>crypto.getRandomValues(new Uint8Array(t)).reduce(((t,e)=>t+=(e&=63)<36?e.toString(36):e<62?(e-26).toString(36).toUpperCase():e<63?"_":"-"),"");
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
let urlAlphabet =
|
||||||
|
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict'
|
||||||
|
|
||||||
|
let customAlphabet = (alphabet, defaultSize = 21) => {
|
||||||
|
return (size = defaultSize) => {
|
||||||
|
let id = ''
|
||||||
|
let i = size | 0
|
||||||
|
while (i--) {
|
||||||
|
id += alphabet[(Math.random() * alphabet.length) | 0]
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let nanoid = (size = 21) => {
|
||||||
|
let id = ''
|
||||||
|
let i = size | 0
|
||||||
|
while (i--) {
|
||||||
|
id += urlAlphabet[(Math.random() * 64) | 0]
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { nanoid, customAlphabet }
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user