test( 'should format absolute URLs as path-absolute URLs', () => { expect( format( 'http://example.com/', 'PATH_ABSOLUTE' ) ).toBe( '/' ); expect( format( 'http://example.com:8080/', 'PATH_ABSOLUTE' ) ).toBe( '/' ); expect( format( 'http://www.example.com', 'PATH_ABSOLUTE' ) ).toBe( '/' ); expect( format( 'http://example.com/foo?b=a#z', 'PATH_ABSOLUTE' ) ).toBe( '/foo?b=a#z' ); } );
function formatDate (value, args = {}) { if (Object.keys(args).length) { const { format, locale = 'en' } = args return moment .utc(toString(value), ISO_8601_FORMAT, true) .locale(locale) .format(format) } return toString(value) }
function set(labels) { return value => { if (typeof value !== 'number') { throw new TypeError(`Value is not a valid number: ${util.format(value)}`); } labels = labels || {}; validateLabel(this.labelNames, labels); this.hashMap = setValue(this.hashMap, value, labels); }; }
async getUser(userID): Promise<User> { const cacheKey = util.format(this.cacheKeys.user, userID); const userStr = await this.client.get(cacheKey); if (!userStr) { return null; } const user = JSON.parse(userStr); return user; }
[...new Array(7)] .map((_, day) => format(setDay(new Date(), day), 'iii')) .map(d => ( <Day key={d}>{d}</Day> ))
const formatFilter = filter => { const { name, value } = filter; if (value._isAMomentObject === true) { return { ...filter, value: moment(value).format() }; } if (name === 'size') { return { ...filter, value: unformatBytes(value) }; } return filter; }
function log(text) { if(typeof(text)=="object") { text=JSON.stringify(text).replace(/\s/g," "); } root.output+="["+moment().format("YYYY-MM-DD HH:mm:ss")+"]"+text+"<br>"; }
async setUserToken(userID: number, token: string) { const cacheKey = util.format(this.cacheKeys.userToken, userID); const tokenMaxAge: number = this.configService.server.tokenMaxAge; return await this.client.set(cacheKey, token, 'EX', Math.floor(tokenMaxAge / 1000)); }
// format a parsed object into a url string /* istanbul ignore next: improve coverage */ function urlFormat(obj) { // ensure it's an object, and not a string url. // If it's an obj, this is a no-op. // this way, you can call url_format() on strings // to clean up potentially wonky urls. if (typeof obj === 'string') obj = urlParse(obj);else if (typeof obj !== 'object' || obj === null) throw new TypeError('Parameter "urlObj" must be an object, not ' + obj === null ? 'null' : typeof obj);else if (!(obj instanceof Url)) return Url.prototype.format.call(obj); return obj.format(); }
it(`must ignore internal spaces`, () => { expect(pgp.as.format(`\${ one },$( two ),$[ three ],$< four >,$/ five /`, { one: 1, two: 2, three: 3, four: 4, five: 5 })).toBe(`1,2,3,4,5`); });
test( 'should format scheme-relative URLs as path-absolute URLs', () => { expect( format( '//example.com/', 'PATH_ABSOLUTE' ) ).toBe( '/' ); expect( format( '//example.com:8080/', 'PATH_ABSOLUTE' ) ).toBe( '/' ); expect( format( '//www.example.com', 'PATH_ABSOLUTE' ) ).toBe( '/' ); expect( format( '//example.com/foo?b=a#z', 'PATH_ABSOLUTE' ) ).toBe( '/foo?b=a#z' ); expect( format( '//example.com/foo/bar/../baz', 'PATH_ABSOLUTE' ) ).toBe( '/foo/baz' ); } );