UNPKG

aws-ddk-core

Version:

The AWS DataOps Development Kit is an open source development framework for customers that build data workflows and modern data architecture on AWS.

43 lines (39 loc) 1.41 kB
'use strict'; var stringifyNumber = require('../../stringify/stringifyNumber.js'); const intIdentify = (value) => typeof value === 'bigint' || Number.isInteger(value); const intResolve = (str, offset, radix, { intAsBigInt }) => (intAsBigInt ? BigInt(str) : parseInt(str.substring(offset), radix)); function intStringify(node, radix, prefix) { const { value } = node; if (intIdentify(value) && value >= 0) return prefix + value.toString(radix); return stringifyNumber.stringifyNumber(node); } const intOct = { identify: value => intIdentify(value) && value >= 0, default: true, tag: 'tag:yaml.org,2002:int', format: 'OCT', test: /^0o[0-7]+$/, resolve: (str, _onError, opt) => intResolve(str, 2, 8, opt), stringify: node => intStringify(node, 8, '0o') }; const int = { identify: intIdentify, default: true, tag: 'tag:yaml.org,2002:int', test: /^[-+]?[0-9]+$/, resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt), stringify: stringifyNumber.stringifyNumber }; const intHex = { identify: value => intIdentify(value) && value >= 0, default: true, tag: 'tag:yaml.org,2002:int', format: 'HEX', test: /^0x[0-9a-fA-F]+$/, resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt), stringify: node => intStringify(node, 16, '0x') }; exports.int = int; exports.intHex = intHex; exports.intOct = intOct;