From 0b52f9210a2c85d3dcc61365d910cdf45996a693 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Mon, 8 May 2023 22:36:52 -0700 Subject: [PATCH] Add a couple helpers --- src/bun.js/bindings/bindings.zig | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index f64c13a22c..cc1df0b0d0 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -214,6 +214,17 @@ pub const ZigString = extern struct { return ZigString__toJSONObject(&this, globalThis); } + pub fn hasPrefixChar(this: ZigString, char: u8) bool { + if (this.len == 0) + return false; + + if (this.is16Bit()) { + return this.utf16SliceAligned()[0] == char; + } + + return this.slice()[0] == char; + } + pub fn substring(this: ZigString, offset: usize, maxlen: usize) ZigString { var len: usize = undefined; if (maxlen == 0) { @@ -3997,7 +4008,7 @@ pub const JSValue = enum(JSValueReprInt) { } pub fn toEnum(this: JSValue, globalThis: *JSGlobalObject, comptime property_name: []const u8, comptime Enum: type) !Enum { - return toEnumWithMapField(this, globalThis, property_name, Enum, "Map"); + return toEnumFromMap(this, globalThis, property_name, Enum, Enum.Map); } pub fn toOptionalEnum(this: JSValue, globalThis: *JSGlobalObject, comptime property_name: []const u8, comptime Enum: type) !?Enum {