Download wp-calypso/client/reader/id-helpers.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 554 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/reader/id-helpers.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/reader/id-helpers.js
-
curl -L -o id-helpers.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/reader/id-helpers.js
554 Bytes
| /** | |
| * Convert a string or number to valid reader ID | |
| * @param {string|number} val The value to convert | |
| * @returns {number|undefined} A valid ID or undefined if we could not convert val | |
| */ | |
| export function toValidId( val ) { | |
| const valType = typeof val; | |
| if ( valType === 'string' && /^\d+$/.test( val ) ) { | |
| const v = Number( val ); | |
| return v === 0 ? undefined : v; | |
| } | |
| if ( valType === 'number' ) { | |
| if ( val === 0 || isNaN( val ) || ! isFinite( val ) || val !== Math.floor( val ) ) { | |
| return undefined; | |
| } | |
| return val; | |
| } | |
| return undefined; | |
| } | |