ddf-time-utils
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -8,5 +8,5 @@ export declare const YEAR_TYPE: unique symbol; | ||
export declare const TIME_TYPES_AS_STRINGS: string[]; | ||
export declare const TIME_TYPES_DDF_COMPATIBLE: string[]; | ||
export declare function detectTimeType(timeQuery: any): symbol; | ||
export declare function getTimeRange(query: any): true[]; | ||
export declare const TIME_TYPES_DDF_COMPATIBLE: any; | ||
export declare function detectTimeType(timeQuery: any): any; | ||
export declare function getTimeRange(query: any): any; | ||
export declare function parseTime(timeString: any): { | ||
@@ -13,0 +13,0 @@ type: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const lodash_1 = require("lodash"); | ||
const uniq = require("lodash/uniq"); | ||
const head = require("lodash/head"); | ||
const isString = require("lodash/isString"); | ||
const isArray = require("lodash/isArray"); | ||
const compact = require("lodash/compact"); | ||
const flatten = require("lodash/flatten"); | ||
const concat = require("lodash/concat"); | ||
const range = require("lodash/range"); | ||
const moment_1 = require("moment"); | ||
@@ -51,3 +58,3 @@ const TWO_DIGITS_MIN_NUMBER = 10; | ||
exports.TIME_TYPES_AS_STRINGS = exports.TIME_TYPES.map(Symbol.keyFor); | ||
exports.TIME_TYPES_DDF_COMPATIBLE = lodash_1.concat('time', exports.TIME_TYPES_AS_STRINGS.map(key => key.replace(/_TYPE/, '').toLowerCase())); | ||
exports.TIME_TYPES_DDF_COMPATIBLE = concat('time', exports.TIME_TYPES_AS_STRINGS.map(key => key.replace(/_TYPE/, '').toLowerCase())); | ||
function extractLocalTimeRange(type) { | ||
@@ -72,6 +79,6 @@ function parse(option) { | ||
} | ||
lodash_1.range(startYear, endYear + 1).forEach(year => { | ||
range(startYear, endYear + 1).forEach(year => { | ||
const startValue = year === startYear ? startSecondMatch : settings.minLimit; | ||
const endValue = year === endYear ? endSecondMatch : settings.maxLimit; | ||
lodash_1.range(startValue, endValue + 1).forEach(valueParam => { | ||
range(startValue, endValue + 1).forEach(valueParam => { | ||
const value = isZeroAppendNeeded(valueParam) ? `0${valueParam}` : valueParam; | ||
@@ -88,3 +95,3 @@ result.push(year + settings.divider + value); | ||
const fYear = Number(parsed.end[0]); | ||
return lodash_1.range(sYear, fYear + 1) | ||
return range(sYear, fYear + 1) | ||
.map(year => `${year}`); | ||
@@ -104,10 +111,10 @@ }, | ||
const endDay = Number(parsed.end[THIRD_ELEMENT]); | ||
lodash_1.range(startYear, endYear + 1).forEach(year => { | ||
range(startYear, endYear + 1).forEach(year => { | ||
const currentStartMonth = year === startYear ? startMonth : 1; | ||
const currentEndMonth = year === endYear ? endMonth : MAX_MONTH; | ||
lodash_1.range(currentStartMonth, currentEndMonth + 1).forEach(month => { | ||
range(currentStartMonth, currentEndMonth + 1).forEach(month => { | ||
const monthStr = month < TWO_DIGITS_MIN_NUMBER ? `0${month}` : month; | ||
const currentStartDay = year === startYear && month === currentStartMonth ? startDay : 1; | ||
const currentEndDay = year === endYear && month === currentEndMonth ? endDay : MAX_DAY; | ||
lodash_1.range(currentStartDay, currentEndDay + 1).forEach(day => { | ||
range(currentStartDay, currentEndDay + 1).forEach(day => { | ||
const dayStr = day < TWO_DIGITS_MIN_NUMBER ? `0${day}` : day; | ||
@@ -124,7 +131,7 @@ result.push(`${year}${monthStr}${dayStr}`); | ||
function detectTimeType(timeQuery) { | ||
const plainTimeQuery = lodash_1.isArray(timeQuery) ? lodash_1.flatten(timeQuery) : [timeQuery]; | ||
const timeTypes = lodash_1.uniq(lodash_1.flatten(plainTimeQuery | ||
const plainTimeQuery = isArray(timeQuery) ? flatten(timeQuery) : [timeQuery]; | ||
const timeTypes = uniq(flatten(plainTimeQuery | ||
.map(queryDetail => Object.getOwnPropertySymbols(TIME_TYPE_PATTERNS) | ||
.filter(type => TIME_TYPE_PATTERNS[type].regularExp.test(queryDetail))))); | ||
return timeTypes.length === 1 ? lodash_1.head(timeTypes) : null; | ||
return timeTypes.length === 1 ? head(timeTypes) : null; | ||
} | ||
@@ -140,6 +147,6 @@ exports.detectTimeType = detectTimeType; | ||
let result = null; | ||
if (lodash_1.isString(option)) { | ||
if (isString(option)) { | ||
result = option; | ||
} | ||
if (lodash_1.isArray(option)) { | ||
if (isArray(option)) { | ||
result = extractor(option); | ||
@@ -149,3 +156,3 @@ } | ||
} | ||
return lodash_1.compact(lodash_1.flatten(query.map(option => getTimeByQueryType(option)))); | ||
return compact(flatten(query.map(option => getTimeByQueryType(option)))); | ||
} | ||
@@ -152,0 +159,0 @@ exports.getTimeRange = getTimeRange; |
{ | ||
"name": "ddf-time-utils", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Gapminder DDF time utils", | ||
@@ -37,3 +37,2 @@ "main": "./lib/index.js", | ||
"devDependencies": { | ||
"@types/lodash": "4.14.85", | ||
"@types/moment": "2.13.0", | ||
@@ -40,0 +39,0 @@ "@types/node": "10.3.1", |
@@ -13,4 +13,3 @@ { | ||
"mocha", | ||
"chai", | ||
"lodash" | ||
"chai" | ||
] | ||
@@ -17,0 +16,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
64827
18
214