PHP's ctype_graph in TypeScript

✓ Verified: PHP 8.3
Examples tested against actual runtime. CI re-verifies continuously. Only documented examples are tested.

How to use

Install via yarn add locutus and import: import { ctype_graph } from 'locutus/php/ctype/ctype_graph'.

Or with CommonJS: const { ctype_graph } = require('locutus/php/ctype/ctype_graph')

Use a bundler that supports tree-shaking so you only ship the functions you actually use. Vite, webpack, Rollup, and Parcel all handle this. For server-side use this is less of a concern.

Examples

These examples are extracted from test cases that automatically verify our functions against their native counterparts.

#codeexpected result
1ctype_graph('!%')true

Dependencies

This function uses the following Locutus functions:

Here's what our current TypeScript equivalent to PHP's ctype_graph looks like.

import { getCtypePattern } from '../_helpers/_ctypePattern.ts'
import { setlocale } from '../strings/setlocale.ts'

export function ctype_graph(text: string): boolean {
// discuss at: https://locutus.io/php/ctype_graph/
// parity verified: PHP 8.3
// original by: Brett Zamir (https://brett-zamir.me)
// example 1: ctype_graph('!%')
// returns 1: true

if (typeof text !== 'string') {
return false
}

setlocale('LC_ALL', 0)

const pattern = getCtypePattern('gr')
return pattern instanceof RegExp ? pattern.test(text) : false
}

Improve this function

Locutus is a community effort following The McDonald's Theory: we ship first iterations, hoping others will improve them. If you see something that could be better, we'd love your contribution.

View on GitHub · Edit on GitHub · View Raw


« More PHP ctype functions


Star