PHP 8.2.30
Preview: string-utils.js Size: 1.51 KB
/home/byroehnu/easepaybiz.easetack.com/node_modules/eslint/lib/shared/string-utils.js

/**
 * @fileoverview Utilities to operate on strings.
 * @author Stephen Wade
 */

"use strict";

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

// eslint-disable-next-line no-control-regex -- intentionally including control characters
const ASCII_REGEX = /^[\u0000-\u007f]*$/u;

/** @type {Intl.Segmenter | undefined} */
let segmenter;

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------

/**
 * Converts the first letter of a string to uppercase.
 * @param {string} string The string to operate on
 * @returns {string} The converted string
 */
function upperCaseFirst(string) {
	if (string.length <= 1) {
		return string.toUpperCase();
	}
	return string[0].toUpperCase() + string.slice(1);
}

/**
 * Counts graphemes in a given string.
 * @param {string} value A string to count graphemes.
 * @returns {number} The number of graphemes in `value`.
 */
function getGraphemeCount(value) {
	if (ASCII_REGEX.test(value)) {
		return value.length;
	}

	segmenter ??= new Intl.Segmenter("en-US"); // en-US locale should be supported everywhere
	let graphemeCount = 0;

	// eslint-disable-next-line no-unused-vars -- for-of needs a variable
	for (const unused of segmenter.segment(value)) {
		graphemeCount++;
	}

	return graphemeCount;
}

module.exports = {
	upperCaseFirst,
	getGraphemeCount,
};

Directory Contents

Dirs: 0 × Files: 19

Name Size Perms Modified Actions
127 B lr--r--r-- 2026-03-14 01:49:12
Edit Download
931 B lrw-r--r-- 2026-03-05 00:20:01
Edit Download
524 B lrw-r--r-- 2026-03-05 00:20:10
Edit Download
897 B lrw-r--r-- 2026-03-05 00:20:11
Edit Download
1.54 KB lrw-r--r-- 2026-03-05 00:20:16
Edit Download
413 B lrw-r--r-- 2026-03-05 00:20:17
Edit Download
2.27 KB lrw-r--r-- 2026-03-05 00:20:18
Edit Download
635 B lrw-r--r-- 2026-03-05 00:20:21
Edit Download
2.88 KB lrw-r--r-- 2026-03-05 00:20:21
Edit Download
1.24 KB lrw-r--r-- 2026-03-05 00:20:24
Edit Download
1.00 KB lrw-r--r-- 2026-03-05 00:20:24
Edit Download
5.02 KB lrw-r--r-- 2026-03-05 00:20:24
Edit Download
2.06 KB lrw-r--r-- 2026-03-05 00:20:24
Edit Download
1.15 KB lrw-r--r-- 2026-03-05 00:20:24
Edit Download
638 B lrw-r--r-- 2026-03-05 00:20:24
Edit Download
1.51 KB lrw-r--r-- 2026-03-05 00:20:24
Edit Download
2.16 KB lrw-r--r-- 2026-03-05 00:20:24
Edit Download
5.88 KB lrw-r--r-- 2026-03-05 00:20:24
Edit Download
4.74 KB lrw-r--r-- 2026-03-05 00:20:24
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).