Internal utility functions shared across Vue.js packages for DOM manipulation, type checking, and general utilities
npx @tessl/cli install tessl/npm-vue--shared@3.5.0Vue Shared is the foundational utility library used internally across all Vue.js packages. It provides a comprehensive collection of utilities for DOM manipulation, type checking, reactive system optimizations, string transformations, and general-purpose functions. These utilities ensure consistent behavior and reduce code duplication across Vue's compiler, reactivity system, runtime, and other core packages.
npm install @vue/sharedimport {
isString, isObject, isFunction, extend, hasOwn,
PatchFlags, ShapeFlags, SlotFlags,
makeMap, camelize, hyphenate, capitalize,
escapeHtml, normalizeClass, normalizeStyle
} from "@vue/shared";For CommonJS:
const {
isString, isObject, isFunction, extend, hasOwn,
PatchFlags, ShapeFlags, SlotFlags,
makeMap, camelize, hyphenate, capitalize,
escapeHtml, normalizeClass, normalizeStyle
} = require("@vue/shared");import {
isString, isObject, extend, camelize,
normalizeClass, escapeHtml, PatchFlags
} from "@vue/shared";
// Type checking
if (isString(value)) {
console.log("It's a string:", value);
}
if (isObject(data)) {
const merged = extend({}, data, { newProp: "value" });
}
// String transformations
const camelCase = camelize("kebab-case-string"); // "kebabCaseString"
const kebabCase = hyphenate("camelCaseString"); // "camel-case-string"
// Class normalization
const classes = normalizeClass(["btn", { active: true }, "btn-primary"]);
// "btn active btn-primary"
// HTML escaping
const safe = escapeHtml('<script>alert("xss")</script>');
// "<script>alert("xss")</script>"
// Using optimization flags
const patchFlag = PatchFlags.TEXT | PatchFlags.CLASS;
if (patchFlag & PatchFlags.TEXT) {
// Handle text content updates
}Vue Shared is organized around several key functional areas:
Comprehensive type guards and validation utilities for runtime type checking and safe property access.
function isString(val: unknown): val is string;
function isObject(val: unknown): val is Record<any, any>;
function isFunction(val: unknown): val is Function;
function isArray(val: unknown): val is any[];
function hasOwn(val: object, key: string | symbol): key is keyof typeof val;Cached string transformation utilities for converting between naming conventions and manipulating text.
function camelize(str: string): string;
function hyphenate(str: string): string;
function capitalize<T extends string>(str: T): Capitalize<T>;
function toHandlerKey<T extends string>(str: T): T extends '' ? '' : `on${Capitalize<T>}`;Bitwise optimization flags used by Vue's compiler and runtime for efficient rendering and reactivity tracking.
enum PatchFlags {
TEXT = 1,
CLASS = 2,
STYLE = 4,
PROPS = 8,
// ... more flags
}
enum ShapeFlags {
ELEMENT = 1,
FUNCTIONAL_COMPONENT = 2,
STATEFUL_COMPONENT = 4,
// ... more flags
}Validation utilities for HTML, SVG, and MathML elements and attributes, used by Vue's compiler for proper DOM handling.
function isHTMLTag(key: string): boolean;
function isSVGTag(key: string): boolean;
function isBooleanAttr(key: string): boolean;
function isVoidTag(key: string): boolean;Utilities for normalizing component props, CSS styles, and class names into standardized formats.
function normalizeClass(value: unknown): string;
function normalizeStyle(value: unknown): NormalizedStyle | string | undefined;
function normalizeProps(props: Record<string, any> | null): Record<string, any> | null;
type NormalizedStyle = Record<string, string | number>;HTML escaping and sanitization utilities for preventing XSS attacks and ensuring safe rendering.
function escapeHtml(string: unknown): string;
function escapeHtmlComment(src: string): string;
function getEscapedCssVarName(key: string, doubleEscape: boolean): string;General-purpose utilities for object manipulation, array operations, and data structure handling.
const extend: typeof Object.assign;
function remove<T>(arr: T[], el: T): void;
function def(obj: object, key: string | symbol, value: any, writable?: boolean): void;
function hasChanged(value: any, oldValue: any): boolean;Deep equality checking and comparison utilities with special handling for complex data types.
function looseEqual(a: any, b: any): boolean;
function looseIndexOf(arr: any[], val: any): number;Utilities for converting values to display strings and formatting data for user presentation.
function toDisplayString(val: unknown): string;
function generateCodeFrame(source: string, start?: number, end?: number): string;Cross-environment utilities for accessing global objects and handling platform differences.
function getGlobalThis(): any;
function isGloballyAllowed(key: string): boolean;Internal utilities used by Vue's compiler for code generation and caching.
function genPropsAccessExp(name: string): string;
function genCacheKey(source: string, options: any): string;const EMPTY_OBJ: { readonly [key: string]: any };
const EMPTY_ARR: readonly never[];
const NOOP: () => void;
const NO: () => false;function isReservedProp(key: string): boolean;
function isBuiltInDirective(key: string): boolean;
function isOn(key: string): boolean;
function isModelListener(key: string): key is `onUpdate:${string}`;Advanced TypeScript utility types for type manipulation and generic programming.
type Prettify<T> = { [K in keyof T]: T[K] } & {};
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
type LooseRequired<T> = { [P in keyof (T & Required<T>)]: T[P] };
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
type IsKeyValues<T, K = string> = IfAny<T, false, T extends object ? (keyof T extends K ? true : false) : false>;
type OverloadParameters<T extends (...args: any[]) => any> = Parameters<OverloadUnion<T>>;