aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-08 22:36:52 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-08 22:36:52 -0700
commit0b52f9210a2c85d3dcc61365d910cdf45996a693 (patch)
tree8ed62434922a936aa51fd91e49ef3942e993ea3e /src/bun.js
parent69ea6fd54f8b2777334e1472bd5509301a49954c (diff)
downloadbun-0b52f9210a2c85d3dcc61365d910cdf45996a693.tar.gz
bun-0b52f9210a2c85d3dcc61365d910cdf45996a693.tar.zst
bun-0b52f9210a2c85d3dcc61365d910cdf45996a693.zip
Add a couple helpers
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/bindings/bindings.zig13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index f64c13a22..cc1df0b0d 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 {