recoder-code
Version:
π AI-powered development platform - Chat with 32+ models, build projects, automate workflows. Free models included!
96 lines β’ 2.33 kB
JavaScript
var formatDistanceLocale = {
lessThanXSeconds: {
one: '1γ³γγγΏγΎγ',
other: '{{count}}γ³γγγΏγΎγ',
oneWithSuffix: 'γγ1γ³γγ',
otherWithSuffix: 'γγ{{count}}γ³γγ'
},
xSeconds: {
one: '1γ³γγ',
other: '{{count}}γ³γγ'
},
halfAMinute: '30γ³γγ',
lessThanXMinutes: {
one: '1γ·γγΏγΎγ',
other: '{{count}}γ΅γγΏγΎγ',
oneWithSuffix: 'γγ1γ·γ',
otherWithSuffix: 'γγ{{count}}γ΅γ'
},
xMinutes: {
one: '1γ·γ',
other: '{{count}}γ΅γ'
},
aboutXHours: {
one: 'γγ1γγγ',
other: 'γγ{{count}}γγγ'
},
xHours: {
one: '1γγγ',
other: '{{count}}γγγ'
},
xDays: {
one: '1γ«γ‘',
other: '{{count}}γ«γ‘'
},
aboutXWeeks: {
one: 'γγ1γγ
γγγ',
other: 'γγ{{count}}γγ
γγγ'
},
xWeeks: {
one: '1γγ
γγγ',
other: '{{count}}γγ
γγγ'
},
aboutXMonths: {
one: 'γγ1γγγ€',
other: 'γγ{{count}}γγγ€'
},
xMonths: {
one: '1γγγ€',
other: '{{count}}γγγ€'
},
aboutXYears: {
one: 'γγ1γγ',
other: 'γγ{{count}}γγ'
},
xYears: {
one: '1γγ',
other: '{{count}}γγ'
},
overXYears: {
one: '1γγγγγγ',
other: '{{count}}γγγγγγ'
},
almostXYears: {
one: '1γγγ‘γγ',
other: '{{count}}γγγ‘γγ'
}
};
var formatDistance = function formatDistance(token, count, options) {
options = options || {};
var result;
var tokenValue = formatDistanceLocale[token];
if (typeof tokenValue === 'string') {
result = tokenValue;
} else if (count === 1) {
if (options.addSuffix && tokenValue.oneWithSuffix) {
result = tokenValue.oneWithSuffix;
} else {
result = tokenValue.one;
}
} else {
if (options.addSuffix && tokenValue.otherWithSuffix) {
result = tokenValue.otherWithSuffix.replace('{{count}}', String(count));
} else {
result = tokenValue.other.replace('{{count}}', String(count));
}
}
if (options.addSuffix) {
if (options.comparison && options.comparison > 0) {
return result + 'γγ¨';
} else {
return result + 'γΎγ';
}
}
return result;
};
export default formatDistance;