@formatjs/intl-utils
Advanced tools
Comparing version 1.4.4 to 1.5.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.5.0](https://github.com/formatjs/formatjs/compare/@formatjs/intl-utils@1.4.4...@formatjs/intl-utils@1.5.0) (2019-12-01) | ||
### Features | ||
* **@formatjs/intl-utils:** add PartitionPattern abstract operation ([#317](https://github.com/formatjs/formatjs/issues/317)) ([5731fcf](https://github.com/formatjs/formatjs/commit/5731fcfeaaba65322f904e863faead8d1f177a98)) | ||
## [1.4.4](https://github.com/formatjs/formatjs/compare/@formatjs/intl-utils@1.4.3...@formatjs/intl-utils@1.4.4) (2019-11-26) | ||
@@ -8,0 +19,0 @@ |
export { selectUnit } from './diff'; | ||
export { toObject, getOption, getAliasesByLang, getParentLocalesByLang, setInternalSlot, getInternalSlot, } from './polyfill-utils'; | ||
export { toObject, getOption, getAliasesByLang, getParentLocalesByLang, setInternalSlot, getInternalSlot, partitionPattern, isLiteralPart, LiteralPart, } from './polyfill-utils'; | ||
export { createResolveLocale, getLocaleHierarchy, supportedLocales, unpackData, isMissingLocaleDataError, } from './resolve-locale'; | ||
@@ -4,0 +4,0 @@ export { SANCTIONED_UNITS } from './constants'; |
@@ -12,2 +12,4 @@ "use strict"; | ||
exports.getInternalSlot = polyfill_utils_1.getInternalSlot; | ||
exports.partitionPattern = polyfill_utils_1.partitionPattern; | ||
exports.isLiteralPart = polyfill_utils_1.isLiteralPart; | ||
var resolve_locale_1 = require("./resolve-locale"); | ||
@@ -14,0 +16,0 @@ exports.createResolveLocale = resolve_locale_1.createResolveLocale; |
@@ -19,1 +19,16 @@ /** | ||
export declare function getInternalSlot<Instance extends object, Internal, Field extends keyof Internal>(map: WeakMap<Instance, Internal>, pl: Instance, field: Field): Internal[Field]; | ||
export interface LiteralPart { | ||
type: 'literal'; | ||
value: string; | ||
} | ||
export declare function isLiteralPart(patternPart: LiteralPart | { | ||
type: string; | ||
value?: string; | ||
}): patternPart is LiteralPart; | ||
export declare function partitionPattern(pattern: string): ({ | ||
type: string; | ||
value: string; | ||
} | { | ||
type: string; | ||
value: undefined; | ||
})[]; |
@@ -5,2 +5,3 @@ "use strict"; | ||
var parentLocales_1 = require("./parentLocales"); | ||
var invariant_1 = require("./invariant"); | ||
/** | ||
@@ -80,1 +81,36 @@ * https://tc39.es/ecma262/#sec-toobject | ||
exports.getInternalSlot = getInternalSlot; | ||
function isLiteralPart(patternPart) { | ||
return patternPart.type === 'literal'; | ||
} | ||
exports.isLiteralPart = isLiteralPart; | ||
function partitionPattern(pattern) { | ||
var result = []; | ||
var beginIndex = pattern.indexOf('{'); | ||
var endIndex = 0; | ||
var nextIndex = 0; | ||
var length = pattern.length; | ||
while (beginIndex < pattern.length && beginIndex > -1) { | ||
endIndex = pattern.indexOf('}', beginIndex); | ||
invariant_1.invariant(endIndex > beginIndex, "Invalid pattern " + pattern); | ||
if (beginIndex > nextIndex) { | ||
result.push({ | ||
type: 'literal', | ||
value: pattern.substring(nextIndex, beginIndex), | ||
}); | ||
} | ||
result.push({ | ||
type: pattern.substring(beginIndex + 1, endIndex), | ||
value: undefined, | ||
}); | ||
nextIndex = endIndex + 1; | ||
beginIndex = pattern.indexOf('{', nextIndex); | ||
} | ||
if (nextIndex < length) { | ||
result.push({ | ||
type: 'literal', | ||
value: pattern.substring(nextIndex, length), | ||
}); | ||
} | ||
return result; | ||
} | ||
exports.partitionPattern = partitionPattern; |
export { selectUnit } from './diff'; | ||
export { toObject, getOption, getAliasesByLang, getParentLocalesByLang, setInternalSlot, getInternalSlot, } from './polyfill-utils'; | ||
export { toObject, getOption, getAliasesByLang, getParentLocalesByLang, setInternalSlot, getInternalSlot, partitionPattern, isLiteralPart, LiteralPart, } from './polyfill-utils'; | ||
export { createResolveLocale, getLocaleHierarchy, supportedLocales, unpackData, isMissingLocaleDataError, } from './resolve-locale'; | ||
@@ -4,0 +4,0 @@ export { SANCTIONED_UNITS } from './constants'; |
export { selectUnit } from './diff'; | ||
export { toObject, getOption, getAliasesByLang, getParentLocalesByLang, setInternalSlot, getInternalSlot, } from './polyfill-utils'; | ||
export { toObject, getOption, getAliasesByLang, getParentLocalesByLang, setInternalSlot, getInternalSlot, partitionPattern, isLiteralPart, } from './polyfill-utils'; | ||
export { createResolveLocale, getLocaleHierarchy, supportedLocales, unpackData, isMissingLocaleDataError, } from './resolve-locale'; | ||
@@ -4,0 +4,0 @@ export { SANCTIONED_UNITS } from './constants'; |
@@ -47,2 +47,7 @@ | ||
export declare function isLiteralPart(patternPart: LiteralPart | { | ||
type: string; | ||
value?: string; | ||
}): patternPart is LiteralPart; | ||
export declare function isMissingLocaleDataError(e: Error): e is MissingLocaleDataError; | ||
@@ -73,2 +78,7 @@ | ||
export declare interface LiteralPart { | ||
type: 'literal'; | ||
value: string; | ||
} | ||
declare type Locale = string; | ||
@@ -93,2 +103,10 @@ | ||
export declare function partitionPattern(pattern: string): ({ | ||
type: string; | ||
value: string; | ||
} | { | ||
type: string; | ||
value: undefined; | ||
})[]; | ||
export declare interface PluralRulesData { | ||
@@ -95,0 +113,0 @@ categories: { |
@@ -19,1 +19,16 @@ /** | ||
export declare function getInternalSlot<Instance extends object, Internal, Field extends keyof Internal>(map: WeakMap<Instance, Internal>, pl: Instance, field: Field): Internal[Field]; | ||
export interface LiteralPart { | ||
type: 'literal'; | ||
value: string; | ||
} | ||
export declare function isLiteralPart(patternPart: LiteralPart | { | ||
type: string; | ||
value?: string; | ||
}): patternPart is LiteralPart; | ||
export declare function partitionPattern(pattern: string): ({ | ||
type: string; | ||
value: string; | ||
} | { | ||
type: string; | ||
value: undefined; | ||
})[]; |
import aliases from './aliases'; | ||
import parentLocales from './parentLocales'; | ||
import { invariant } from './invariant'; | ||
/** | ||
@@ -71,1 +72,34 @@ * https://tc39.es/ecma262/#sec-toobject | ||
} | ||
export function isLiteralPart(patternPart) { | ||
return patternPart.type === 'literal'; | ||
} | ||
export function partitionPattern(pattern) { | ||
var result = []; | ||
var beginIndex = pattern.indexOf('{'); | ||
var endIndex = 0; | ||
var nextIndex = 0; | ||
var length = pattern.length; | ||
while (beginIndex < pattern.length && beginIndex > -1) { | ||
endIndex = pattern.indexOf('}', beginIndex); | ||
invariant(endIndex > beginIndex, "Invalid pattern " + pattern); | ||
if (beginIndex > nextIndex) { | ||
result.push({ | ||
type: 'literal', | ||
value: pattern.substring(nextIndex, beginIndex), | ||
}); | ||
} | ||
result.push({ | ||
type: pattern.substring(beginIndex + 1, endIndex), | ||
value: undefined, | ||
}); | ||
nextIndex = endIndex + 1; | ||
beginIndex = pattern.indexOf('{', nextIndex); | ||
} | ||
if (nextIndex < length) { | ||
result.push({ | ||
type: 'literal', | ||
value: pattern.substring(nextIndex, length), | ||
}); | ||
} | ||
return result; | ||
} |
{ | ||
"name": "@formatjs/intl-utils", | ||
"version": "1.4.4", | ||
"version": "1.5.0", | ||
"description": "Smartly determine best unit for relative time format", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
"license": "MIT", | ||
"gitHead": "6d6aa5ccec18f2f04be72a6e510193c0a1210725" | ||
"gitHead": "3ea32d0792af5e0757bede58b8b6235202ea74f2" | ||
} |
@@ -9,2 +9,5 @@ export {selectUnit} from './diff'; | ||
getInternalSlot, | ||
partitionPattern, | ||
isLiteralPart, | ||
LiteralPart, | ||
} from './polyfill-utils'; | ||
@@ -11,0 +14,0 @@ export { |
import aliases from './aliases'; | ||
import parentLocales from './parentLocales'; | ||
import {invariant} from './invariant'; | ||
@@ -105,1 +106,43 @@ /** | ||
} | ||
export interface LiteralPart { | ||
type: 'literal'; | ||
value: string; | ||
} | ||
export function isLiteralPart( | ||
patternPart: LiteralPart | {type: string; value?: string} | ||
): patternPart is LiteralPart { | ||
return patternPart.type === 'literal'; | ||
} | ||
export function partitionPattern(pattern: string) { | ||
const result = []; | ||
let beginIndex = pattern.indexOf('{'); | ||
let endIndex = 0; | ||
let nextIndex = 0; | ||
const length = pattern.length; | ||
while (beginIndex < pattern.length && beginIndex > -1) { | ||
endIndex = pattern.indexOf('}', beginIndex); | ||
invariant(endIndex > beginIndex, `Invalid pattern ${pattern}`); | ||
if (beginIndex > nextIndex) { | ||
result.push({ | ||
type: 'literal', | ||
value: pattern.substring(nextIndex, beginIndex), | ||
}); | ||
} | ||
result.push({ | ||
type: pattern.substring(beginIndex + 1, endIndex), | ||
value: undefined, | ||
}); | ||
nextIndex = endIndex + 1; | ||
beginIndex = pattern.indexOf('{', nextIndex); | ||
} | ||
if (nextIndex < length) { | ||
result.push({ | ||
type: 'literal', | ||
value: pattern.substring(nextIndex, length), | ||
}); | ||
} | ||
return result; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138428
3510