@odigos/ui-kit 0.0.9 → 0.0.11-1.patch-dev.361

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (563) hide show
  1. package/.devcontainer/README.md +26 -0
  2. package/.devcontainer/devcontainer.json +21 -0
  3. package/CHANGELOG.md +862 -0
  4. package/README.md +3 -2
  5. package/VERSIONING.md +228 -0
  6. package/lib/chunks/ui-components-f51830d4.js +1605 -0
  7. package/lib/chunks/vendor-1dea551d.js +1 -0
  8. package/lib/components/auto-complete-input/index.d.ts +3 -0
  9. package/lib/components/badge/index.d.ts +2 -2
  10. package/lib/components/code/index.d.ts +1 -1
  11. package/lib/components/data-card/data-card-fields/index.d.ts +19 -19
  12. package/lib/components/data-card/index.d.ts +8 -6
  13. package/lib/components/data-finger/index.d.ts +12 -0
  14. package/lib/components/data-tab/index.d.ts +25 -10
  15. package/lib/components/delete-warning/index.d.ts +2 -2
  16. package/lib/components/describe-row/index.d.ts +2 -2
  17. package/lib/components/divider/index.d.ts +3 -2
  18. package/lib/components/drawer/drawer-footer/index.d.ts +3 -0
  19. package/lib/components/drawer/drawer-header/index.d.ts +7 -5
  20. package/lib/components/drawer/index.d.ts +2 -2
  21. package/lib/components/dropdown/index.d.ts +6 -2
  22. package/lib/components/error-boundary/index.d.ts +1 -2
  23. package/lib/components/field-error/index.d.ts +1 -2
  24. package/lib/components/field-label/index.d.ts +2 -0
  25. package/lib/components/icon-button/index.d.ts +2 -0
  26. package/lib/components/icon-group/index.d.ts +3 -2
  27. package/lib/components/icon-wrapped/index.d.ts +2 -2
  28. package/lib/components/index.d.ts +56 -48
  29. package/lib/components/input/index.d.ts +2 -1
  30. package/lib/components/input-table/index.d.ts +4 -11
  31. package/lib/components/input-table/map-columns-to-fields/index.d.ts +15 -0
  32. package/lib/components/input-table/types.d.ts +15 -0
  33. package/lib/components/interactive-table/index.d.ts +9 -8
  34. package/lib/components/interactive-table/table-row.d.ts +13 -0
  35. package/lib/components/key-value-input-list/index.d.ts +4 -0
  36. package/lib/components/monitors-checkboxes/index.d.ts +4 -4
  37. package/lib/components/monitors-icons/index.d.ts +2 -2
  38. package/lib/components/notification-note/index.d.ts +3 -2
  39. package/lib/components/popup/index.d.ts +18 -0
  40. package/lib/components/popup-form/index.d.ts +18 -0
  41. package/lib/components/scroll-x/index.d.ts +10 -0
  42. package/lib/components/segment/index.d.ts +8 -6
  43. package/lib/{containers/data-flow-actions-menu → components}/selection-button/index.d.ts +3 -3
  44. package/lib/components/status/index.d.ts +8 -5
  45. package/lib/components/stepper/index.d.ts +2 -1
  46. package/lib/components/styled.d.ts +33 -2
  47. package/lib/components/tab-list/index.d.ts +17 -0
  48. package/lib/components/tag/index.d.ts +9 -0
  49. package/lib/components/text/index.d.ts +16 -3
  50. package/lib/components/toggle/index.d.ts +2 -1
  51. package/lib/components/warning-modal/index.d.ts +2 -2
  52. package/lib/components.js +1 -173
  53. package/lib/constants/destinations/index.d.ts +18 -0
  54. package/lib/constants/index.d.ts +2 -0
  55. package/lib/constants/sources/index.d.ts +4 -0
  56. package/lib/constants/strings/index.d.ts +90 -0
  57. package/lib/constants.js +1 -13
  58. package/lib/containers/action-drawer/build-card.d.ts +1 -7
  59. package/lib/containers/action-drawer/index.d.ts +2 -2
  60. package/lib/containers/action-form/custom-fields/add-cluster-info.d.ts +2 -2
  61. package/lib/containers/action-form/custom-fields/delete-attributes.d.ts +2 -2
  62. package/lib/containers/action-form/custom-fields/error-sampler.d.ts +2 -2
  63. package/lib/containers/action-form/custom-fields/index.d.ts +3 -3
  64. package/lib/containers/action-form/custom-fields/k8s-attributes.d.ts +2 -2
  65. package/lib/containers/action-form/custom-fields/latency-sampler.d.ts +2 -2
  66. package/lib/containers/action-form/custom-fields/pii-masking.d.ts +2 -2
  67. package/lib/containers/action-form/custom-fields/probabilistic-sampler.d.ts +2 -2
  68. package/lib/containers/action-form/custom-fields/rename-attributes.d.ts +2 -2
  69. package/lib/containers/action-form/custom-fields/service-name-sampler.d.ts +5 -0
  70. package/lib/containers/action-form/custom-fields/span-attribute-sampler.d.ts +5 -0
  71. package/lib/containers/await-pipeline/index.d.ts +1 -2
  72. package/lib/containers/data-flow/helpers/build-action-nodes.d.ts +7 -1
  73. package/lib/containers/data-flow/helpers/build-destination-nodes.d.ts +7 -1
  74. package/lib/containers/data-flow/helpers/build-edges.d.ts +2 -2
  75. package/lib/containers/data-flow/helpers/build-rule-nodes.d.ts +7 -1
  76. package/lib/containers/data-flow/helpers/get-node-positions.d.ts +2 -2
  77. package/lib/containers/data-flow/index.d.ts +2 -2
  78. package/lib/containers/data-flow-actions-menu/add-entity/index.d.ts +2 -3
  79. package/lib/containers/data-flow-actions-menu/data-stream-select/index.d.ts +9 -0
  80. package/lib/containers/data-flow-actions-menu/filters/index.d.ts +2 -8
  81. package/lib/containers/data-flow-actions-menu/index.d.ts +5 -6
  82. package/lib/containers/data-flow-actions-menu/search/index.d.ts +3 -2
  83. package/lib/containers/data-flow-actions-menu/search/search-results/builder.d.ts +3 -3
  84. package/lib/containers/data-flow-actions-menu/search/search-results/index.d.ts +0 -1
  85. package/lib/containers/data-flow-actions-menu/styled.d.ts +5 -1
  86. package/lib/containers/data-stream-drawer/index.d.ts +10 -0
  87. package/lib/containers/data-stream-form/index.d.ts +9 -0
  88. package/lib/containers/data-stream-modal/index.d.ts +4 -0
  89. package/lib/containers/data-stream-selection-form/index.d.ts +13 -0
  90. package/lib/containers/destination-drawer/build-card.d.ts +1 -7
  91. package/lib/containers/destination-drawer/index.d.ts +2 -5
  92. package/lib/containers/destination-form/dynamic-fields/index.d.ts +2 -1
  93. package/lib/containers/destination-form/index.d.ts +2 -5
  94. package/lib/containers/destination-form/test-connection/index.d.ts +5 -10
  95. package/lib/containers/destination-modal/choose-destination/destinations-list/index.d.ts +3 -1
  96. package/lib/containers/destination-modal/choose-destination/index.d.ts +5 -5
  97. package/lib/containers/destination-modal/index.d.ts +5 -6
  98. package/lib/containers/destination-selection-form/destination-list/index.d.ts +8 -0
  99. package/lib/containers/destination-selection-form/index.d.ts +5 -9
  100. package/lib/containers/dropdowns/{connection-type-dropdown → condition-dropdown}/index.d.ts +5 -5
  101. package/lib/containers/dropdowns/error-dropdown/index.d.ts +2 -0
  102. package/lib/containers/dropdowns/index.d.ts +6 -7
  103. package/lib/containers/dropdowns/kind-dropdown/index.d.ts +2 -0
  104. package/lib/containers/dropdowns/language-dropdown/index.d.ts +2 -0
  105. package/lib/containers/dropdowns/namespace-dropdown/index.d.ts +2 -3
  106. package/lib/containers/index.d.ts +38 -33
  107. package/lib/containers/instrumentation-rule-drawer/build-card.d.ts +2 -8
  108. package/lib/containers/instrumentation-rule-form/custom-fields/custom-instrumentation.d.ts +5 -0
  109. package/lib/containers/instrumentation-rule-form/custom-fields/headers-collection.d.ts +5 -0
  110. package/lib/containers/instrumentation-rule-form/custom-fields/index.d.ts +2 -2
  111. package/lib/containers/instrumentation-rule-form/index.d.ts +1 -1
  112. package/lib/containers/multi-source-control/index.d.ts +2 -0
  113. package/lib/containers/notification-manager/index.d.ts +1 -2
  114. package/lib/containers/overview-drawer/index.d.ts +10 -4
  115. package/lib/containers/service-map/helpers/build-edges.d.ts +10 -0
  116. package/lib/containers/service-map/helpers/build-map-nodes.d.ts +11 -0
  117. package/lib/containers/service-map/helpers/generate-dag-positions.d.ts +5 -0
  118. package/lib/containers/service-map/helpers/generate-spiral-grid-position.d.ts +2 -0
  119. package/lib/containers/service-map/index.d.ts +8 -0
  120. package/lib/containers/setup-summary/index.d.ts +10 -0
  121. package/lib/containers/side-nav/index.d.ts +8 -8
  122. package/lib/containers/slack-invite/index.d.ts +1 -2
  123. package/lib/containers/source-drawer/build-card.d.ts +1 -6
  124. package/lib/containers/source-drawer/describe/index.d.ts +1 -1
  125. package/lib/containers/source-drawer/index.d.ts +7 -8
  126. package/lib/containers/source-drawer/libraries/index.d.ts +14 -0
  127. package/lib/containers/source-drawer/odigos-health/index.d.ts +6 -0
  128. package/lib/containers/source-modal/index.d.ts +3 -9
  129. package/lib/containers/source-selection-form/index.d.ts +4 -8
  130. package/lib/containers/source-selection-form/source-list/index.d.ts +8 -0
  131. package/lib/containers/system-overview/describe/index.d.ts +1 -1
  132. package/lib/containers/system-settings/index.d.ts +9 -0
  133. package/lib/containers/system-settings/settings/collector-gateway-settings.d.ts +4 -0
  134. package/lib/containers/system-settings/settings/collector-node-settings.d.ts +4 -0
  135. package/lib/containers/system-settings/settings/general-settings.d.ts +4 -0
  136. package/lib/containers/system-settings/settings/options.d.ts +5 -0
  137. package/lib/containers/system-settings/settings/rollback-settings.d.ts +4 -0
  138. package/lib/containers/system-settings/settings/styled.d.ts +8 -0
  139. package/lib/containers/system-settings/settings/types.d.ts +13 -0
  140. package/lib/containers/system-settings/settings/ui-settings.d.ts +4 -0
  141. package/lib/containers/table-cell-conditions/index.d.ts +1 -0
  142. package/lib/containers/toast-list/index.d.ts +1 -2
  143. package/lib/containers/toggle-dark-mode/index.d.ts +1 -2
  144. package/lib/containers/trace-view/build-spans.d.ts +2 -0
  145. package/lib/containers/trace-view/index.d.ts +9 -0
  146. package/lib/containers/trace-view/span/index.d.ts +38 -0
  147. package/lib/containers/trace-view/span-drawer/build-details-card.d.ts +3 -0
  148. package/lib/containers/trace-view/span-drawer/build-logs-card.d.ts +3 -0
  149. package/lib/containers/trace-view/span-drawer/build-process-card.d.ts +3 -0
  150. package/lib/containers/trace-view/span-drawer/build-tags-card.d.ts +3 -0
  151. package/lib/containers/trace-view/span-drawer/index.d.ts +9 -0
  152. package/lib/containers.js +285 -15711
  153. package/lib/functions/clean-object-empty-strings-values/index.d.ts +2 -1
  154. package/lib/functions/compare-condition/index.d.ts +3 -3
  155. package/lib/functions/filter-destinations-by-stream/index.d.ts +2 -0
  156. package/lib/functions/filter-sources-by-stream/index.d.ts +2 -0
  157. package/lib/functions/flatten-object-keys/index.d.ts +2 -1
  158. package/lib/functions/format-duration/index.d.ts +1 -0
  159. package/lib/functions/get-action-icon/index.d.ts +2 -2
  160. package/lib/functions/get-conditions-booleans/index.d.ts +6 -2
  161. package/lib/functions/get-destination-icon/index.d.ts +5 -1
  162. package/lib/functions/get-entity-icon/index.d.ts +2 -2
  163. package/lib/functions/get-entity-id/index.d.ts +2 -2
  164. package/lib/functions/get-entity-label/index.d.ts +2 -2
  165. package/lib/functions/get-id-from-sse-target/index.d.ts +2 -2
  166. package/lib/functions/get-instrumentation-rule-icon/index.d.ts +2 -2
  167. package/lib/functions/get-main-container-language/index.d.ts +2 -0
  168. package/lib/functions/get-metric-for-entity/index.d.ts +2 -2
  169. package/lib/functions/get-monitor-icon/index.d.ts +2 -2
  170. package/lib/functions/get-platform-icon/index.d.ts +2 -2
  171. package/lib/functions/get-platform-label/index.d.ts +2 -2
  172. package/lib/functions/get-programming-language-icon/index.d.ts +2 -2
  173. package/lib/functions/get-recursive-values/index.d.ts +4 -0
  174. package/lib/functions/get-sse-target-from-id/index.d.ts +2 -2
  175. package/lib/functions/get-status-icon/index.d.ts +3 -2
  176. package/lib/functions/get-status-type-from-odigos-health/index.d.ts +2 -0
  177. package/lib/functions/get-yaml-fields-for-destination/index.d.ts +2 -0
  178. package/lib/functions/has-unhealthy-instances/index.d.ts +2 -0
  179. package/lib/functions/index.d.ts +15 -1
  180. package/lib/functions/is-legal-k8s-label/index.d.ts +1 -0
  181. package/lib/functions/is-string-a-boolean/index.d.ts +1 -0
  182. package/lib/functions/is-valid-version/index.d.ts +1 -0
  183. package/lib/functions/map-destination-fields-for-display/index.d.ts +6 -0
  184. package/lib/functions/map-exported-signals/index.d.ts +2 -0
  185. package/lib/functions/numbers-only/index.d.ts +1 -0
  186. package/lib/functions/parse-boolean-from-string/index.d.ts +1 -0
  187. package/lib/functions/remove-empty-values-from-object/index.d.ts +2 -1
  188. package/lib/functions/safe-json-parse/index.d.ts +2 -1
  189. package/lib/functions/safe-json-stringify/index.d.ts +2 -1
  190. package/lib/functions/split-camel-string/index.d.ts +1 -1
  191. package/lib/functions/stringify-non-string-values/index.d.ts +2 -1
  192. package/lib/functions.js +1 -115
  193. package/lib/hooks/index.d.ts +3 -0
  194. package/lib/hooks/useActionFormData.d.ts +2 -2
  195. package/lib/hooks/useDataStreamFormData.d.ts +12 -0
  196. package/lib/hooks/useDestinationFormData.d.ts +1 -1
  197. package/lib/hooks/useGenericForm.d.ts +3 -1
  198. package/lib/hooks/useInstrumentationRuleFormData.d.ts +3 -6
  199. package/lib/hooks/usePopup.d.ts +17 -0
  200. package/lib/hooks/useSessionStorage.d.ts +5 -0
  201. package/lib/hooks/useSourceFormData.d.ts +2 -5
  202. package/lib/hooks/useSourceSelectionFormData.d.ts +19 -20
  203. package/lib/hooks.js +1 -13
  204. package/lib/icons/actions/index.d.ts +5 -5
  205. package/lib/icons/brand/index.d.ts +2 -2
  206. package/lib/icons/common/avatar-icon/index.d.ts +2 -0
  207. package/lib/icons/common/edited-icon/index.d.ts +2 -0
  208. package/lib/icons/common/gear-icon/index.d.ts +2 -0
  209. package/lib/icons/common/index.d.ts +30 -20
  210. package/lib/icons/common/refresh-arrows-icon/index.d.ts +2 -0
  211. package/lib/icons/common/refresh-left-arrow-icon/index.d.ts +2 -0
  212. package/lib/icons/common/refresh-right-arrow-icon/index.d.ts +2 -0
  213. package/lib/icons/common/rotate-arrows-icon/index.d.ts +2 -0
  214. package/lib/icons/common/user-group-icon/index.d.ts +2 -0
  215. package/lib/icons/common/user-icon/index.d.ts +2 -0
  216. package/lib/icons/common/user-settings-icon/index.d.ts +2 -0
  217. package/lib/icons/compute-platform/index.d.ts +2 -2
  218. package/lib/icons/destinations/alauda-logo/index.d.ts +2 -0
  219. package/lib/icons/destinations/alibaba-cloud-logo/index.d.ts +2 -0
  220. package/lib/icons/destinations/app-dynamics-logo/index.d.ts +2 -0
  221. package/lib/icons/destinations/aws-cloudwatch-logo/index.d.ts +2 -0
  222. package/lib/icons/destinations/aws-s3-logo/index.d.ts +2 -0
  223. package/lib/icons/destinations/aws-xray-logo/index.d.ts +2 -0
  224. package/lib/icons/destinations/axiom-logo/index.d.ts +2 -0
  225. package/lib/icons/destinations/better-stack-logo/index.d.ts +2 -0
  226. package/lib/icons/destinations/blob-storage-logo/index.d.ts +2 -0
  227. package/lib/icons/destinations/bonree-logo/index.d.ts +2 -0
  228. package/lib/icons/destinations/causely-logo/index.d.ts +2 -0
  229. package/lib/icons/destinations/checkly-logo/index.d.ts +2 -0
  230. package/lib/icons/destinations/chronosphere-logo/index.d.ts +2 -0
  231. package/lib/icons/destinations/clickhouse-logo/index.d.ts +2 -0
  232. package/lib/icons/destinations/coralogix-logo/index.d.ts +2 -0
  233. package/lib/icons/destinations/dash0-logo/index.d.ts +2 -0
  234. package/lib/icons/destinations/datadog-logo/index.d.ts +2 -0
  235. package/lib/icons/destinations/dynatrace-logo/index.d.ts +2 -0
  236. package/lib/icons/destinations/elastic-apm-logo/index.d.ts +2 -0
  237. package/lib/icons/destinations/elastic-search-logo/index.d.ts +2 -0
  238. package/lib/icons/destinations/gigapipe-logo/index.d.ts +2 -0
  239. package/lib/icons/destinations/google-cloud-platform-logo/index.d.ts +2 -0
  240. package/lib/icons/destinations/google-cloud-storage-logo/index.d.ts +2 -0
  241. package/lib/icons/destinations/grafana-logo/index.d.ts +2 -0
  242. package/lib/icons/destinations/greptime-logo/index.d.ts +2 -0
  243. package/lib/icons/destinations/groundcover-logo/index.d.ts +2 -0
  244. package/lib/icons/destinations/honeycomb-logo/index.d.ts +2 -0
  245. package/lib/icons/destinations/hyperdx-logo/index.d.ts +2 -0
  246. package/lib/icons/destinations/index.d.ts +60 -0
  247. package/lib/icons/destinations/instana-logo/index.d.ts +2 -0
  248. package/lib/icons/destinations/jaeger-logo/index.d.ts +2 -0
  249. package/lib/icons/destinations/kloudmate-logo/index.d.ts +2 -0
  250. package/lib/icons/destinations/last9-logo/index.d.ts +2 -0
  251. package/lib/icons/destinations/lightstep-logo/index.d.ts +2 -0
  252. package/lib/icons/destinations/logzio-logo/index.d.ts +2 -0
  253. package/lib/icons/destinations/loki-logo/index.d.ts +2 -0
  254. package/lib/icons/destinations/lumigo-logo/index.d.ts +2 -0
  255. package/lib/icons/destinations/middleware-logo/index.d.ts +2 -0
  256. package/lib/icons/destinations/new-relic-logo/index.d.ts +2 -0
  257. package/lib/icons/destinations/observe-logo/index.d.ts +2 -0
  258. package/lib/icons/destinations/odigos-destination-logo/index.d.ts +2 -0
  259. package/lib/icons/destinations/one-uptime-logo/index.d.ts +2 -0
  260. package/lib/icons/destinations/open-observe-logo/index.d.ts +2 -0
  261. package/lib/icons/destinations/open-telemetry-logo/index.d.ts +2 -0
  262. package/lib/icons/destinations/ops-verse-logo/index.d.ts +2 -0
  263. package/lib/icons/destinations/oracle-logo/index.d.ts +2 -0
  264. package/lib/icons/destinations/prometheus-logo/index.d.ts +2 -0
  265. package/lib/icons/destinations/qryn-logo/index.d.ts +2 -0
  266. package/lib/icons/destinations/quickwit-logo/index.d.ts +2 -0
  267. package/lib/icons/destinations/sentry-logo/index.d.ts +2 -0
  268. package/lib/icons/destinations/seq-logo/index.d.ts +2 -0
  269. package/lib/icons/destinations/signoz-logo/index.d.ts +2 -0
  270. package/lib/icons/destinations/splunk-logo/index.d.ts +2 -0
  271. package/lib/icons/destinations/sumo-logic-logo/index.d.ts +2 -0
  272. package/lib/icons/destinations/telemetry-hub-logo/index.d.ts +2 -0
  273. package/lib/icons/destinations/tempo-logo/index.d.ts +2 -0
  274. package/lib/icons/destinations/tingyun-logo/index.d.ts +2 -0
  275. package/lib/icons/destinations/traceloop-logo/index.d.ts +2 -0
  276. package/lib/icons/destinations/uptrace-logo/index.d.ts +2 -0
  277. package/lib/icons/destinations/victoria-metrics-logo/index.d.ts +2 -0
  278. package/lib/icons/index.d.ts +1 -0
  279. package/lib/icons/instrumentation-rules/custom-instrumentation-icon/index.d.ts +2 -0
  280. package/lib/icons/instrumentation-rules/headers-collection-icon/index.d.ts +2 -0
  281. package/lib/icons/instrumentation-rules/index.d.ts +4 -2
  282. package/lib/icons/math/index.d.ts +4 -2
  283. package/lib/icons/math/minus-circled-icon/index.d.ts +2 -0
  284. package/lib/icons/math/plus-circled-icon/index.d.ts +2 -0
  285. package/lib/icons/monitors/index.d.ts +3 -3
  286. package/lib/icons/on-off/index.d.ts +6 -6
  287. package/lib/icons/overview/data-streams-icon/index.d.ts +2 -0
  288. package/lib/icons/overview/index.d.ts +10 -8
  289. package/lib/icons/overview/namespaces-icon/index.d.ts +2 -0
  290. package/lib/icons/programming-languages/index.d.ts +0 -1
  291. package/lib/icons/social/index.d.ts +1 -1
  292. package/lib/icons/status/index.d.ts +8 -8
  293. package/lib/icons.js +1 -82
  294. package/lib/mock-data/config/index.d.ts +2 -0
  295. package/lib/{data → mock-data}/destinations/index.d.ts +1 -1
  296. package/lib/{data → mock-data}/index.d.ts +4 -0
  297. package/lib/mock-data/instrumentation-instances/index.d.ts +2 -0
  298. package/lib/mock-data/service-map/index.d.ts +2 -0
  299. package/lib/{data → mock-data}/sources/index.d.ts +8 -4
  300. package/lib/mock-data/traces/index.d.ts +2 -0
  301. package/lib/snippets/add-button/index.d.ts +8 -0
  302. package/lib/snippets/copy-text/index.d.ts +7 -0
  303. package/lib/snippets/edit-button/index.d.ts +7 -0
  304. package/lib/snippets/index.d.ts +7 -0
  305. package/lib/snippets/note-back-to-summary/index.d.ts +6 -0
  306. package/lib/snippets/pod-container/index.d.ts +5 -0
  307. package/lib/snippets/react-flow/edges/labeled-edge.d.ts +10 -0
  308. package/lib/{containers/data-flow → snippets/react-flow}/flow.d.ts +2 -0
  309. package/lib/snippets/react-flow/index.d.ts +13 -0
  310. package/lib/snippets/react-flow/nodes/add-node.d.ts +11 -0
  311. package/lib/snippets/react-flow/nodes/base-node.d.ts +21 -0
  312. package/lib/snippets/react-flow/nodes/edged-node.d.ts +9 -0
  313. package/lib/snippets/react-flow/nodes/frame-node.d.ts +9 -0
  314. package/lib/{containers/data-flow → snippets/react-flow}/nodes/header-node.d.ts +5 -5
  315. package/lib/snippets/react-flow/nodes/map-item-node.d.ts +12 -0
  316. package/lib/snippets/react-flow/nodes/no-data-node.d.ts +9 -0
  317. package/lib/snippets/react-flow/nodes/scroll-node.d.ts +15 -0
  318. package/lib/snippets/react-flow/nodes/skeleton-node.d.ts +8 -0
  319. package/lib/snippets/source-container/index.d.ts +7 -0
  320. package/lib/snippets/source-container/override-runtime.d.ts +9 -0
  321. package/lib/snippets.js +1 -0
  322. package/lib/store/index.d.ts +2 -0
  323. package/lib/store/useActiveNodeStore.d.ts +11 -0
  324. package/lib/store/useDarkMode.d.ts +5 -3
  325. package/lib/store/useDataStreamStore.d.ts +16 -0
  326. package/lib/store/useDrawerStore.d.ts +2 -2
  327. package/lib/store/useEntityStore.d.ts +8 -6
  328. package/lib/store/useFilterStore.d.ts +5 -2
  329. package/lib/store/usePendingStore.d.ts +2 -2
  330. package/lib/store/useSetupStore.d.ts +20 -26
  331. package/lib/store.js +1 -4
  332. package/lib/theme/index.d.ts +2 -3
  333. package/lib/theme/palletes/index.d.ts +2 -105
  334. package/lib/theme.js +1 -240
  335. package/lib/types/actions/index.d.ts +154 -68
  336. package/lib/types/common/index.d.ts +91 -76
  337. package/lib/types/config/index.d.ts +80 -0
  338. package/lib/types/data-flow/index.d.ts +17 -15
  339. package/lib/types/data-streams/index.d.ts +3 -0
  340. package/lib/types/describe/index.d.ts +7 -3
  341. package/lib/types/destinations/index.d.ts +89 -9
  342. package/lib/types/index.d.ts +5 -1
  343. package/lib/types/instrumentation-instances/index.d.ts +7 -0
  344. package/lib/types/instrumentation-rules/index.d.ts +65 -36
  345. package/lib/types/namespaces/index.d.ts +14 -0
  346. package/lib/types/service-map/index.d.ts +10 -0
  347. package/lib/types/signals/index.d.ts +5 -5
  348. package/lib/types/sources/index.d.ts +42 -20
  349. package/lib/types/traces/index.d.ts +38 -0
  350. package/lib/types.js +1 -166
  351. package/package.json +50 -40
  352. package/lib/components/auto-complete-input/auto-complete-input.stories.d.ts +0 -9
  353. package/lib/components/badge/badge.stories.d.ts +0 -13
  354. package/lib/components/button/button.stories.d.ts +0 -9
  355. package/lib/components/cancel-warning/cancel-warning.stories.d.ts +0 -9
  356. package/lib/components/checkbox/checkbox.stories.d.ts +0 -9
  357. package/lib/components/code/code.stories.d.ts +0 -9
  358. package/lib/components/condition-details/condition-details.stories.d.ts +0 -14
  359. package/lib/components/data-card/data-card.stories.d.ts +0 -10
  360. package/lib/components/data-tab/data-tab.stories.d.ts +0 -9
  361. package/lib/components/delete-warning/delete-warning.stories.d.ts +0 -9
  362. package/lib/components/describe-row/describe-row.stories.d.ts +0 -9
  363. package/lib/components/divider/divider.stories.d.ts +0 -9
  364. package/lib/components/docs-button/docs-button.stories.d.ts +0 -9
  365. package/lib/components/drawer/drawer.stories.d.ts +0 -10
  366. package/lib/components/dropdown/dropdown.stories.d.ts +0 -10
  367. package/lib/components/error-boundary/error-boundary.stories.d.ts +0 -9
  368. package/lib/components/extend-arrow/extend-arrow.stories.d.ts +0 -9
  369. package/lib/components/fade-loader/fade-loader.stories.d.ts +0 -9
  370. package/lib/components/field-error/field-error.stories.d.ts +0 -9
  371. package/lib/components/field-label/field-label.stories.d.ts +0 -9
  372. package/lib/components/header/header.stories.d.ts +0 -9
  373. package/lib/components/icon-button/icon-button.stories.d.ts +0 -9
  374. package/lib/components/icon-group/icon-group.stories.d.ts +0 -14
  375. package/lib/components/icon-title-badge/icon-title-badge.stories.d.ts +0 -9
  376. package/lib/components/icon-wrapped/icon-wrapped.stories.d.ts +0 -10
  377. package/lib/components/icons-nav/icons-nav.stories.d.ts +0 -9
  378. package/lib/components/image-controlled/image-controlled.stories.d.ts +0 -9
  379. package/lib/components/input/input.stories.d.ts +0 -9
  380. package/lib/components/input-list/input-list.stories.d.ts +0 -9
  381. package/lib/components/input-table/input-table.stories.d.ts +0 -9
  382. package/lib/components/interactive-table/interactive-table.stories.d.ts +0 -12
  383. package/lib/components/interactive-table/row.d.ts +0 -13
  384. package/lib/components/key-value-input-list/key-value-input-list.stories.d.ts +0 -9
  385. package/lib/components/modal/modal.stories.d.ts +0 -9
  386. package/lib/components/monitors-checkboxes/monitors-checkboxes.stories.d.ts +0 -9
  387. package/lib/components/monitors-icons/monitors-icons.stories.d.ts +0 -9
  388. package/lib/components/navigation-buttons/navigation-buttons.stories.d.ts +0 -9
  389. package/lib/components/no-data-found/no-data-found.stories.d.ts +0 -9
  390. package/lib/components/notification-note/notification-note.stories.d.ts +0 -10
  391. package/lib/components/section-title/section-title.stories.d.ts +0 -9
  392. package/lib/components/segment/segment.stories.d.ts +0 -9
  393. package/lib/components/skeleton-loader/skeleton-loader.stories.d.ts +0 -9
  394. package/lib/components/status/status.stories.d.ts +0 -9
  395. package/lib/components/stepper/stepper.stories.d.ts +0 -9
  396. package/lib/components/text/text.stories.d.ts +0 -9
  397. package/lib/components/textarea/textarea.stories.d.ts +0 -9
  398. package/lib/components/toggle/toggle.stories.d.ts +0 -9
  399. package/lib/components/tooltip/tooltip.stories.d.ts +0 -9
  400. package/lib/components/trace-loader/trace-loader.stories.d.ts +0 -9
  401. package/lib/components/warning-modal/warning-modal.stories.d.ts +0 -9
  402. package/lib/containers/action-drawer/action-drawer.stories.d.ts +0 -9
  403. package/lib/containers/action-form/action-form.stories.d.ts +0 -9
  404. package/lib/containers/action-modal/action-modal.stories.d.ts +0 -9
  405. package/lib/containers/action-table/action-table.stories.d.ts +0 -9
  406. package/lib/containers/await-pipeline/await-pipeline.stories.d.ts +0 -9
  407. package/lib/containers/compute-platform-select/compute-platform-select.stories.d.ts +0 -9
  408. package/lib/containers/compute-platform-select/index.d.ts +0 -10
  409. package/lib/containers/compute-platforms/compute-platforms.stories.d.ts +0 -9
  410. package/lib/containers/compute-platforms/index.d.ts +0 -8
  411. package/lib/containers/compute-platforms-actions-menu/compute-platforms-actions-menu.stories.d.ts +0 -9
  412. package/lib/containers/compute-platforms-actions-menu/index.d.ts +0 -7
  413. package/lib/containers/data-flow/data-flow.stories.d.ts +0 -9
  414. package/lib/containers/data-flow/edges/labeled-edge.d.ts +0 -10
  415. package/lib/containers/data-flow/helpers/get-main-container-language.d.ts +0 -2
  416. package/lib/containers/data-flow/nodes/add-node.d.ts +0 -11
  417. package/lib/containers/data-flow/nodes/base-node.d.ts +0 -21
  418. package/lib/containers/data-flow/nodes/edged-node.d.ts +0 -9
  419. package/lib/containers/data-flow/nodes/frame-node.d.ts +0 -9
  420. package/lib/containers/data-flow/nodes/scroll-node.d.ts +0 -26
  421. package/lib/containers/data-flow/nodes/skeleton-node.d.ts +0 -8
  422. package/lib/containers/data-flow-actions-menu/data-flow.stories.d.ts +0 -11
  423. package/lib/containers/data-flow-actions-menu/search/recent-searches/index.d.ts +0 -2
  424. package/lib/containers/destination-drawer/destination-drawer.stories.d.ts +0 -9
  425. package/lib/containers/destination-form/destination-form.stories.d.ts +0 -9
  426. package/lib/containers/destination-modal/choose-destination/potential-destinations-list/index.d.ts +0 -8
  427. package/lib/containers/destination-modal/destination-modal.stories.d.ts +0 -9
  428. package/lib/containers/destination-selection-form/configured-list/index.d.ts +0 -5
  429. package/lib/containers/destination-selection-form/destination-selection-form.stories.d.ts +0 -9
  430. package/lib/containers/destination-table/destination-table.stories.d.ts +0 -9
  431. package/lib/containers/dropdowns/connection-status-dropdown/connection-status-dropdown.stories.d.ts +0 -9
  432. package/lib/containers/dropdowns/connection-status-dropdown/index.d.ts +0 -15
  433. package/lib/containers/dropdowns/connection-type-dropdown/connection-type-dropdown.stories.d.ts +0 -9
  434. package/lib/containers/dropdowns/error-dropdown/error-dropdown.stories.d.ts +0 -9
  435. package/lib/containers/dropdowns/kind-dropdown/error-dropdown.stories.d.ts +0 -9
  436. package/lib/containers/dropdowns/language-dropdown/language-dropdown.stories.d.ts +0 -9
  437. package/lib/containers/dropdowns/monitor-dropdown/monitor-dropdown.stories.d.ts +0 -9
  438. package/lib/containers/dropdowns/namespace-dropdown/namespace-dropdown.stories.d.ts +0 -9
  439. package/lib/containers/instrumentation-rule-drawer/instrumentation-rule-drawer.stories.d.ts +0 -9
  440. package/lib/containers/instrumentation-rule-form/instrumentation-rule-form.stories.d.ts +0 -9
  441. package/lib/containers/instrumentation-rule-modal/instrumentation-rule-modal.stories.d.ts +0 -9
  442. package/lib/containers/instrumentation-rule-table/instrumentation-rule-table.stories.d.ts +0 -9
  443. package/lib/containers/multi-source-control/multi-source-control.stories.d.ts +0 -9
  444. package/lib/containers/notification-manager/notification-manager.stories.d.ts +0 -9
  445. package/lib/containers/overview-drawer/overview-drawer.stories.d.ts +0 -9
  446. package/lib/containers/side-nav/side-nav.stories.d.ts +0 -9
  447. package/lib/containers/slack-invite/slack-invite.stories.d.ts +0 -9
  448. package/lib/containers/source-drawer/source-drawer.stories.d.ts +0 -9
  449. package/lib/containers/source-form/source-form.stories.d.ts +0 -9
  450. package/lib/containers/source-modal/source-modal.stories.d.ts +0 -9
  451. package/lib/containers/source-selection-form/fast/controls/index.d.ts +0 -7
  452. package/lib/containers/source-selection-form/fast/index.d.ts +0 -7
  453. package/lib/containers/source-selection-form/fast/list/index.d.ts +0 -10
  454. package/lib/containers/source-selection-form/simple/controls/index.d.ts +0 -11
  455. package/lib/containers/source-selection-form/simple/index.d.ts +0 -7
  456. package/lib/containers/source-selection-form/simple/list/index.d.ts +0 -9
  457. package/lib/containers/source-selection-form/source-selection-form.stories.d.ts +0 -9
  458. package/lib/containers/source-table/source-table.stories.d.ts +0 -9
  459. package/lib/containers/system-overview/system-overview.stories.d.ts +0 -9
  460. package/lib/containers/table-cell-conditions/table-cell-conditions.stories.d.ts +0 -9
  461. package/lib/containers/toast-list/toast-list.stories.d.ts +0 -9
  462. package/lib/containers/toggle-dark-mode/toggle-dark-mode.stories.d.ts +0 -9
  463. package/lib/functions/derive-type-from-rule/index.d.ts +0 -2
  464. package/lib/icons/actions/add-cluster-info-icon/add-cluster-info-icon.stories.d.ts +0 -8
  465. package/lib/icons/actions/delete-attribute-icon/delete-attribute-icon.stories.d.ts +0 -8
  466. package/lib/icons/actions/pii-masking-icon/pii-masking-icon.stories.d.ts +0 -8
  467. package/lib/icons/actions/rename-attribute-icon/rename-attribute-icon.stories.d.ts +0 -8
  468. package/lib/icons/actions/sampler-icon/sampler-icon.stories.d.ts +0 -8
  469. package/lib/icons/brand/odigos-logo/odigos-logo.stories.d.ts +0 -8
  470. package/lib/icons/brand/odigos-logo-text/odigos-logo-text.stories.d.ts +0 -8
  471. package/lib/icons/common/arrow-icon/arrow-icon.stories.d.ts +0 -8
  472. package/lib/icons/common/code-brackets-icon/code-brackets-icon.stories.d.ts +0 -8
  473. package/lib/icons/common/code-icon/code-icon.stories.d.ts +0 -8
  474. package/lib/icons/common/command-icon/command-icon.stories.d.ts +0 -8
  475. package/lib/icons/common/copy-icon/copy-icon.stories.d.ts +0 -8
  476. package/lib/icons/common/edit-icon/edit-icon.stories.d.ts +0 -8
  477. package/lib/icons/common/extend-arrow-icon/extend-arrow-icon.stories.d.ts +0 -8
  478. package/lib/icons/common/filter-icon/filter-icon.stories.d.ts +0 -8
  479. package/lib/icons/common/folder-icon/folder-icon.stories.d.ts +0 -8
  480. package/lib/icons/common/image-error-icon/image-error-icon.stories.d.ts +0 -8
  481. package/lib/icons/common/key-icon/key-icon.stories.d.ts +0 -8
  482. package/lib/icons/common/list-icon/list-icon.stories.d.ts +0 -8
  483. package/lib/icons/common/no-data-icon/no-data-icon.stories.d.ts +0 -8
  484. package/lib/icons/common/notebook-icon/notebook-icon.stories.d.ts +0 -8
  485. package/lib/icons/common/notification-icon/notification-icon.stories.d.ts +0 -8
  486. package/lib/icons/common/search-icon/search-icon.stories.d.ts +0 -8
  487. package/lib/icons/common/sort-arrows-icon/sort-arrows-icon.stories.d.ts +0 -8
  488. package/lib/icons/common/terminal-icon/terminal-icon.stories.d.ts +0 -8
  489. package/lib/icons/common/trash-icon/trash-icon.stories.d.ts +0 -8
  490. package/lib/icons/common/x-icon/x-icon.stories.d.ts +0 -8
  491. package/lib/icons/compute-platform/k8s-logo/k8s-logo.stories.d.ts +0 -8
  492. package/lib/icons/compute-platform/vm-logo/vm-logo.stories.d.ts +0 -8
  493. package/lib/icons/instrumentation-rules/code-attributes-icon/code-attributes-icon.stories.d.ts +0 -8
  494. package/lib/icons/instrumentation-rules/payload-collection-icon/payload-collection-icon.stories.d.ts +0 -8
  495. package/lib/icons/math/minus-icon/minus-icon.stories.d.ts +0 -8
  496. package/lib/icons/math/plus-icon/plus-icon.stories.d.ts +0 -8
  497. package/lib/icons/monitors/logs-icon/logs-icon.stories.d.ts +0 -8
  498. package/lib/icons/monitors/metrics-icon/metrics-icon.stories.d.ts +0 -8
  499. package/lib/icons/monitors/traces-icon/traces-icon.stories.d.ts +0 -8
  500. package/lib/icons/on-off/eye-closed-icon/eye-closed-icon.stories.d.ts +0 -8
  501. package/lib/icons/on-off/eye-open-icon/eye-open-icon.stories.d.ts +0 -8
  502. package/lib/icons/on-off/light-off-icon/light-off-icon.stories.d.ts +0 -8
  503. package/lib/icons/on-off/light-on-icon/light-on-icon.stories.d.ts +0 -8
  504. package/lib/icons/on-off/moon-icon/moon-icon.stories.d.ts +0 -8
  505. package/lib/icons/on-off/sun-icon/sun-icon.stories.d.ts +0 -8
  506. package/lib/icons/overview/actions-icon/actions-icon.stories.d.ts +0 -8
  507. package/lib/icons/overview/connections-icon/connections-icon.stories.d.ts +0 -8
  508. package/lib/icons/overview/destinations-icon/destinations-icon.stories.d.ts +0 -8
  509. package/lib/icons/overview/overview-icon/overview-icon.stories.d.ts +0 -8
  510. package/lib/icons/overview/rules-icon/rules-icon.stories.d.ts +0 -8
  511. package/lib/icons/overview/service-map-icon/service-map-icon.stories.d.ts +0 -8
  512. package/lib/icons/overview/sources-icon/sources-icon.stories.d.ts +0 -8
  513. package/lib/icons/overview/trace-view-icon/trace-view-icon.stories.d.ts +0 -8
  514. package/lib/icons/programming-languages/c-plus-plus-logo/c-plus-plus-logo.stories.d.ts +0 -8
  515. package/lib/icons/programming-languages/c-sharp-logo/c-sharp-logo.stories.d.ts +0 -8
  516. package/lib/icons/programming-languages/dotnet-logo/dotnet-logo.stories.d.ts +0 -8
  517. package/lib/icons/programming-languages/elixir-logo/elixir-logo.stories.d.ts +0 -8
  518. package/lib/icons/programming-languages/go-logo/go-logo.stories.d.ts +0 -8
  519. package/lib/icons/programming-languages/java-logo/java-logo.stories.d.ts +0 -8
  520. package/lib/icons/programming-languages/kafka-logo/kafka-logo.stories.d.ts +0 -8
  521. package/lib/icons/programming-languages/mysql-logo/mysql-logo.stories.d.ts +0 -8
  522. package/lib/icons/programming-languages/nginx-logo/nginx-logo.stories.d.ts +0 -8
  523. package/lib/icons/programming-languages/nodejs-logo/nodejs-logo.stories.d.ts +0 -8
  524. package/lib/icons/programming-languages/php-logo/php-logo.stories.d.ts +0 -8
  525. package/lib/icons/programming-languages/postgres-logo/postgres-logo.stories.d.ts +0 -8
  526. package/lib/icons/programming-languages/python-logo/python-logo.stories.d.ts +0 -8
  527. package/lib/icons/programming-languages/redis-logo/redis-logo.stories.d.ts +0 -8
  528. package/lib/icons/programming-languages/ruby-logo/ruby-logo.stories.d.ts +0 -8
  529. package/lib/icons/programming-languages/rust-logo/rust-logo.stories.d.ts +0 -8
  530. package/lib/icons/programming-languages/swift-logo/swift-logo.stories.d.ts +0 -8
  531. package/lib/icons/social/slack-logo/slack-logo.stories.d.ts +0 -8
  532. package/lib/icons/status/check-circled-icon/check-circled-icon.stories.d.ts +0 -8
  533. package/lib/icons/status/check-icon/check-icon.stories.d.ts +0 -8
  534. package/lib/icons/status/cross-circled-icon/cross-circled-icon.stories.d.ts +0 -8
  535. package/lib/icons/status/cross-icon/cross-icon.stories.d.ts +0 -8
  536. package/lib/icons/status/error-round-icon/error-round-icon.stories.d.ts +0 -8
  537. package/lib/icons/status/error-triangle-icon/error-triangle-icon.stories.d.ts +0 -8
  538. package/lib/icons/status/info-icon/info-icon.stories.d.ts +0 -8
  539. package/lib/icons/status/warning-triangle-icon/warning-triangle-icon.stories.d.ts +0 -8
  540. package/lib/index-3KUV6Vlt.js +0 -89
  541. package/lib/index-BFct3S32.js +0 -22
  542. package/lib/index-BGlk5VhF.js +0 -69
  543. package/lib/index-BZS1ijMm.js +0 -30
  544. package/lib/index-Bc8gi9FH.js +0 -202
  545. package/lib/index-BjJpYtF1.js +0 -42
  546. package/lib/index-BumPE6cF.js +0 -37
  547. package/lib/index-CZe2VX28.js +0 -128
  548. package/lib/index-Cu2uHOuh.js +0 -44
  549. package/lib/index-DIcomki-.js +0 -671
  550. package/lib/index-D_Qn2U89.js +0 -138
  551. package/lib/index-g6Twdelv.js +0 -196
  552. package/lib/index-ixs381n-.js +0 -466
  553. package/lib/index-m62aT4IR.js +0 -29574
  554. package/lib/types/connection/index.d.ts +0 -7
  555. package/lib/useSourceSelectionFormData-BY6B70Kf.js +0 -561
  556. package/lib/useTransition-Dfxjcy-C.js +0 -3493
  557. /package/lib/icons/{programming-languages → destinations}/kafka-logo/index.d.ts +0 -0
  558. /package/lib/{data → mock-data}/actions/index.d.ts +0 -0
  559. /package/lib/{data → mock-data}/describe/index.d.ts +0 -0
  560. /package/lib/{data → mock-data}/instrumentation-rules/index.d.ts +0 -0
  561. /package/lib/{data → mock-data}/namespaces/index.d.ts +0 -0
  562. /package/lib/{data → mock-data}/tokens/index.d.ts +0 -0
  563. /package/lib/{containers/data-flow/helpers → snippets/react-flow}/node-config.d.ts +0 -0
@@ -1,3493 +0,0 @@
1
- import React, { useState, useRef, useEffect, useCallback } from 'react';
2
- import './index-CZe2VX28.js';
3
- import { f as useNotificationStore } from './index-DIcomki-.js';
4
- import { CODE_ATTRIBUTES_KEY_TYPES, PAYLOAD_COLLECTION_KEY_TYPES } from './types.js';
5
- import styled from 'styled-components';
6
-
7
- const useGenericForm = (initialFormData) => {
8
- function copyInitial() {
9
- // this is to avoid reference issues with the initial form data,
10
- // when an object has arrays or objects as part of it's values, a simple spread operator won't work, the children would act as references,
11
- // so we use JSON.parse(JSON.stringify()) to create a deep copy of the object without affecting the original
12
- return JSON.parse(JSON.stringify(initialFormData));
13
- }
14
- const [formData, setFormData] = useState(copyInitial());
15
- const [formErrors, setFormErrors] = useState({});
16
- const handleFormChange = (key, val, obj) => {
17
- if (key) {
18
- // this is for cases where the form contains objects such as "exportedSignals",
19
- // the object's child is targeted with a ".dot" for example: "exportedSignals.logs"
20
- const [parentKey, childKey] = key.toString().split('.');
21
- setFormData((prev) => {
22
- if (childKey) {
23
- return {
24
- ...prev,
25
- [parentKey]: {
26
- ...prev[parentKey],
27
- [childKey]: val,
28
- },
29
- };
30
- }
31
- else {
32
- return {
33
- ...prev,
34
- [parentKey]: val,
35
- };
36
- }
37
- });
38
- }
39
- else if (obj) {
40
- setFormData({ ...obj });
41
- }
42
- };
43
- const handleErrorChange = (key, val, obj) => {
44
- if (key) {
45
- setFormErrors((prev) => ({ ...prev, [key]: val }));
46
- }
47
- else if (obj) {
48
- setFormErrors({ ...obj });
49
- }
50
- };
51
- const resetFormData = () => {
52
- setFormData(copyInitial());
53
- setFormErrors({});
54
- };
55
- return {
56
- formData,
57
- formErrors,
58
- handleFormChange,
59
- handleErrorChange,
60
- resetFormData,
61
- };
62
- };
63
-
64
- const useContainerSize = () => {
65
- const ref = useRef(null);
66
- const [width, setWidth] = useState(0);
67
- const [height, setHeight] = useState(0);
68
- useEffect(() => {
69
- const resize = () => {
70
- if (ref.current) {
71
- const { width, height } = ref.current.getBoundingClientRect();
72
- setWidth(width);
73
- setHeight(height);
74
- }
75
- };
76
- resize();
77
- window.addEventListener('resize', resize);
78
- return () => window.removeEventListener('resize', resize);
79
- }, []);
80
- return {
81
- containerRef: ref,
82
- containerWidth: width,
83
- containerHeight: height,
84
- };
85
- };
86
-
87
- const useCopy = () => {
88
- const [isCopied, setIsCopied] = useState(false);
89
- const [copiedIndex, setCopiedIndex] = useState(-1);
90
- const clickCopy = async (str, idx) => {
91
- if (!isCopied) {
92
- setIsCopied(true);
93
- if (idx !== undefined)
94
- setCopiedIndex(idx);
95
- if (navigator?.clipboard && navigator.clipboard.writeText) {
96
- try {
97
- await navigator.clipboard.writeText(str);
98
- }
99
- catch (err) {
100
- console.error('Clipboard write failed:', err);
101
- }
102
- }
103
- else {
104
- // Fallback: Create a temporary textarea
105
- const textArea = document.createElement('textarea');
106
- textArea.value = str;
107
- document.body.appendChild(textArea);
108
- textArea.select();
109
- try {
110
- document.execCommand('copy');
111
- }
112
- catch (err) {
113
- console.error('execCommand copy failed:', err);
114
- }
115
- document.body.removeChild(textArea);
116
- }
117
- setTimeout(() => {
118
- setIsCopied(false);
119
- setCopiedIndex(-1);
120
- }, 1000);
121
- }
122
- };
123
- return { isCopied, copiedIndex, clickCopy };
124
- };
125
-
126
- const INITIAL = {
127
- ruleName: '',
128
- notes: '',
129
- disabled: false,
130
- workloads: null,
131
- instrumentationLibraries: null,
132
- payloadCollection: {
133
- [PAYLOAD_COLLECTION_KEY_TYPES.HTTP_REQUEST]: null,
134
- [PAYLOAD_COLLECTION_KEY_TYPES.HTTP_RESPONSE]: null,
135
- [PAYLOAD_COLLECTION_KEY_TYPES.DB_QUERY]: null,
136
- [PAYLOAD_COLLECTION_KEY_TYPES.MESSAGING]: null,
137
- },
138
- codeAttributes: {
139
- [CODE_ATTRIBUTES_KEY_TYPES.COLUMN]: null,
140
- [CODE_ATTRIBUTES_KEY_TYPES.FILE_PATH]: null,
141
- [CODE_ATTRIBUTES_KEY_TYPES.FUNCTION]: null,
142
- [CODE_ATTRIBUTES_KEY_TYPES.LINE_NUMBER]: null,
143
- [CODE_ATTRIBUTES_KEY_TYPES.NAMESPACE]: null,
144
- [CODE_ATTRIBUTES_KEY_TYPES.STACKTRACE]: null,
145
- },
146
- };
147
- const useInstrumentationRuleFormData = () => {
148
- const { addNotification } = useNotificationStore();
149
- const { formData, formErrors, handleFormChange, handleErrorChange, resetFormData } = useGenericForm(INITIAL);
150
- const validateForm = (params) => {
151
- const errors = {};
152
- let ok = true;
153
- handleErrorChange(undefined, undefined, errors);
154
- return ok;
155
- };
156
- const loadFormWithDrawerItem = ({ ruleName, notes, disabled, payloadCollection, codeAttributes }) => {
157
- const updatedData = {
158
- ...INITIAL,
159
- ruleName,
160
- notes,
161
- disabled,
162
- };
163
- if (payloadCollection) {
164
- updatedData['payloadCollection'] = {
165
- [PAYLOAD_COLLECTION_KEY_TYPES.HTTP_REQUEST]: !!payloadCollection[PAYLOAD_COLLECTION_KEY_TYPES.HTTP_REQUEST] ? {} : null,
166
- [PAYLOAD_COLLECTION_KEY_TYPES.HTTP_RESPONSE]: !!payloadCollection[PAYLOAD_COLLECTION_KEY_TYPES.HTTP_RESPONSE] ? {} : null,
167
- [PAYLOAD_COLLECTION_KEY_TYPES.DB_QUERY]: !!payloadCollection[PAYLOAD_COLLECTION_KEY_TYPES.DB_QUERY] ? {} : null,
168
- [PAYLOAD_COLLECTION_KEY_TYPES.MESSAGING]: !!payloadCollection[PAYLOAD_COLLECTION_KEY_TYPES.MESSAGING] ? {} : null,
169
- };
170
- }
171
- if (codeAttributes) {
172
- updatedData['codeAttributes'] = {
173
- [CODE_ATTRIBUTES_KEY_TYPES.COLUMN]: codeAttributes[CODE_ATTRIBUTES_KEY_TYPES.COLUMN] || null,
174
- [CODE_ATTRIBUTES_KEY_TYPES.FILE_PATH]: codeAttributes[CODE_ATTRIBUTES_KEY_TYPES.FILE_PATH] || null,
175
- [CODE_ATTRIBUTES_KEY_TYPES.FUNCTION]: codeAttributes[CODE_ATTRIBUTES_KEY_TYPES.FUNCTION] || null,
176
- [CODE_ATTRIBUTES_KEY_TYPES.LINE_NUMBER]: codeAttributes[CODE_ATTRIBUTES_KEY_TYPES.LINE_NUMBER] || null,
177
- [CODE_ATTRIBUTES_KEY_TYPES.NAMESPACE]: codeAttributes[CODE_ATTRIBUTES_KEY_TYPES.NAMESPACE] || null,
178
- [CODE_ATTRIBUTES_KEY_TYPES.STACKTRACE]: codeAttributes[CODE_ATTRIBUTES_KEY_TYPES.STACKTRACE] || null,
179
- };
180
- }
181
- handleFormChange(undefined, undefined, updatedData);
182
- };
183
- return {
184
- formData,
185
- formErrors,
186
- handleFormChange,
187
- resetFormData,
188
- validateForm,
189
- loadFormWithDrawerItem,
190
- };
191
- };
192
-
193
- const useKeyDown = ({ active, key, withAltKey, withCtrlKey, withShiftKey, withMetaKey }, callback) => {
194
- useEffect(() => {
195
- const handleKeyDown = (e) => {
196
- if (active &&
197
- key === e.key &&
198
- (!withAltKey || (withAltKey && e.altKey)) &&
199
- (!withCtrlKey || (withCtrlKey && e.ctrlKey)) &&
200
- (!withShiftKey || (withShiftKey && e.shiftKey)) &&
201
- (!withMetaKey || (withMetaKey && e.metaKey))) {
202
- e.preventDefault();
203
- e.stopPropagation();
204
- callback(e);
205
- }
206
- };
207
- window.addEventListener('keydown', handleKeyDown);
208
- return () => {
209
- window.removeEventListener('keydown', handleKeyDown);
210
- };
211
- }, [key, active, withAltKey, withCtrlKey, withShiftKey, withMetaKey, callback]);
212
- return null;
213
- };
214
-
215
- const useOnClickOutside = (ref, handler) => {
216
- useEffect(() => {
217
- const listener = (event) => {
218
- // Do nothing if clicking ref's element or descendent elements
219
- if (!ref.current || ref.current.contains(event.target)) {
220
- return;
221
- }
222
- handler();
223
- };
224
- document.addEventListener('mousedown', listener);
225
- document.addEventListener('touchstart', listener);
226
- return () => {
227
- document.removeEventListener('mousedown', listener);
228
- document.removeEventListener('touchstart', listener);
229
- };
230
- }, [ref, handler]);
231
- };
232
-
233
- // Fallback locale.
234
- // (when not a single one of the supplied "preferred" locales is available)
235
- var defaultLocale$1 = 'en'; // For all locales added
236
- // their relative time formatter messages will be stored here.
237
-
238
- var localesData$1 = {}; // According to the spec BCP 47 language tags are case-insensitive.
239
- // https://tools.ietf.org/html/rfc5646
240
-
241
- var lowercaseLocaleLookup = {};
242
- function getDefaultLocale() {
243
- return defaultLocale$1;
244
- }
245
- function setDefaultLocale(locale) {
246
- defaultLocale$1 = locale;
247
- }
248
- /**
249
- * Gets locale data previously added by `addLocaleData()`.
250
- * @return {object} [localeData]
251
- */
252
-
253
- function getLocaleData$1(locale) {
254
- return localesData$1[locale];
255
- }
256
- /**
257
- * Adds locale data.
258
- * Is called by `RelativeTimeFormat.addLocale(...)`.
259
- * @param {object} localeData
260
- */
261
-
262
- function addLocaleData$1(localeData) {
263
- if (!localeData) {
264
- throw new Error('No locale data passed');
265
- } // This locale data is stored in a global variable
266
- // and later used when calling `.format(time)`.
267
-
268
-
269
- localesData$1[localeData.locale] = localeData;
270
- lowercaseLocaleLookup[localeData.locale.toLowerCase()] = localeData.locale;
271
- }
272
- /**
273
- * Returns a locale for which locale data has been added
274
- * via `RelativeTimeFormat.addLocale(...)`.
275
- * @param {string} locale
276
- * @return {string} [locale]
277
- */
278
-
279
- function resolveLocale$1(locale) {
280
- if (localesData$1[locale]) {
281
- return locale;
282
- }
283
-
284
- if (lowercaseLocaleLookup[locale.toLowerCase()]) {
285
- return lowercaseLocaleLookup[locale.toLowerCase()];
286
- }
287
- }
288
-
289
- /**
290
- * Resolves a locale to a supported one (if any).
291
- * @param {string} locale
292
- * @param {Object} [options] - An object that may have the following property:
293
- * @param {string} [options.localeMatcher="lookup"] - The locale matching algorithm to use. Possible values are "lookup" and "best fit". Currently only "lookup" is supported.
294
- * @return {string} [locale]
295
- * @example
296
- * // Returns "sr"
297
- * resolveLocale("sr-Cyrl-BA")
298
- * // Returns `undefined`
299
- * resolveLocale("xx-Latn")
300
- */
301
-
302
- function resolveLocale(locale) {
303
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
304
- var localeMatcher = options.localeMatcher || 'lookup';
305
-
306
- switch (localeMatcher) {
307
- case 'lookup':
308
- return resolveLocaleLookup(locale);
309
- // "best fit" locale matching is not supported.
310
- // https://github.com/catamphetamine/relative-time-format/issues/2
311
-
312
- case 'best fit':
313
- // return resolveLocaleBestFit(locale)
314
- return resolveLocaleLookup(locale);
315
-
316
- default:
317
- throw new RangeError("Invalid \"localeMatcher\" option: ".concat(localeMatcher));
318
- }
319
- }
320
- /**
321
- * Resolves a locale to a supported one (if any).
322
- * Starts from the most specific locale and gradually
323
- * falls back to less specific ones.
324
- * This is a basic implementation of the "lookup" algorithm.
325
- * https://tools.ietf.org/html/rfc4647#section-3.4
326
- * @param {string} locale
327
- * @return {string} [locale]
328
- * @example
329
- * // Returns "sr"
330
- * resolveLocaleLookup("sr-Cyrl-BA")
331
- * // Returns `undefined`
332
- * resolveLocaleLookup("xx-Latn")
333
- */
334
-
335
- function resolveLocaleLookup(locale) {
336
- var resolvedLocale = resolveLocale$1(locale);
337
-
338
- if (resolvedLocale) {
339
- return resolvedLocale;
340
- } // `sr-Cyrl-BA` -> `sr-Cyrl` -> `sr`.
341
-
342
-
343
- var parts = locale.split('-');
344
-
345
- while (locale.length > 1) {
346
- parts.pop();
347
- locale = parts.join('-');
348
-
349
- var _resolvedLocale = resolveLocale$1(locale);
350
-
351
- if (_resolvedLocale) {
352
- return _resolvedLocale;
353
- }
354
- }
355
- }
356
-
357
- // (this file was autogenerated by `generate-locales`)
358
- // "plural rules" functions are not stored in locale JSON files because they're not strings.
359
- // This file isn't big — it's about 5 kilobytes in size (minified).
360
- // Alternatively, the pluralization rules for each locale could be stored
361
- // in their JSON files in a non-parsed form and later parsed via `make-plural` library.
362
- // But `make-plural` library itself is relatively big in size:
363
- // `make-plural.min.js` is about 6 kilobytes (https://unpkg.com/make-plural/).
364
- // So, it's more practical to bypass runtime `make-plural` pluralization rules compilation
365
- // and just include the already compiled pluarlization rules for all locales in the library code.
366
- var $ = {
367
- af: function af(n) {
368
- return n == 1 ? 'one' : 'other';
369
- },
370
- am: function am(n) {
371
- return n >= 0 && n <= 1 ? 'one' : 'other';
372
- },
373
- ar: function ar(n) {
374
- var s = String(n).split('.'),
375
- t0 = Number(s[0]) == n,
376
- n100 = t0 && s[0].slice(-2);
377
- return n == 0 ? 'zero' : n == 1 ? 'one' : n == 2 ? 'two' : n100 >= 3 && n100 <= 10 ? 'few' : n100 >= 11 && n100 <= 99 ? 'many' : 'other';
378
- },
379
- ast: function ast(n) {
380
- var s = String(n).split('.'),
381
- v0 = !s[1];
382
- return n == 1 && v0 ? 'one' : 'other';
383
- },
384
- be: function be(n) {
385
- var s = String(n).split('.'),
386
- t0 = Number(s[0]) == n,
387
- n10 = t0 && s[0].slice(-1),
388
- n100 = t0 && s[0].slice(-2);
389
- return n10 == 1 && n100 != 11 ? 'one' : n10 >= 2 && n10 <= 4 && (n100 < 12 || n100 > 14) ? 'few' : t0 && n10 == 0 || n10 >= 5 && n10 <= 9 || n100 >= 11 && n100 <= 14 ? 'many' : 'other';
390
- },
391
- br: function br(n) {
392
- var s = String(n).split('.'),
393
- t0 = Number(s[0]) == n,
394
- n10 = t0 && s[0].slice(-1),
395
- n100 = t0 && s[0].slice(-2),
396
- n1000000 = t0 && s[0].slice(-6);
397
- return n10 == 1 && n100 != 11 && n100 != 71 && n100 != 91 ? 'one' : n10 == 2 && n100 != 12 && n100 != 72 && n100 != 92 ? 'two' : (n10 == 3 || n10 == 4 || n10 == 9) && (n100 < 10 || n100 > 19) && (n100 < 70 || n100 > 79) && (n100 < 90 || n100 > 99) ? 'few' : n != 0 && t0 && n1000000 == 0 ? 'many' : 'other';
398
- },
399
- bs: function bs(n) {
400
- var s = String(n).split('.'),
401
- i = s[0],
402
- f = s[1] || '',
403
- v0 = !s[1],
404
- i10 = i.slice(-1),
405
- i100 = i.slice(-2),
406
- f10 = f.slice(-1),
407
- f100 = f.slice(-2);
408
- return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) || f10 >= 2 && f10 <= 4 && (f100 < 12 || f100 > 14) ? 'few' : 'other';
409
- },
410
- ca: function ca(n) {
411
- var s = String(n).split('.'),
412
- i = s[0],
413
- v0 = !s[1],
414
- i1000000 = i.slice(-6);
415
- return n == 1 && v0 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
416
- },
417
- ceb: function ceb(n) {
418
- var s = String(n).split('.'),
419
- i = s[0],
420
- f = s[1] || '',
421
- v0 = !s[1],
422
- i10 = i.slice(-1),
423
- f10 = f.slice(-1);
424
- return v0 && (i == 1 || i == 2 || i == 3) || v0 && i10 != 4 && i10 != 6 && i10 != 9 || !v0 && f10 != 4 && f10 != 6 && f10 != 9 ? 'one' : 'other';
425
- },
426
- cs: function cs(n) {
427
- var s = String(n).split('.'),
428
- i = s[0],
429
- v0 = !s[1];
430
- return n == 1 && v0 ? 'one' : i >= 2 && i <= 4 && v0 ? 'few' : !v0 ? 'many' : 'other';
431
- },
432
- cy: function cy(n) {
433
- return n == 0 ? 'zero' : n == 1 ? 'one' : n == 2 ? 'two' : n == 3 ? 'few' : n == 6 ? 'many' : 'other';
434
- },
435
- da: function da(n) {
436
- var s = String(n).split('.'),
437
- i = s[0],
438
- t0 = Number(s[0]) == n;
439
- return n == 1 || !t0 && (i == 0 || i == 1) ? 'one' : 'other';
440
- },
441
- dsb: function dsb(n) {
442
- var s = String(n).split('.'),
443
- i = s[0],
444
- f = s[1] || '',
445
- v0 = !s[1],
446
- i100 = i.slice(-2),
447
- f100 = f.slice(-2);
448
- return v0 && i100 == 1 || f100 == 1 ? 'one' : v0 && i100 == 2 || f100 == 2 ? 'two' : v0 && (i100 == 3 || i100 == 4) || f100 == 3 || f100 == 4 ? 'few' : 'other';
449
- },
450
- dz: function dz(n) {
451
- return 'other';
452
- },
453
- es: function es(n) {
454
- var s = String(n).split('.'),
455
- i = s[0],
456
- v0 = !s[1],
457
- i1000000 = i.slice(-6);
458
- return n == 1 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
459
- },
460
- ff: function ff(n) {
461
- return n >= 0 && n < 2 ? 'one' : 'other';
462
- },
463
- fr: function fr(n) {
464
- var s = String(n).split('.'),
465
- i = s[0],
466
- v0 = !s[1],
467
- i1000000 = i.slice(-6);
468
- return n >= 0 && n < 2 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
469
- },
470
- ga: function ga(n) {
471
- var s = String(n).split('.'),
472
- t0 = Number(s[0]) == n;
473
- return n == 1 ? 'one' : n == 2 ? 'two' : t0 && n >= 3 && n <= 6 ? 'few' : t0 && n >= 7 && n <= 10 ? 'many' : 'other';
474
- },
475
- gd: function gd(n) {
476
- var s = String(n).split('.'),
477
- t0 = Number(s[0]) == n;
478
- return n == 1 || n == 11 ? 'one' : n == 2 || n == 12 ? 'two' : t0 && n >= 3 && n <= 10 || t0 && n >= 13 && n <= 19 ? 'few' : 'other';
479
- },
480
- he: function he(n) {
481
- var s = String(n).split('.'),
482
- i = s[0],
483
- v0 = !s[1];
484
- return i == 1 && v0 || i == 0 && !v0 ? 'one' : i == 2 && v0 ? 'two' : 'other';
485
- },
486
- is: function is(n) {
487
- var s = String(n).split('.'),
488
- i = s[0],
489
- t = (s[1] || '').replace(/0+$/, ''),
490
- t0 = Number(s[0]) == n,
491
- i10 = i.slice(-1),
492
- i100 = i.slice(-2);
493
- return t0 && i10 == 1 && i100 != 11 || t % 10 == 1 && t % 100 != 11 ? 'one' : 'other';
494
- },
495
- ksh: function ksh(n) {
496
- return n == 0 ? 'zero' : n == 1 ? 'one' : 'other';
497
- },
498
- lt: function lt(n) {
499
- var s = String(n).split('.'),
500
- f = s[1] || '',
501
- t0 = Number(s[0]) == n,
502
- n10 = t0 && s[0].slice(-1),
503
- n100 = t0 && s[0].slice(-2);
504
- return n10 == 1 && (n100 < 11 || n100 > 19) ? 'one' : n10 >= 2 && n10 <= 9 && (n100 < 11 || n100 > 19) ? 'few' : f != 0 ? 'many' : 'other';
505
- },
506
- lv: function lv(n) {
507
- var s = String(n).split('.'),
508
- f = s[1] || '',
509
- v = f.length,
510
- t0 = Number(s[0]) == n,
511
- n10 = t0 && s[0].slice(-1),
512
- n100 = t0 && s[0].slice(-2),
513
- f100 = f.slice(-2),
514
- f10 = f.slice(-1);
515
- return t0 && n10 == 0 || n100 >= 11 && n100 <= 19 || v == 2 && f100 >= 11 && f100 <= 19 ? 'zero' : n10 == 1 && n100 != 11 || v == 2 && f10 == 1 && f100 != 11 || v != 2 && f10 == 1 ? 'one' : 'other';
516
- },
517
- mk: function mk(n) {
518
- var s = String(n).split('.'),
519
- i = s[0],
520
- f = s[1] || '',
521
- v0 = !s[1],
522
- i10 = i.slice(-1),
523
- i100 = i.slice(-2),
524
- f10 = f.slice(-1),
525
- f100 = f.slice(-2);
526
- return v0 && i10 == 1 && i100 != 11 || f10 == 1 && f100 != 11 ? 'one' : 'other';
527
- },
528
- mt: function mt(n) {
529
- var s = String(n).split('.'),
530
- t0 = Number(s[0]) == n,
531
- n100 = t0 && s[0].slice(-2);
532
- return n == 1 ? 'one' : n == 2 ? 'two' : n == 0 || n100 >= 3 && n100 <= 10 ? 'few' : n100 >= 11 && n100 <= 19 ? 'many' : 'other';
533
- },
534
- pa: function pa(n) {
535
- return n == 0 || n == 1 ? 'one' : 'other';
536
- },
537
- pl: function pl(n) {
538
- var s = String(n).split('.'),
539
- i = s[0],
540
- v0 = !s[1],
541
- i10 = i.slice(-1),
542
- i100 = i.slice(-2);
543
- return n == 1 && v0 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) ? 'few' : v0 && i != 1 && (i10 == 0 || i10 == 1) || v0 && i10 >= 5 && i10 <= 9 || v0 && i100 >= 12 && i100 <= 14 ? 'many' : 'other';
544
- },
545
- pt: function pt(n) {
546
- var s = String(n).split('.'),
547
- i = s[0],
548
- v0 = !s[1],
549
- i1000000 = i.slice(-6);
550
- return i == 0 || i == 1 ? 'one' : i != 0 && i1000000 == 0 && v0 ? 'many' : 'other';
551
- },
552
- ro: function ro(n) {
553
- var s = String(n).split('.'),
554
- v0 = !s[1],
555
- t0 = Number(s[0]) == n,
556
- n100 = t0 && s[0].slice(-2);
557
- return n == 1 && v0 ? 'one' : !v0 || n == 0 || n != 1 && n100 >= 1 && n100 <= 19 ? 'few' : 'other';
558
- },
559
- ru: function ru(n) {
560
- var s = String(n).split('.'),
561
- i = s[0],
562
- v0 = !s[1],
563
- i10 = i.slice(-1),
564
- i100 = i.slice(-2);
565
- return v0 && i10 == 1 && i100 != 11 ? 'one' : v0 && i10 >= 2 && i10 <= 4 && (i100 < 12 || i100 > 14) ? 'few' : v0 && i10 == 0 || v0 && i10 >= 5 && i10 <= 9 || v0 && i100 >= 11 && i100 <= 14 ? 'many' : 'other';
566
- },
567
- se: function se(n) {
568
- return n == 1 ? 'one' : n == 2 ? 'two' : 'other';
569
- },
570
- si: function si(n) {
571
- var s = String(n).split('.'),
572
- i = s[0],
573
- f = s[1] || '';
574
- return n == 0 || n == 1 || i == 0 && f == 1 ? 'one' : 'other';
575
- },
576
- sl: function sl(n) {
577
- var s = String(n).split('.'),
578
- i = s[0],
579
- v0 = !s[1],
580
- i100 = i.slice(-2);
581
- return v0 && i100 == 1 ? 'one' : v0 && i100 == 2 ? 'two' : v0 && (i100 == 3 || i100 == 4) || !v0 ? 'few' : 'other';
582
- }
583
- };
584
- $.as = $.am;
585
- $.az = $.af;
586
- $.bg = $.af;
587
- $.bn = $.am;
588
- $.brx = $.af;
589
- $.ce = $.af;
590
- $.chr = $.af;
591
- $.de = $.ast;
592
- $.ee = $.af;
593
- $.el = $.af;
594
- $.en = $.ast;
595
- $.et = $.ast;
596
- $.eu = $.af;
597
- $.fa = $.am;
598
- $.fi = $.ast;
599
- $.fil = $.ceb;
600
- $.fo = $.af;
601
- $.fur = $.af;
602
- $.fy = $.ast;
603
- $.gl = $.ast;
604
- $.gu = $.am;
605
- $.ha = $.af;
606
- $.hi = $.am;
607
- $.hr = $.bs;
608
- $.hsb = $.dsb;
609
- $.hu = $.af;
610
- $.hy = $.ff;
611
- $.ia = $.ast;
612
- $.id = $.dz;
613
- $.ig = $.dz;
614
- $.it = $.ca;
615
- $.ja = $.dz;
616
- $.jgo = $.af;
617
- $.jv = $.dz;
618
- $.ka = $.af;
619
- $.kea = $.dz;
620
- $.kk = $.af;
621
- $.kl = $.af;
622
- $.km = $.dz;
623
- $.kn = $.am;
624
- $.ko = $.dz;
625
- $.ks = $.af;
626
- $.ku = $.af;
627
- $.ky = $.af;
628
- $.lb = $.af;
629
- $.lkt = $.dz;
630
- $.lo = $.dz;
631
- $.ml = $.af;
632
- $.mn = $.af;
633
- $.mr = $.af;
634
- $.ms = $.dz;
635
- $.my = $.dz;
636
- $.nb = $.af;
637
- $.ne = $.af;
638
- $.nl = $.ast;
639
- $.nn = $.af;
640
- $.no = $.af;
641
- $.or = $.af;
642
- $.pcm = $.am;
643
- $.ps = $.af;
644
- $.rm = $.af;
645
- $.sah = $.dz;
646
- $.sc = $.ast;
647
- $.sd = $.af;
648
- $.sk = $.cs;
649
- $.so = $.af;
650
- $.sq = $.af;
651
- $.sr = $.bs;
652
- $.su = $.dz;
653
- $.sv = $.ast;
654
- $.sw = $.ast;
655
- $.ta = $.af;
656
- $.te = $.af;
657
- $.th = $.dz;
658
- $.ti = $.pa;
659
- $.tk = $.af;
660
- $.to = $.dz;
661
- $.tr = $.af;
662
- $.ug = $.af;
663
- $.uk = $.ru;
664
- $.ur = $.ast;
665
- $.uz = $.af;
666
- $.vi = $.dz;
667
- $.wae = $.af;
668
- $.wo = $.dz;
669
- $.xh = $.af;
670
- $.yi = $.ast;
671
- $.yo = $.dz;
672
- $.yue = $.dz;
673
- $.zh = $.dz;
674
- $.zu = $.am;
675
-
676
- /**
677
- * Returns a `locale` for which a function exists in `./PluralRuleFunctions.js`.
678
- * @param {string} locale
679
- * @return {string}
680
- * @example
681
- * getPluralRulesLocale("ru-RU-Cyrl") // Returns "ru".
682
- */
683
- function getPluralRulesLocale(locale) {
684
- // "pt" language is the only one having different pluralization rules
685
- // for the one ("pt") (Portuguese) locale and the other ("pt-PT") (European Portuguese).
686
- // http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html
687
- // (see the entries for "pt" and "pt_PT" there)
688
- if (locale === 'pt-PT') {
689
- return locale;
690
- }
691
-
692
- return getLanguageFromLanguageTag(locale);
693
- }
694
- /**
695
- * Extracts language from an IETF BCP 47 language tag.
696
- * @param {string} languageTag - IETF BCP 47 language tag.
697
- * @return {string}
698
- * @example
699
- * // Returns "he"
700
- * getLanguageFromLanguageTag("he-IL-u-ca-hebrew-tz-jeruslm")
701
- * // Returns "ar"
702
- * getLanguageFromLanguageTag("ar-u-nu-latn")
703
- */
704
-
705
- var LANGUAGE_REG_EXP = /^([a-z0-9]+)/i;
706
-
707
- function getLanguageFromLanguageTag(languageTag) {
708
- var match = languageTag.match(LANGUAGE_REG_EXP);
709
-
710
- if (!match) {
711
- throw new TypeError("Invalid locale: ".concat(languageTag));
712
- }
713
-
714
- return match[1];
715
- }
716
-
717
- function _classCallCheck$3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
718
-
719
- function _defineProperties$3(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
720
-
721
- function _createClass$3(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$3(Constructor.prototype, protoProps); if (staticProps) _defineProperties$3(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
722
- /**
723
- * `Intl.PluralRules` polyfill.
724
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules
725
- */
726
-
727
- var PluralRules = /*#__PURE__*/function () {
728
- function PluralRules(locale, options) {
729
- _classCallCheck$3(this, PluralRules);
730
-
731
- var locales = PluralRules.supportedLocalesOf(locale);
732
-
733
- if (locales.length === 0) {
734
- throw new RangeError("Unsupported locale: " + locale);
735
- }
736
-
737
- if (options && options.type !== "cardinal") {
738
- throw new RangeError("Only \"cardinal\" \"type\" is supported");
739
- }
740
-
741
- this.$ = $[getPluralRulesLocale(locales[0])];
742
- }
743
-
744
- _createClass$3(PluralRules, [{
745
- key: "select",
746
- value: function select(number) {
747
- return this.$(number);
748
- }
749
- }], [{
750
- key: "supportedLocalesOf",
751
- value: function supportedLocalesOf(locales) {
752
- if (typeof locales === "string") {
753
- locales = [locales];
754
- }
755
-
756
- return locales.filter(function (locale) {
757
- return $[getPluralRulesLocale(locale)];
758
- });
759
- }
760
- }]);
761
-
762
- return PluralRules;
763
- }();
764
-
765
- function _typeof$5(obj) { "@babel/helpers - typeof"; return _typeof$5 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof$5(obj); }
766
-
767
- function ownKeys$9(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
768
-
769
- function _objectSpread$9(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$9(Object(source), true).forEach(function (key) { _defineProperty$9(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$9(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
770
-
771
- function _defineProperty$9(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
772
-
773
- function _slicedToArray$1(arr, i) { return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _unsupportedIterableToArray$2(arr, i) || _nonIterableRest$1(); }
774
-
775
- function _nonIterableRest$1() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
776
-
777
- function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen); }
778
-
779
- function _arrayLikeToArray$2(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
780
-
781
- function _iterableToArrayLimit$1(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
782
-
783
- function _arrayWithHoles$1(arr) { if (Array.isArray(arr)) return arr; }
784
-
785
- function _classCallCheck$2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
786
-
787
- function _defineProperties$2(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
788
-
789
- function _createClass$2(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$2(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
790
- // results in a bundle that is larger by 1kB for some reason.
791
- // import PluralRules from 'intl-plural-rules-polyfill/cardinal'
792
- // Valid time units.
793
-
794
- var UNITS = ["second", "minute", "hour", "day", "week", "month", "quarter", "year"]; // Valid values for the `numeric` option.
795
-
796
- var NUMERIC_VALUES = ["auto", "always"]; // Valid values for the `style` option.
797
-
798
- var STYLE_VALUES = ["long", "short", "narrow"]; // Valid values for the `localeMatcher` option.
799
-
800
- var LOCALE_MATCHER_VALUES = ["lookup", "best fit"];
801
- /**
802
- * Polyfill for `Intl.RelativeTimeFormat` proposal.
803
- * https://github.com/tc39/proposal-intl-relative-time
804
- * https://github.com/tc39/proposal-intl-relative-time/issues/55
805
- */
806
-
807
- var RelativeTimeFormat = /*#__PURE__*/function () {
808
- /**
809
- * @param {(string|string[])} [locales] - Preferred locales (or locale).
810
- * @param {Object} [options] - Formatting options.
811
- * @param {string} [options.style="long"] - One of: "long", "short", "narrow".
812
- * @param {string} [options.numeric="always"] - (Version >= 2) One of: "always", "auto".
813
- * @param {string} [options.localeMatcher="lookup"] - One of: "lookup", "best fit". Currently only "lookup" is supported.
814
- */
815
- function RelativeTimeFormat() {
816
- var locales = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
817
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
818
-
819
- _classCallCheck$2(this, RelativeTimeFormat);
820
-
821
- var numeric = options.numeric,
822
- style = options.style,
823
- localeMatcher = options.localeMatcher;
824
- this.numeric = "always";
825
- this.style = "long";
826
- this.localeMatcher = "lookup"; // Set `numeric` option.
827
-
828
- if (numeric !== undefined) {
829
- if (NUMERIC_VALUES.indexOf(numeric) < 0) {
830
- throw new RangeError("Invalid \"numeric\" option: ".concat(numeric));
831
- }
832
-
833
- this.numeric = numeric;
834
- } // Set `style` option.
835
-
836
-
837
- if (style !== undefined) {
838
- if (STYLE_VALUES.indexOf(style) < 0) {
839
- throw new RangeError("Invalid \"style\" option: ".concat(style));
840
- }
841
-
842
- this.style = style;
843
- } // Set `localeMatcher` option.
844
-
845
-
846
- if (localeMatcher !== undefined) {
847
- if (LOCALE_MATCHER_VALUES.indexOf(localeMatcher) < 0) {
848
- throw new RangeError("Invalid \"localeMatcher\" option: ".concat(localeMatcher));
849
- }
850
-
851
- this.localeMatcher = localeMatcher;
852
- } // Set `locale`.
853
- // Convert `locales` to an array.
854
-
855
-
856
- if (typeof locales === 'string') {
857
- locales = [locales];
858
- } // Add default locale.
859
-
860
-
861
- locales.push(getDefaultLocale()); // Choose the most appropriate locale.
862
-
863
- this.locale = RelativeTimeFormat.supportedLocalesOf(locales, {
864
- localeMatcher: this.localeMatcher
865
- })[0];
866
-
867
- if (!this.locale) {
868
- throw new Error("No supported locale was found");
869
- } // Construct an `Intl.PluralRules` instance (polyfill).
870
-
871
-
872
- if (PluralRules.supportedLocalesOf(this.locale).length > 0) {
873
- this.pluralRules = new PluralRules(this.locale);
874
- } else {
875
- console.warn("\"".concat(this.locale, "\" locale is not supported"));
876
- } // Use `Intl.NumberFormat` for formatting numbers (when available).
877
-
878
-
879
- if (typeof Intl !== 'undefined' && Intl.NumberFormat) {
880
- this.numberFormat = new Intl.NumberFormat(this.locale);
881
- this.numberingSystem = this.numberFormat.resolvedOptions().numberingSystem;
882
- } else {
883
- this.numberingSystem = 'latn';
884
- }
885
-
886
- this.locale = resolveLocale(this.locale, {
887
- localeMatcher: this.localeMatcher
888
- });
889
- }
890
- /**
891
- * Formats time `number` in `units` (either in past or in future).
892
- * @param {number} number - Time interval value.
893
- * @param {string} unit - Time interval measurement unit.
894
- * @return {string}
895
- * @throws {RangeError} If unit is not one of "second", "minute", "hour", "day", "week", "month", "quarter".
896
- * @example
897
- * // Returns "2 days ago"
898
- * rtf.format(-2, "day")
899
- * // Returns "in 5 minutes"
900
- * rtf.format(5, "minute")
901
- */
902
-
903
-
904
- _createClass$2(RelativeTimeFormat, [{
905
- key: "format",
906
- value: function format() {
907
- var _parseFormatArgs = parseFormatArgs(arguments),
908
- _parseFormatArgs2 = _slicedToArray$1(_parseFormatArgs, 2),
909
- number = _parseFormatArgs2[0],
910
- unit = _parseFormatArgs2[1];
911
-
912
- return this.getRule(number, unit).replace('{0}', this.formatNumber(Math.abs(number)));
913
- }
914
- /**
915
- * Formats time `number` in `units` (either in past or in future).
916
- * @param {number} number - Time interval value.
917
- * @param {string} unit - Time interval measurement unit.
918
- * @return {Object[]} The parts (`{ type, value, unit? }`).
919
- * @throws {RangeError} If unit is not one of "second", "minute", "hour", "day", "week", "month", "quarter".
920
- * @example
921
- * // Version 1 (deprecated).
922
- * // Returns [
923
- * // { type: "literal", value: "in " },
924
- * // { type: "day", value: "100" },
925
- * // { type: "literal", value: " days" }
926
- * // ]
927
- * rtf.formatToParts(100, "day")
928
- * //
929
- * // Version 2.
930
- * // Returns [
931
- * // { type: "literal", value: "in " },
932
- * // { type: "integer", value: "100", unit: "day" },
933
- * // { type: "literal", value: " days" }
934
- * // ]
935
- * rtf.formatToParts(100, "day")
936
- */
937
-
938
- }, {
939
- key: "formatToParts",
940
- value: function formatToParts() {
941
- var _parseFormatArgs3 = parseFormatArgs(arguments),
942
- _parseFormatArgs4 = _slicedToArray$1(_parseFormatArgs3, 2),
943
- number = _parseFormatArgs4[0],
944
- unit = _parseFormatArgs4[1];
945
-
946
- var rule = this.getRule(number, unit);
947
- var valueIndex = rule.indexOf("{0}"); // "yesterday"/"today"/"tomorrow".
948
-
949
- if (valueIndex < 0) {
950
- return [{
951
- type: "literal",
952
- value: rule
953
- }];
954
- }
955
-
956
- var parts = [];
957
-
958
- if (valueIndex > 0) {
959
- parts.push({
960
- type: "literal",
961
- value: rule.slice(0, valueIndex)
962
- });
963
- }
964
-
965
- parts = parts.concat(this.formatNumberToParts(Math.abs(number)).map(function (part) {
966
- return _objectSpread$9(_objectSpread$9({}, part), {}, {
967
- unit: unit
968
- });
969
- }));
970
-
971
- if (valueIndex + "{0}".length < rule.length - 1) {
972
- parts.push({
973
- type: "literal",
974
- value: rule.slice(valueIndex + "{0}".length)
975
- });
976
- }
977
-
978
- return parts;
979
- }
980
- /**
981
- * Returns formatting rule for `value` in `units` (either in past or in future).
982
- * @param {number} value - Time interval value.
983
- * @param {string} unit - Time interval measurement unit.
984
- * @return {string}
985
- * @throws {RangeError} If unit is not one of "second", "minute", "hour", "day", "week", "month", "quarter".
986
- * @example
987
- * // Returns "{0} days ago"
988
- * getRule(-2, "day")
989
- */
990
-
991
- }, {
992
- key: "getRule",
993
- value: function getRule(value, unit) {
994
- // Get locale-specific time interval formatting rules
995
- // of a given `style` for the given value of measurement `unit`.
996
- //
997
- // E.g.:
998
- //
999
- // ```json
1000
- // {
1001
- // "past": {
1002
- // "one": "a second ago",
1003
- // "other": "{0} seconds ago"
1004
- // },
1005
- // "future": {
1006
- // "one": "in a second",
1007
- // "other": "in {0} seconds"
1008
- // }
1009
- // }
1010
- // ```
1011
- //
1012
- var unitMessages = getLocaleData$1(this.locale)[this.style][unit]; // Bundle size optimization technique for styles like
1013
- // "tiny" in `javascript-time-ago`: "1m", "2h", "3d"...
1014
-
1015
- if (typeof unitMessages === 'string') {
1016
- return unitMessages;
1017
- } // Special case for "yesterday"/"today"/"tomorrow".
1018
-
1019
-
1020
- if (this.numeric === "auto") {
1021
- // "yesterday", "the day before yesterday", etc.
1022
- if (value === -2 || value === -1) {
1023
- var message = unitMessages["previous".concat(value === -1 ? '' : '-' + Math.abs(value))];
1024
-
1025
- if (message) {
1026
- return message;
1027
- }
1028
- } // "tomorrow", "the day after tomorrow", etc.
1029
- else if (value === 1 || value === 2) {
1030
- var _message = unitMessages["next".concat(value === 1 ? '' : '-' + Math.abs(value))];
1031
-
1032
- if (_message) {
1033
- return _message;
1034
- }
1035
- } // "today"
1036
- else if (value === 0) {
1037
- if (unitMessages.current) {
1038
- return unitMessages.current;
1039
- }
1040
- }
1041
- } // Choose either "past" or "future" based on time `value` sign.
1042
- // If there's only "other" then it's being collapsed.
1043
- // (the resulting bundle size optimization technique)
1044
-
1045
-
1046
- var pluralizedMessages = unitMessages[isNegative(value) ? "past" : "future"]; // Bundle size optimization technique for styles like "narrow"
1047
- // having messages like "in {0} d." or "{0} d. ago".
1048
-
1049
- if (typeof pluralizedMessages === "string") {
1050
- return pluralizedMessages;
1051
- } // Quantify `value`.
1052
- // There seems to be no such locale in CLDR
1053
- // for which "plural rules" function is missing.
1054
-
1055
-
1056
- var quantifier = this.pluralRules && this.pluralRules.select(Math.abs(value)) || 'other'; // "other" rule is supposed to be always present.
1057
- // If only "other" rule is present then "rules" is not an object and is a string.
1058
-
1059
- return pluralizedMessages[quantifier] || pluralizedMessages.other;
1060
- }
1061
- /**
1062
- * Formats a number into a string.
1063
- * Uses `Intl.NumberFormat` when available.
1064
- * @param {number} number
1065
- * @return {string}
1066
- */
1067
-
1068
- }, {
1069
- key: "formatNumber",
1070
- value: function formatNumber(number) {
1071
- return this.numberFormat ? this.numberFormat.format(number) : String(number);
1072
- }
1073
- /**
1074
- * Formats a number into a list of parts.
1075
- * Uses `Intl.NumberFormat` when available.
1076
- * @param {number} number
1077
- * @return {object[]}
1078
- */
1079
-
1080
- }, {
1081
- key: "formatNumberToParts",
1082
- value: function formatNumberToParts(number) {
1083
- // `Intl.NumberFormat.formatToParts()` is not present, for example,
1084
- // in Node.js 8.x while `Intl.NumberFormat` itself is present.
1085
- return this.numberFormat && this.numberFormat.formatToParts ? this.numberFormat.formatToParts(number) : [{
1086
- type: "integer",
1087
- value: this.formatNumber(number)
1088
- }];
1089
- }
1090
- /**
1091
- * Returns a new object with properties reflecting the locale and date and time formatting options computed during initialization of this DateTimeFormat object.
1092
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/resolvedOptions
1093
- * @return {Object}
1094
- */
1095
-
1096
- }, {
1097
- key: "resolvedOptions",
1098
- value: function resolvedOptions() {
1099
- return {
1100
- locale: this.locale,
1101
- style: this.style,
1102
- numeric: this.numeric,
1103
- numberingSystem: this.numberingSystem
1104
- };
1105
- }
1106
- }]);
1107
-
1108
- return RelativeTimeFormat;
1109
- }();
1110
-
1111
- RelativeTimeFormat.supportedLocalesOf = function (locales) {
1112
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1113
-
1114
- // Convert `locales` to an array.
1115
- if (typeof locales === 'string') {
1116
- locales = [locales];
1117
- } else if (!Array.isArray(locales)) {
1118
- throw new TypeError('Invalid "locales" argument');
1119
- }
1120
-
1121
- return locales.filter(function (locale) {
1122
- return resolveLocale(locale, options);
1123
- });
1124
- };
1125
- /**
1126
- * Adds locale data for a specific locale.
1127
- * @param {Object} localeData
1128
- */
1129
-
1130
-
1131
- RelativeTimeFormat.addLocale = addLocaleData$1;
1132
- /**
1133
- * Sets default locale.
1134
- * @param {string} locale
1135
- */
1136
-
1137
- RelativeTimeFormat.setDefaultLocale = setDefaultLocale;
1138
- /**
1139
- * Gets default locale.
1140
- * @return {string} locale
1141
- */
1142
-
1143
- RelativeTimeFormat.getDefaultLocale = getDefaultLocale;
1144
- /**
1145
- * Export `Intl.PluralRules` just in case it's used somewhere else.
1146
- */
1147
-
1148
- RelativeTimeFormat.PluralRules = PluralRules; // The specification allows units to be in plural form.
1149
- // Convert plural to singular.
1150
- // Example: "seconds" -> "second".
1151
-
1152
- var UNIT_ERROR = 'Invalid "unit" argument';
1153
-
1154
- function parseUnit(unit) {
1155
- if (_typeof$5(unit) === 'symbol') {
1156
- throw new TypeError(UNIT_ERROR);
1157
- }
1158
-
1159
- if (typeof unit !== 'string') {
1160
- throw new RangeError("".concat(UNIT_ERROR, ": ").concat(unit));
1161
- }
1162
-
1163
- if (unit[unit.length - 1] === 's') {
1164
- unit = unit.slice(0, unit.length - 1);
1165
- }
1166
-
1167
- if (UNITS.indexOf(unit) < 0) {
1168
- throw new RangeError("".concat(UNIT_ERROR, ": ").concat(unit));
1169
- }
1170
-
1171
- return unit;
1172
- } // Converts `value` to a `Number`.
1173
- // The specification allows value to be a non-number.
1174
- // For example, "-0" is supposed to be treated as `-0`.
1175
- // Also checks if `value` is a finite number.
1176
-
1177
-
1178
- var NUMBER_ERROR = 'Invalid "number" argument';
1179
-
1180
- function parseNumber(value) {
1181
- value = Number(value);
1182
-
1183
- if (Number.isFinite) {
1184
- if (!Number.isFinite(value)) {
1185
- throw new RangeError("".concat(NUMBER_ERROR, ": ").concat(value));
1186
- }
1187
- }
1188
-
1189
- return value;
1190
- }
1191
- /**
1192
- * Tells `0` from `-0`.
1193
- * https://stackoverflow.com/questions/7223359/are-0-and-0-the-same
1194
- * @param {number} number
1195
- * @return {Boolean}
1196
- * @example
1197
- * isNegativeZero(0); // false
1198
- * isNegativeZero(-0); // true
1199
- */
1200
-
1201
-
1202
- function isNegativeZero(number) {
1203
- return 1 / number === -Infinity;
1204
- }
1205
-
1206
- function isNegative(number) {
1207
- return number < 0 || number === 0 && isNegativeZero(number);
1208
- }
1209
-
1210
- function parseFormatArgs(args) {
1211
- if (args.length < 2) {
1212
- throw new TypeError("\"unit\" argument is required");
1213
- }
1214
-
1215
- return [parseNumber(args[0]), parseUnit(args[1])];
1216
- }
1217
-
1218
- function _typeof$4(obj) { "@babel/helpers - typeof"; return _typeof$4 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof$4(obj); }
1219
-
1220
- function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1221
-
1222
- function _defineProperties$1(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
1223
-
1224
- function _createClass$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
1225
-
1226
- /**
1227
- * A basic in-memory cache.
1228
- *
1229
- * import Cache from 'javascript-time-ago/Cache'
1230
- * const cache = new Cache()
1231
- * const object = cache.get('key1', 'key2', ...) || cache.put('key1', 'key2', ..., createObject())
1232
- */
1233
- var Cache = /*#__PURE__*/function () {
1234
- function Cache() {
1235
- _classCallCheck$1(this, Cache);
1236
-
1237
- this.cache = {};
1238
- }
1239
-
1240
- _createClass$1(Cache, [{
1241
- key: "get",
1242
- value: function get() {
1243
- var cache = this.cache;
1244
-
1245
- for (var _len = arguments.length, keys = new Array(_len), _key = 0; _key < _len; _key++) {
1246
- keys[_key] = arguments[_key];
1247
- }
1248
-
1249
- for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
1250
- var key = _keys[_i];
1251
-
1252
- if (_typeof$4(cache) !== 'object') {
1253
- return;
1254
- }
1255
-
1256
- cache = cache[key];
1257
- }
1258
-
1259
- return cache;
1260
- }
1261
- }, {
1262
- key: "put",
1263
- value: function put() {
1264
- for (var _len2 = arguments.length, keys = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
1265
- keys[_key2] = arguments[_key2];
1266
- }
1267
-
1268
- var value = keys.pop();
1269
- var lastKey = keys.pop();
1270
- var cache = this.cache;
1271
-
1272
- for (var _i2 = 0, _keys2 = keys; _i2 < _keys2.length; _i2++) {
1273
- var key = _keys2[_i2];
1274
-
1275
- if (_typeof$4(cache[key]) !== 'object') {
1276
- cache[key] = {};
1277
- }
1278
-
1279
- cache = cache[key];
1280
- }
1281
-
1282
- return cache[lastKey] = value;
1283
- }
1284
- }]);
1285
-
1286
- return Cache;
1287
- }();
1288
-
1289
- function _typeof$3(obj) { "@babel/helpers - typeof"; return _typeof$3 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof$3(obj); }
1290
-
1291
- function _createForOfIteratorHelperLoose$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike) { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
1292
-
1293
- function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
1294
-
1295
- function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
1296
-
1297
- /**
1298
- * Chooses the most appropriate locale
1299
- * (one of the registered ones)
1300
- * based on the list of preferred `locales` supplied by the user.
1301
- *
1302
- * @param {string[]} locales - the list of preferable locales (in [IETF format](https://en.wikipedia.org/wiki/IETF_language_tag)).
1303
- * @param {Function} isLocaleDataAvailable - tests if a locale is available.
1304
- *
1305
- * @returns {string} The most suitable locale.
1306
- *
1307
- * @example
1308
- * // Returns 'en'
1309
- * chooseLocale(['en-US'], undefined, (locale) => locale === 'ru' || locale === 'en')
1310
- */
1311
- function chooseLocale(locales, isLocaleDataAvailable) {
1312
- // This is not an intelligent algorithm,
1313
- // but it will do for this library's case.
1314
- // `sr-Cyrl-BA` -> `sr-Cyrl` -> `sr`.
1315
- for (var _iterator = _createForOfIteratorHelperLoose$1(locales), _step; !(_step = _iterator()).done;) {
1316
- var locale = _step.value;
1317
-
1318
- if (isLocaleDataAvailable(locale)) {
1319
- return locale;
1320
- }
1321
-
1322
- var parts = locale.split('-');
1323
-
1324
- while (parts.length > 1) {
1325
- parts.pop();
1326
- locale = parts.join('-');
1327
-
1328
- if (isLocaleDataAvailable(locale)) {
1329
- return locale;
1330
- }
1331
- }
1332
- }
1333
-
1334
- throw new Error("No locale data has been registered for any of the locales: ".concat(locales.join(', ')));
1335
- }
1336
- /**
1337
- * Whether can use `Intl.DateTimeFormat`.
1338
- * @return {boolean}
1339
- */
1340
-
1341
- function intlDateTimeFormatSupported() {
1342
- // Babel transforms `typeof` into some "branches"
1343
- // so istanbul will show this as "branch not covered".
1344
-
1345
- /* istanbul ignore next */
1346
- var isIntlAvailable = (typeof Intl === "undefined" ? "undefined" : _typeof$3(Intl)) === 'object';
1347
- return isIntlAvailable && typeof Intl.DateTimeFormat === 'function';
1348
- }
1349
-
1350
- function _typeof$2(obj) { "@babel/helpers - typeof"; return _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof$2(obj); }
1351
-
1352
- function isStyleObject(object) {
1353
- return isObject(object) && (Array.isArray(object.steps) || // `gradation` property is deprecated: it has been renamed to `steps`.
1354
- Array.isArray(object.gradation) || // `flavour` property is deprecated: it has been renamed to `labels`.
1355
- Array.isArray(object.flavour) || typeof object.flavour === 'string' || Array.isArray(object.labels) || typeof object.labels === 'string' || // `units` property is deprecated.
1356
- Array.isArray(object.units) || // `custom` property is deprecated.
1357
- typeof object.custom === 'function');
1358
- }
1359
- var OBJECT_CONSTRUCTOR = {}.constructor;
1360
-
1361
- function isObject(object) {
1362
- return _typeof$2(object) !== undefined && object !== null && object.constructor === OBJECT_CONSTRUCTOR;
1363
- }
1364
-
1365
- var minute = 60; // in seconds
1366
-
1367
- var hour = 60 * minute; // in seconds
1368
-
1369
- var day = 24 * hour; // in seconds
1370
-
1371
- var week = 7 * day; // in seconds
1372
- // https://www.quora.com/What-is-the-average-number-of-days-in-a-month
1373
-
1374
- var month = 30.44 * day; // in seconds
1375
- // "400 years have 146097 days (taking into account leap year rules)"
1376
-
1377
- var year = 146097 / 400 * day; // in seconds
1378
-
1379
- function getSecondsInUnit(unit) {
1380
- switch (unit) {
1381
- case 'second':
1382
- return 1;
1383
-
1384
- case 'minute':
1385
- return minute;
1386
-
1387
- case 'hour':
1388
- return hour;
1389
-
1390
- case 'day':
1391
- return day;
1392
-
1393
- case 'week':
1394
- return week;
1395
-
1396
- case 'month':
1397
- return month;
1398
-
1399
- case 'year':
1400
- return year;
1401
- }
1402
- } // export function getPreviousUnitFor(unit) {
1403
- // switch (unit) {
1404
- // case 'second':
1405
- // return 'now'
1406
- // case 'minute':
1407
- // return 'second'
1408
- // case 'hour':
1409
- // return 'minute'
1410
- // case 'day':
1411
- // return 'hour'
1412
- // case 'week':
1413
- // return 'day'
1414
- // case 'month':
1415
- // return 'week'
1416
- // case 'year':
1417
- // return 'month'
1418
- // }
1419
- // }
1420
-
1421
- function getStepDenominator(step) {
1422
- // `factor` is a legacy property.
1423
- if (step.factor !== undefined) {
1424
- return step.factor;
1425
- } // "unit" is now called "formatAs".
1426
-
1427
-
1428
- return getSecondsInUnit(step.unit || step.formatAs) || 1;
1429
- }
1430
-
1431
- function getRoundFunction(round) {
1432
- switch (round) {
1433
- case 'floor':
1434
- return Math.floor;
1435
-
1436
- default:
1437
- return Math.round;
1438
- }
1439
- } // For non-negative numbers.
1440
-
1441
- function getDiffRatioToNextRoundedNumber(round) {
1442
- switch (round) {
1443
- case 'floor':
1444
- // Math.floor(x) = x
1445
- // Math.floor(x + 1) = x + 1
1446
- return 1;
1447
-
1448
- default:
1449
- // Math.round(x) = x
1450
- // Math.round(x + 0.5) = x + 1
1451
- return 0.5;
1452
- }
1453
- }
1454
-
1455
- function _typeof$1(obj) { "@babel/helpers - typeof"; return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof$1(obj); }
1456
- function getStepMinTime(step, _ref) {
1457
- var prevStep = _ref.prevStep,
1458
- timestamp = _ref.timestamp,
1459
- now = _ref.now,
1460
- future = _ref.future,
1461
- round = _ref.round;
1462
- var minTime; // "threshold_for_xxx" is a legacy property.
1463
-
1464
- if (prevStep) {
1465
- if (prevStep.id || prevStep.unit) {
1466
- minTime = step["threshold_for_".concat(prevStep.id || prevStep.unit)];
1467
- }
1468
- }
1469
-
1470
- if (minTime === undefined) {
1471
- // "threshold" is a legacy property.
1472
- if (step.threshold !== undefined) {
1473
- // "threshold" is a legacy name for "minTime".
1474
- minTime = step.threshold; // "threshold" function is deprecated.
1475
-
1476
- if (typeof minTime === 'function') {
1477
- minTime = minTime(now, future);
1478
- }
1479
- }
1480
- }
1481
-
1482
- if (minTime === undefined) {
1483
- minTime = step.minTime;
1484
- } // A deprecated way of specifying a different threshold
1485
- // depending on the previous step's unit.
1486
-
1487
-
1488
- if (_typeof$1(minTime) === 'object') {
1489
- if (prevStep && prevStep.id && minTime[prevStep.id] !== undefined) {
1490
- minTime = minTime[prevStep.id];
1491
- } else {
1492
- minTime = minTime["default"];
1493
- }
1494
- }
1495
-
1496
- if (typeof minTime === 'function') {
1497
- minTime = minTime(timestamp, {
1498
- future: future,
1499
- getMinTimeForUnit: function getMinTimeForUnit(toUnit, fromUnit) {
1500
- return _getMinTimeForUnit(toUnit, fromUnit || prevStep && prevStep.formatAs, {
1501
- round: round
1502
- });
1503
- }
1504
- });
1505
- } // Evaluate the `test()` function.
1506
- // `test()` function is deprecated.
1507
-
1508
-
1509
- if (minTime === undefined) {
1510
- if (step.test) {
1511
- if (step.test(timestamp, {
1512
- now: now,
1513
- future: future
1514
- })) {
1515
- // `0` threshold always passes.
1516
- minTime = 0;
1517
- } else {
1518
- // `MAX_SAFE_INTEGER` threshold won't ever pass in real life.
1519
- minTime = 9007199254740991; // Number.MAX_SAFE_INTEGER
1520
- }
1521
- }
1522
- }
1523
-
1524
- if (minTime === undefined) {
1525
- if (prevStep) {
1526
- if (step.formatAs && prevStep.formatAs) {
1527
- minTime = _getMinTimeForUnit(step.formatAs, prevStep.formatAs, {
1528
- round: round
1529
- });
1530
- }
1531
- } else {
1532
- // The first step's `minTime` is `0` by default.
1533
- minTime = 0;
1534
- }
1535
- } // Warn if no `minTime` was defined or could be deduced.
1536
-
1537
-
1538
- if (minTime === undefined) {
1539
- console.warn('[javascript-time-ago] A step should specify `minTime`:\n' + JSON.stringify(step, null, 2));
1540
- }
1541
-
1542
- return minTime;
1543
- }
1544
-
1545
- function _getMinTimeForUnit(toUnit, fromUnit, _ref2) {
1546
- var round = _ref2.round;
1547
- var toUnitAmount = getSecondsInUnit(toUnit); // if (!fromUnit) {
1548
- // return toUnitAmount;
1549
- // }
1550
- // if (!fromUnit) {
1551
- // fromUnit = getPreviousUnitFor(toUnit)
1552
- // }
1553
-
1554
- var fromUnitAmount;
1555
-
1556
- if (fromUnit === 'now') {
1557
- fromUnitAmount = getSecondsInUnit(toUnit);
1558
- } else {
1559
- fromUnitAmount = getSecondsInUnit(fromUnit);
1560
- }
1561
-
1562
- if (toUnitAmount !== undefined && fromUnitAmount !== undefined) {
1563
- return toUnitAmount - fromUnitAmount * (1 - getDiffRatioToNextRoundedNumber(round));
1564
- }
1565
- }
1566
-
1567
- function ownKeys$8(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1568
-
1569
- function _objectSpread$8(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$8(Object(source), true).forEach(function (key) { _defineProperty$8(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$8(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1570
-
1571
- function _defineProperty$8(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
1572
- /**
1573
- * Finds an appropriate `step` of `steps` for the time interval (in seconds).
1574
- *
1575
- * @param {Object[]} steps - Time formatting steps.
1576
- *
1577
- * @param {number} secondsPassed - Time interval (in seconds).
1578
- * `< 0` for past dates and `> 0` for future dates.
1579
- *
1580
- * @param {number} options.now - Current timestamp.
1581
- *
1582
- * @param {boolean} [options.future] - Whether the date should be formatted as a future one
1583
- * instead of a past one.
1584
- *
1585
- * @param {string} [options.round] - (undocumented) Rounding mechanism.
1586
- *
1587
- * @param {string[]} [options.units] - A list of allowed time units.
1588
- * (Example: ['second', 'minute', 'hour', …])
1589
- *
1590
- * @param {boolean} [options.getNextStep] - Pass true to return `[step, nextStep]` instead of just `step`.
1591
- *
1592
- * @return {Object|Object[]} [step] — Either a `step` or `[prevStep, step, nextStep]`.
1593
- */
1594
-
1595
- function getStep(steps, secondsPassed, _ref) {
1596
- var now = _ref.now,
1597
- future = _ref.future,
1598
- round = _ref.round,
1599
- units = _ref.units;
1600
- // Ignore steps having not-supported time units in `formatAs`.
1601
- steps = filterStepsByUnits(steps, units);
1602
-
1603
- var step = _getStep(steps, secondsPassed, {
1604
- now: now,
1605
- future: future,
1606
- round: round
1607
- });
1608
-
1609
- {
1610
- if (step) {
1611
- var prevStep = steps[steps.indexOf(step) - 1];
1612
- var nextStep = steps[steps.indexOf(step) + 1];
1613
- return [prevStep, step, nextStep];
1614
- }
1615
-
1616
- return [undefined, undefined, steps[0]];
1617
- }
1618
- }
1619
-
1620
- function _getStep(steps, secondsPassed, _ref2) {
1621
- var now = _ref2.now,
1622
- future = _ref2.future,
1623
- round = _ref2.round;
1624
-
1625
- // If no steps fit the conditions then return nothing.
1626
- if (steps.length === 0) {
1627
- return;
1628
- } // Find the most appropriate step.
1629
-
1630
-
1631
- var i = getStepIndex(steps, secondsPassed, {
1632
- now: now,
1633
- future: future || secondsPassed < 0,
1634
- round: round
1635
- }); // If no step is applicable the return nothing.
1636
-
1637
- if (i === -1) {
1638
- return;
1639
- }
1640
-
1641
- var step = steps[i]; // Apply granularity to the time amount
1642
- // (and fall back to the previous step
1643
- // if the first level of granularity
1644
- // isn't met by this amount)
1645
-
1646
- if (step.granularity) {
1647
- // Recalculate the amount of seconds passed based on `granularity`.
1648
- var secondsPassedGranular = getRoundFunction(round)(Math.abs(secondsPassed) / getStepDenominator(step) / step.granularity) * step.granularity; // If the granularity for this step is too high,
1649
- // then fall back to the previous step.
1650
- // (if there is any previous step)
1651
-
1652
- if (secondsPassedGranular === 0 && i > 0) {
1653
- return steps[i - 1];
1654
- }
1655
- }
1656
-
1657
- return step;
1658
- }
1659
- /**
1660
- * Iterates through steps until it finds the maximum one satisfying the `minTime` threshold.
1661
- * @param {Object} steps - Steps.
1662
- * @param {number} secondsPassed - How much seconds have passed since the date till `now`.
1663
- * @param {number} options.now - Current timestamp.
1664
- * @param {boolean} options.future - Whether the time interval should be formatted as a future one.
1665
- * @param {number} [i] - Gradation step currently being tested.
1666
- * @return {number} Gradation step index.
1667
- */
1668
-
1669
-
1670
- function getStepIndex(steps, secondsPassed, options) {
1671
- var i = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
1672
- var minTime = getStepMinTime(steps[i], _objectSpread$8({
1673
- prevStep: steps[i - 1],
1674
- timestamp: options.now - secondsPassed * 1000
1675
- }, options)); // If `minTime` isn't defined or deduceable for this step, then stop.
1676
-
1677
- if (minTime === undefined) {
1678
- return i - 1;
1679
- } // If the `minTime` threshold for moving from previous step
1680
- // to this step is too high then return the previous step.
1681
-
1682
-
1683
- if (Math.abs(secondsPassed) < minTime) {
1684
- return i - 1;
1685
- } // If it's the last step then return it.
1686
-
1687
-
1688
- if (i === steps.length - 1) {
1689
- return i;
1690
- } // Move to the next step.
1691
-
1692
-
1693
- return getStepIndex(steps, secondsPassed, options, i + 1);
1694
- }
1695
- /**
1696
- * Leaves only allowed steps.
1697
- * @param {Object[]} steps
1698
- * @param {string[]} units - Allowed time units.
1699
- * @return {Object[]}
1700
- */
1701
-
1702
-
1703
- function filterStepsByUnits(steps, units) {
1704
- return steps.filter(function (_ref3) {
1705
- var unit = _ref3.unit,
1706
- formatAs = _ref3.formatAs;
1707
- // "unit" is now called "formatAs".
1708
- unit = unit || formatAs; // If this step has a `unit` defined
1709
- // then this `unit` must be in the list of allowed `units`.
1710
-
1711
- if (unit) {
1712
- return units.indexOf(unit) >= 0;
1713
- } // A step is not required to specify a `unit`:
1714
- // alternatively, it could specify `format()`.
1715
- // (see "twitter" style for an example)
1716
-
1717
-
1718
- return true;
1719
- });
1720
- }
1721
-
1722
- /**
1723
- * Gets the time to next update for a step with a time unit defined.
1724
- * @param {string} unit
1725
- * @param {number} date — The date passed to `.format()`, converted to a timestamp.
1726
- * @param {number} options.now
1727
- * @param {string} [options.round] — (undocumented) Rounding mechanism.
1728
- * @return {number} [timeToNextUpdate]
1729
- */
1730
-
1731
- function getTimeToNextUpdateForUnit(unit, timestamp, _ref) {
1732
- var now = _ref.now,
1733
- round = _ref.round;
1734
-
1735
- // For some units, like "now", there's no defined amount of seconds in them.
1736
- if (!getSecondsInUnit(unit)) {
1737
- // If there's no amount of seconds defined for this unit
1738
- // then the update interval can't be determined reliably.
1739
- return;
1740
- }
1741
-
1742
- var unitDenominator = getSecondsInUnit(unit) * 1000;
1743
- var future = timestamp > now;
1744
- var preciseAmount = Math.abs(timestamp - now);
1745
- var roundedAmount = getRoundFunction(round)(preciseAmount / unitDenominator) * unitDenominator;
1746
-
1747
- if (future) {
1748
- if (roundedAmount > 0) {
1749
- // Amount decreases with time.
1750
- return preciseAmount - roundedAmount + getDiffToPreviousRoundedNumber(round, unitDenominator);
1751
- } else {
1752
- // Refresh right after the zero point,
1753
- // when "future" changes to "past".
1754
- return preciseAmount - roundedAmount + 1;
1755
- }
1756
- } // Amount increases with time.
1757
-
1758
-
1759
- return -(preciseAmount - roundedAmount) + getDiffToNextRoundedNumber(round, unitDenominator);
1760
- }
1761
-
1762
- function getDiffToNextRoundedNumber(round, unitDenominator) {
1763
- return getDiffRatioToNextRoundedNumber(round) * unitDenominator;
1764
- }
1765
-
1766
- function getDiffToPreviousRoundedNumber(round, unitDenominator) {
1767
- return (1 - getDiffRatioToNextRoundedNumber(round)) * unitDenominator + 1;
1768
- }
1769
-
1770
- var YEAR = 365 * 24 * 60 * 60 * 1000;
1771
- var INFINITY = 1000 * YEAR;
1772
- /**
1773
- * Gets the time to next update for a date and a step.
1774
- * @param {number} date — The date passed to `.format()`, converted to a timestamp.
1775
- * @param {object} step
1776
- * @param {object} [options.previousStep]
1777
- * @param {object} [options.nextStep]
1778
- * @param {number} options.now
1779
- * @param {boolean} options.future
1780
- * @param {string} [options.round] - (undocumented) Rounding mechanism.
1781
- * @return {number} [timeToNextUpdate]
1782
- */
1783
-
1784
- function getTimeToNextUpdate(date, step, _ref) {
1785
- var prevStep = _ref.prevStep,
1786
- nextStep = _ref.nextStep,
1787
- now = _ref.now,
1788
- future = _ref.future,
1789
- round = _ref.round;
1790
- var timestamp = date.getTime ? date.getTime() : date;
1791
-
1792
- var getTimeToNextUpdateForUnit$1 = function getTimeToNextUpdateForUnit$1(unit) {
1793
- return getTimeToNextUpdateForUnit(unit, timestamp, {
1794
- now: now,
1795
- round: round
1796
- });
1797
- }; // For future dates, steps move from the last one to the first one,
1798
- // while for past dates, steps move from the first one to the last one,
1799
- // due to the fact that time flows in one direction,
1800
- // and future dates' interval naturally becomes smaller
1801
- // while past dates' interval naturally grows larger.
1802
- //
1803
- // For future dates, it's the transition
1804
- // from the current step to the previous step,
1805
- // therefore check the `minTime` of the current step.
1806
- //
1807
- // For past dates, it's the transition
1808
- // from the current step to the next step,
1809
- // therefore check the `minTime` of the next step.
1810
- //
1811
-
1812
-
1813
- var timeToStepChange = getTimeToStepChange(future ? step : nextStep, timestamp, {
1814
- future: future,
1815
- now: now,
1816
- round: round,
1817
- prevStep: future ? prevStep : step // isFirstStep: future && isFirstStep
1818
-
1819
- });
1820
-
1821
- if (timeToStepChange === undefined) {
1822
- // Can't reliably determine "time to next update"
1823
- // if not all of the steps provide `minTime`.
1824
- return;
1825
- }
1826
-
1827
- var timeToNextUpdate;
1828
-
1829
- if (step) {
1830
- if (step.getTimeToNextUpdate) {
1831
- timeToNextUpdate = step.getTimeToNextUpdate(timestamp, {
1832
- getTimeToNextUpdateForUnit: getTimeToNextUpdateForUnit$1,
1833
- getRoundFunction: getRoundFunction,
1834
- now: now,
1835
- future: future,
1836
- round: round
1837
- });
1838
- }
1839
-
1840
- if (timeToNextUpdate === undefined) {
1841
- // "unit" is now called "formatAs".
1842
- var unit = step.unit || step.formatAs;
1843
-
1844
- if (unit) {
1845
- // For some units, like "now", there's no defined amount of seconds in them.
1846
- // In such cases, `getTimeToNextUpdateForUnit()` returns `undefined`,
1847
- // and the next step's `minTime` could be used to calculate the update interval:
1848
- // it will just assume that the label never changes for this step.
1849
- timeToNextUpdate = getTimeToNextUpdateForUnit$1(unit);
1850
- }
1851
- }
1852
- }
1853
-
1854
- if (timeToNextUpdate === undefined) {
1855
- return timeToStepChange;
1856
- }
1857
-
1858
- return Math.min(timeToNextUpdate, timeToStepChange);
1859
- }
1860
- function getStepChangesAt(currentOrNextStep, timestamp, _ref2) {
1861
- var now = _ref2.now,
1862
- future = _ref2.future,
1863
- round = _ref2.round,
1864
- prevStep = _ref2.prevStep;
1865
- // The first step's `minTime` is `0` by default.
1866
- // It doesn't "change" steps at zero point
1867
- // but it does change the wording when switching
1868
- // from "future" to "past": "in ..." -> "... ago".
1869
- // Therefore, the label should be updated at zero-point too.
1870
- var minTime = getStepMinTime(currentOrNextStep, {
1871
- timestamp: timestamp,
1872
- now: now,
1873
- future: future,
1874
- round: round,
1875
- prevStep: prevStep
1876
- });
1877
-
1878
- if (minTime === undefined) {
1879
- return;
1880
- }
1881
-
1882
- if (future) {
1883
- // The step changes to the previous step
1884
- // as soon as `timestamp - now` becomes
1885
- // less than the `minTime` of the current step:
1886
- // `timestamp - now === minTime - 1`
1887
- // => `now === timestamp - minTime + 1`.
1888
- return timestamp - minTime * 1000 + 1;
1889
- } else {
1890
- // The step changes to the next step
1891
- // as soon as `now - timestamp` becomes
1892
- // equal to `minTime` of the next step:
1893
- // `now - timestamp === minTime`
1894
- // => `now === timestamp + minTime`.
1895
- // This is a special case when double-update could be skipped.
1896
- if (minTime === 0 && timestamp === now) {
1897
- return INFINITY;
1898
- }
1899
-
1900
- return timestamp + minTime * 1000;
1901
- }
1902
- }
1903
- function getTimeToStepChange(step, timestamp, _ref3) {
1904
- var now = _ref3.now,
1905
- future = _ref3.future,
1906
- round = _ref3.round,
1907
- prevStep = _ref3.prevStep;
1908
-
1909
- if (step) {
1910
- var stepChangesAt = getStepChangesAt(step, timestamp, {
1911
- now: now,
1912
- future: future,
1913
- round: round,
1914
- prevStep: prevStep
1915
- });
1916
-
1917
- if (stepChangesAt === undefined) {
1918
- return;
1919
- }
1920
-
1921
- return stepChangesAt - now;
1922
- } else {
1923
- if (future) {
1924
- // No step.
1925
- // Update right after zero point, when it changes from "future" to "past".
1926
- return timestamp - now + 1;
1927
- } else {
1928
- // The last step doesn't ever change when `date` is in the past.
1929
- return INFINITY;
1930
- }
1931
- }
1932
- }
1933
-
1934
- // For all locales added
1935
- // their relative time formatter messages will be stored here.
1936
- var localesData = {};
1937
- function getLocaleData(locale) {
1938
- return localesData[locale];
1939
- }
1940
- function addLocaleData(localeData) {
1941
- if (!localeData) {
1942
- throw new Error('[javascript-time-ago] No locale data passed.');
1943
- } // This locale data is stored in a global variable
1944
- // and later used when calling `.format(time)`.
1945
-
1946
-
1947
- localesData[localeData.locale] = localeData;
1948
- }
1949
-
1950
- // just now
1951
- // 1 second ago
1952
- // 2 seconds ago
1953
- // …
1954
- // 59 seconds ago
1955
- // 1 minute ago
1956
- // 2 minutes ago
1957
- // …
1958
- // 59 minutes ago
1959
- // 1 hour ago
1960
- // 2 hours ago
1961
- // …
1962
- // 24 hours ago
1963
- // 1 day ago
1964
- // 2 days ago
1965
- // …
1966
- // 6 days ago
1967
- // 1 week ago
1968
- // 2 weeks ago
1969
- // …
1970
- // 3 weeks ago
1971
- // 1 month ago
1972
- // 2 months ago
1973
- // …
1974
- // 11 months ago
1975
- // 1 year ago
1976
- // 2 years ago
1977
- // …
1978
- var round$1 = [{
1979
- formatAs: 'now'
1980
- }, {
1981
- formatAs: 'second'
1982
- }, {
1983
- formatAs: 'minute'
1984
- }, {
1985
- formatAs: 'hour'
1986
- }, {
1987
- formatAs: 'day'
1988
- }, {
1989
- formatAs: 'week'
1990
- }, {
1991
- formatAs: 'month'
1992
- }, {
1993
- formatAs: 'year'
1994
- }];
1995
-
1996
- // 1 second ago
1997
- // 2 seconds ago
1998
- // …
1999
- // 59 seconds ago
2000
- // 1 minute ago
2001
- // 2 minutes ago
2002
- // …
2003
- // 59 minutes ago
2004
- // 1 minute ago
2005
- // 2 minutes ago
2006
- // …
2007
- // 59 minutes ago
2008
- // 1 hour ago
2009
- // 2 hours ago
2010
- // …
2011
- // 24 hours ago
2012
- // 1 day ago
2013
- // 2 days ago
2014
- // …
2015
- // 6 days ago
2016
- // 1 week ago
2017
- // 2 weeks ago
2018
- // 3 weeks ago
2019
- // 4 weeks ago
2020
- // 1 month ago
2021
- // 2 months ago
2022
- // …
2023
- // 11 months ago
2024
- // 1 year ago
2025
- // 2 years ago
2026
- // …
2027
- //
2028
-
2029
- var round = {
2030
- steps: round$1,
2031
- labels: 'long'
2032
- };
2033
-
2034
- function ownKeys$7(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2035
-
2036
- function _objectSpread$7(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$7(Object(source), true).forEach(function (key) { _defineProperty$7(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$7(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2037
-
2038
- function _defineProperty$7(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2039
- // 1 minute ago
2040
- // 2 minutes ago
2041
- // …
2042
- // 59 minutes ago
2043
- // 1 minute ago
2044
- // 2 minutes ago
2045
- // …
2046
- // 59 minutes ago
2047
- // 1 hour ago
2048
- // 2 hours ago
2049
- // …
2050
- // 24 hours ago
2051
- // 1 day ago
2052
- // 2 days ago
2053
- // …
2054
- // 6 days ago
2055
- // 1 week ago
2056
- // 2 weeks ago
2057
- // 3 weeks ago
2058
- // 4 weeks ago
2059
- // 1 month ago
2060
- // 2 months ago
2061
- // …
2062
- // 11 months ago
2063
- // 1 year ago
2064
- // 2 years ago
2065
- // …
2066
- //
2067
-
2068
- var defaultStyle = _objectSpread$7(_objectSpread$7({}, round), {}, {
2069
- // Skip "seconds".
2070
- steps: round.steps.filter(function (step) {
2071
- return step.formatAs !== 'second';
2072
- })
2073
- });
2074
-
2075
- // Developers shouldn't need to use it in their custom steps.
2076
- // "threshold" is a legacy name of "min".
2077
- // Developers should use "min" property name instead of "threshold".
2078
- // "threshold_for_idOrUnit: value" is a legacy way of specifying "min: { id: value }".
2079
- // Developers should use "min" property instead of "threshold".
2080
- // just now
2081
- // 1 minute ago
2082
- // 2 minutes ago
2083
- // 5 minutes ago
2084
- // 10 minutes ago
2085
- // 15 minutes ago
2086
- // 20 minutes ago
2087
- // …
2088
- // 50 minutes ago
2089
- // an hour ago
2090
- // 2 hours ago
2091
- // …
2092
- // 20 hours ago
2093
- // a day ago
2094
- // 2 days ago
2095
- // 5 days ago
2096
- // a week ago
2097
- // 2 weeks ago
2098
- // 3 weeks ago
2099
- // a month ago
2100
- // 2 months ago
2101
- // 4 months ago
2102
- // a year ago
2103
- // 2 years ago
2104
- // …
2105
-
2106
- var approximate$1 = [{
2107
- // This step returns the amount of seconds
2108
- // by dividing the amount of seconds by `1`.
2109
- factor: 1,
2110
- // "now" labels are used for formatting the output.
2111
- unit: 'now'
2112
- }, {
2113
- // When the language doesn't support `now` unit,
2114
- // the first step is ignored, and it uses this `second` unit.
2115
- threshold: 1,
2116
- // `threshold_for_now` should be the same as `threshold` on minutes.
2117
- threshold_for_now: 45.5,
2118
- // This step returns the amount of seconds
2119
- // by dividing the amount of seconds by `1`.
2120
- factor: 1,
2121
- // "second" labels are used for formatting the output.
2122
- unit: 'second'
2123
- }, {
2124
- // `threshold` should be the same as `threshold_for_now` on seconds.
2125
- threshold: 45.5,
2126
- // Return the amount of minutes by dividing the amount
2127
- // of seconds by the amount of seconds in a minute.
2128
- factor: minute,
2129
- // "minute" labels are used for formatting the output.
2130
- unit: 'minute'
2131
- }, {
2132
- // This step is effective starting from 2.5 minutes.
2133
- threshold: 2.5 * minute,
2134
- // Allow only 5-minute increments of minutes starting from 2.5 minutes.
2135
- // `granularity` — (advanced) Time interval value "granularity".
2136
- // For example, it could be set to `5` for minutes to allow only 5-minute increments
2137
- // when formatting time intervals: `0 minutes`, `5 minutes`, `10 minutes`, etc.
2138
- // Perhaps this feature will be removed because there seem to be no use cases
2139
- // of it in the real world.
2140
- granularity: 5,
2141
- // Return the amount of minutes by dividing the amount
2142
- // of seconds by the amount of seconds in a minute.
2143
- factor: minute,
2144
- // "minute" labels are used for formatting the output.
2145
- unit: 'minute'
2146
- }, {
2147
- // This step is effective starting from 22.5 minutes.
2148
- threshold: 22.5 * minute,
2149
- // Return the amount of minutes by dividing the amount
2150
- // of seconds by the amount of seconds in half-an-hour.
2151
- factor: 0.5 * hour,
2152
- // "half-hour" labels are used for formatting the output.
2153
- // (if available, which is no longer the case)
2154
- unit: 'half-hour'
2155
- }, {
2156
- // This step is effective starting from 42.5 minutes.
2157
- threshold: 42.5 * minute,
2158
- threshold_for_minute: 52.5 * minute,
2159
- // Return the amount of minutes by dividing the amount
2160
- // of seconds by the amount of seconds in an hour.
2161
- factor: hour,
2162
- // "hour" labels are used for formatting the output.
2163
- unit: 'hour'
2164
- }, {
2165
- // This step is effective starting from 20.5 hours.
2166
- threshold: 20.5 / 24 * day,
2167
- // Return the amount of minutes by dividing the amount
2168
- // of seconds by the amount of seconds in a day.
2169
- factor: day,
2170
- // "day" labels are used for formatting the output.
2171
- unit: 'day'
2172
- }, {
2173
- // This step is effective starting from 5.5 days.
2174
- threshold: 5.5 * day,
2175
- // Return the amount of minutes by dividing the amount
2176
- // of seconds by the amount of seconds in a week.
2177
- factor: week,
2178
- // "week" labels are used for formatting the output.
2179
- unit: 'week'
2180
- }, {
2181
- // This step is effective starting from 3.5 weeks.
2182
- threshold: 3.5 * week,
2183
- // Return the amount of minutes by dividing the amount
2184
- // of seconds by the amount of seconds in a month.
2185
- factor: month,
2186
- // "month" labels are used for formatting the output.
2187
- unit: 'month'
2188
- }, {
2189
- // This step is effective starting from 10.5 months.
2190
- threshold: 10.5 * month,
2191
- // Return the amount of minutes by dividing the amount
2192
- // of seconds by the amount of seconds in a year.
2193
- factor: year,
2194
- // "year" labels are used for formatting the output.
2195
- unit: 'year'
2196
- }];
2197
-
2198
- // It's here just for legacy compatibility.
2199
- // Use "steps" name instead.
2200
- // "flavour" is a legacy name for "labels".
2201
- // It's here just for legacy compatibility.
2202
- // Use "labels" name instead.
2203
- // "units" is a legacy property.
2204
- // It's here just for legacy compatibility.
2205
- // Developers shouldn't need to use it in their custom styles.
2206
-
2207
- var approximate = {
2208
- gradation: approximate$1,
2209
- flavour: 'long',
2210
- units: ['now', 'minute', 'hour', 'day', 'week', 'month', 'year']
2211
- };
2212
-
2213
- // It's here just for legacy compatibility.
2214
- // Use "steps" name instead.
2215
- // "flavour" is a legacy name for "labels".
2216
- // It's here just for legacy compatibility.
2217
- // Use "labels" name instead.
2218
- // "units" is a legacy property.
2219
- // It's here just for legacy compatibility.
2220
- // Developers shouldn't need to use it in their custom styles.
2221
- // Similar to the default style but with "ago" omitted.
2222
- //
2223
- // just now
2224
- // 5 minutes
2225
- // 10 minutes
2226
- // 15 minutes
2227
- // 20 minutes
2228
- // an hour
2229
- // 2 hours
2230
- // …
2231
- // 20 hours
2232
- // 1 day
2233
- // 2 days
2234
- // a week
2235
- // 2 weeks
2236
- // 3 weeks
2237
- // a month
2238
- // 2 months
2239
- // 3 months
2240
- // 4 months
2241
- // a year
2242
- // 2 years
2243
- //
2244
-
2245
- var approximateTime = {
2246
- gradation: approximate$1,
2247
- flavour: 'long-time',
2248
- units: ['now', 'minute', 'hour', 'day', 'week', 'month', 'year']
2249
- };
2250
-
2251
- // Looks like this one's deprecated.
2252
- // /**
2253
- // * Returns a step corresponding to the unit.
2254
- // * @param {Object[]} steps
2255
- // * @param {string} unit
2256
- // * @return {?Object}
2257
- // */
2258
- // export function getStepForUnit(steps, unit) {
2259
- // for (const step of steps) {
2260
- // if (step.unit === unit) {
2261
- // return step
2262
- // }
2263
- // }
2264
- // }
2265
- // Looks like this one won't be used in the next major version.
2266
-
2267
- /**
2268
- * Converts value to a `Date`
2269
- * @param {(number|Date)} value
2270
- * @return {Date}
2271
- */
2272
- function getDate(value) {
2273
- return value instanceof Date ? value : new Date(value);
2274
- }
2275
-
2276
- // ("1m", "2h", "Mar 3", "Apr 4, 2012").
2277
- //
2278
- // Seconds, minutes or hours are shown for shorter intervals,
2279
- // and longer intervals are formatted using full date format.
2280
-
2281
- var steps = [{
2282
- formatAs: 'second'
2283
- }, {
2284
- formatAs: 'minute'
2285
- }, {
2286
- formatAs: 'hour'
2287
- }]; // A cache for `Intl.DateTimeFormat` formatters
2288
- // for various locales (is a global variable).
2289
-
2290
- var formatters = {}; // Starting from day intervals, output month and day.
2291
-
2292
- var monthAndDay = {
2293
- minTime: function minTime(timestamp, _ref) {
2294
- _ref.future;
2295
- var getMinTimeForUnit = _ref.getMinTimeForUnit;
2296
- // Returns `23.5 * 60 * 60` when `round` is "round",
2297
- // and `24 * 60 * 60` when `round` is "floor".
2298
- return getMinTimeForUnit('day');
2299
- },
2300
- format: function format(value, locale) {
2301
- /* istanbul ignore else */
2302
- if (!formatters[locale]) {
2303
- formatters[locale] = {};
2304
- }
2305
- /* istanbul ignore else */
2306
-
2307
-
2308
- if (!formatters[locale].dayMonth) {
2309
- // "Apr 11" (MMMd)
2310
- formatters[locale].dayMonth = new Intl.DateTimeFormat(locale, {
2311
- month: 'short',
2312
- day: 'numeric'
2313
- });
2314
- } // Output month and day.
2315
-
2316
-
2317
- return formatters[locale].dayMonth.format(getDate(value));
2318
- }
2319
- }; // If the `date` happened/happens outside of current year,
2320
- // then output day, month and year.
2321
- // The interval should be such that the `date` lies outside of the current year.
2322
-
2323
- var yearMonthAndDay = {
2324
- minTime: function minTime(timestamp, _ref2) {
2325
- var future = _ref2.future;
2326
-
2327
- if (future) {
2328
- // January 1, 00:00, of the `date`'s year is right after
2329
- // the maximum `now` for formatting a future date:
2330
- // When `now` is before that date, the `date` is formatted as "day/month/year" (this step),
2331
- // When `now` is equal to or after that date, the `date` is formatted as "day/month" (another step).
2332
- // After that, it's hours, minutes, seconds, and after that it's no longer `future`.
2333
- // The date is right after the maximum `now` for formatting a future date,
2334
- // so subtract 1 millisecond from it.
2335
- var maxFittingNow = new Date(new Date(timestamp).getFullYear(), 0).getTime() - 1; // Return `minTime` (in seconds).
2336
-
2337
- return (timestamp - maxFittingNow) / 1000;
2338
- } else {
2339
- // January 1, 00:00, of the year following the `date`'s year
2340
- // is the minimum `now` for formatting a past date:
2341
- // When `now` is before that date, the `date` is formatted as "day/month" (another step),
2342
- // When `now` is equal to or after that date, the `date` is formatted as "day/month/year" (this step).
2343
- // After that, it's hours, minutes, seconds, and after that it's no longer `future`.
2344
- var minFittingNow = new Date(new Date(timestamp).getFullYear() + 1, 0).getTime(); // Return `minTime` (in seconds).
2345
-
2346
- return (minFittingNow - timestamp) / 1000;
2347
- }
2348
- },
2349
- format: function format(value, locale) {
2350
- /* istanbul ignore if */
2351
- if (!formatters[locale]) {
2352
- formatters[locale] = {};
2353
- }
2354
- /* istanbul ignore else */
2355
-
2356
-
2357
- if (!formatters[locale].dayMonthYear) {
2358
- // "Apr 11, 2017" (yMMMd)
2359
- formatters[locale].dayMonthYear = new Intl.DateTimeFormat(locale, {
2360
- year: 'numeric',
2361
- month: 'short',
2362
- day: 'numeric'
2363
- });
2364
- } // Output day, month and year.
2365
-
2366
-
2367
- return formatters[locale].dayMonthYear.format(getDate(value));
2368
- }
2369
- }; // If `Intl.DateTimeFormat` is supported,
2370
- // then longer time intervals will be formatted as dates.
2371
-
2372
- /* istanbul ignore else */
2373
-
2374
- if (intlDateTimeFormatSupported()) {
2375
- steps.push(monthAndDay, yearMonthAndDay);
2376
- } // Otherwise, if `Intl.DateTimeFormat` is not supported,
2377
- // which could be the case when using Internet Explorer,
2378
- // then simply mimick "round" steps.
2379
- else {
2380
- steps.push({
2381
- formatAs: 'day'
2382
- }, {
2383
- formatAs: 'week'
2384
- }, {
2385
- formatAs: 'month'
2386
- }, {
2387
- formatAs: 'year'
2388
- });
2389
- }
2390
-
2391
- var twitter = {
2392
- steps: steps,
2393
- labels: [// "mini" labels are only defined for a few languages.
2394
- 'mini', // "short-time" labels are only defined for a few languages.
2395
- 'short-time', // "narrow" and "short" labels are defined for all languages.
2396
- // "narrow" labels can sometimes be weird (like "+5d."),
2397
- // but "short" labels have the " ago" part, so "narrow" seem
2398
- // more appropriate.
2399
- // "short" labels would have been more appropriate if they
2400
- // didn't have the " ago" part, hence the "short-time" above.
2401
- 'narrow', // Since "narrow" labels are always present, "short" element
2402
- // of this array can be removed.
2403
- 'short']
2404
- };
2405
-
2406
- function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2407
-
2408
- function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$6(Object(source), true).forEach(function (key) { _defineProperty$6(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2409
-
2410
- function _defineProperty$6(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2411
- var twitterNow = _objectSpread$6(_objectSpread$6({}, twitter), {}, {
2412
- // Add "now".
2413
- steps: [{
2414
- formatAs: 'now'
2415
- }].concat(twitter.steps)
2416
- });
2417
-
2418
- function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2419
-
2420
- function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty$5(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2421
-
2422
- function _defineProperty$5(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2423
- var twitterMinute = _objectSpread$5(_objectSpread$5({}, twitter), {}, {
2424
- // Skip "seconds".
2425
- steps: twitter.steps.filter(function (step) {
2426
- return step.formatAs !== 'second';
2427
- })
2428
- });
2429
-
2430
- function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2431
-
2432
- function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty$4(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2433
-
2434
- function _defineProperty$4(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2435
- var twitterMinuteNow = _objectSpread$4(_objectSpread$4({}, twitterMinute), {}, {
2436
- // Add "now".
2437
- steps: [{
2438
- formatAs: 'now'
2439
- }].concat(twitterMinute.steps)
2440
- });
2441
-
2442
- function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2443
-
2444
- function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty$3(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2445
-
2446
- function _defineProperty$3(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2447
- var twitterFirstMinute = _objectSpread$3(_objectSpread$3({}, twitter), {}, {
2448
- // Skip "seconds".
2449
- steps: twitter.steps.filter(function (step) {
2450
- return step.formatAs !== 'second';
2451
- }) // Start showing `1m` from the first minute.
2452
- .map(function (step) {
2453
- return step.formatAs === 'minute' ? _objectSpread$3(_objectSpread$3({}, step), {}, {
2454
- minTime: minute
2455
- }) : step;
2456
- })
2457
- });
2458
-
2459
- var mini = {
2460
- steps: [{
2461
- formatAs: 'second'
2462
- }, {
2463
- formatAs: 'minute'
2464
- }, {
2465
- formatAs: 'hour'
2466
- }, {
2467
- formatAs: 'day'
2468
- }, {
2469
- formatAs: 'month'
2470
- }, {
2471
- formatAs: 'year'
2472
- }],
2473
- labels: [// "mini" labels are only defined for a few languages.
2474
- 'mini', // "short-time" labels are only defined for a few languages.
2475
- 'short-time', // "narrow" and "short" labels are defined for all languages.
2476
- // "narrow" labels can sometimes be weird (like "+5d."),
2477
- // but "short" labels have the " ago" part, so "narrow" seem
2478
- // more appropriate.
2479
- // "short" labels would have been more appropriate if they
2480
- // didn't have the " ago" part, hence the "short-time" above.
2481
- 'narrow', // Since "narrow" labels are always present, "short" element
2482
- // of this array can be removed.
2483
- 'short']
2484
- };
2485
-
2486
- function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2487
-
2488
- function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty$2(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2489
-
2490
- function _defineProperty$2(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2491
- var miniNow = _objectSpread$2(_objectSpread$2({}, mini), {}, {
2492
- // Add "now".
2493
- steps: [{
2494
- formatAs: 'now'
2495
- }].concat(mini.steps)
2496
- });
2497
-
2498
- function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2499
-
2500
- function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty$1(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2501
-
2502
- function _defineProperty$1(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2503
- var miniMinute = _objectSpread$1(_objectSpread$1({}, mini), {}, {
2504
- // Skip "seconds".
2505
- steps: mini.steps.filter(function (step) {
2506
- return step.formatAs !== 'second';
2507
- })
2508
- });
2509
-
2510
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2511
-
2512
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2513
-
2514
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2515
- var miniMinuteNow = _objectSpread(_objectSpread({}, miniMinute), {}, {
2516
- // Add "now".
2517
- steps: [{
2518
- formatAs: 'now'
2519
- }].concat(miniMinute.steps)
2520
- });
2521
-
2522
- function getStyleByName(style) {
2523
- switch (style) {
2524
- // "default" style name is deprecated.
2525
- case 'default':
2526
- case 'round':
2527
- return round;
2528
-
2529
- case 'round-minute':
2530
- return defaultStyle;
2531
-
2532
- case 'approximate':
2533
- return approximate;
2534
- // "time" style name is deprecated.
2535
-
2536
- case 'time':
2537
- case 'approximate-time':
2538
- return approximateTime;
2539
-
2540
- case 'mini':
2541
- return mini;
2542
-
2543
- case 'mini-now':
2544
- return miniNow;
2545
-
2546
- case 'mini-minute':
2547
- return miniMinute;
2548
-
2549
- case 'mini-minute-now':
2550
- return miniMinuteNow;
2551
-
2552
- case 'twitter':
2553
- return twitter;
2554
-
2555
- case 'twitter-now':
2556
- return twitterNow;
2557
-
2558
- case 'twitter-minute':
2559
- return twitterMinute;
2560
-
2561
- case 'twitter-minute-now':
2562
- return twitterMinuteNow;
2563
-
2564
- case 'twitter-first-minute':
2565
- return twitterFirstMinute;
2566
-
2567
- default:
2568
- // For historical reasons, the default style is "approximate".
2569
- return approximate;
2570
- }
2571
- }
2572
-
2573
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2574
-
2575
- function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike) { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2576
-
2577
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2578
-
2579
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2580
-
2581
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
2582
-
2583
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
2584
-
2585
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
2586
-
2587
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
2588
-
2589
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2590
-
2591
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
2592
-
2593
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2594
-
2595
- var TimeAgo = /*#__PURE__*/function () {
2596
- /**
2597
- * @param {(string|string[])} locales=[] - Preferred locales (or locale).
2598
- * @param {boolean} [polyfill] — Pass `false` to use native `Intl.RelativeTimeFormat` and `Intl.PluralRules` instead of the polyfills.
2599
- */
2600
- function TimeAgo() {
2601
- var locales = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2602
-
2603
- var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
2604
- polyfill = _ref.polyfill;
2605
-
2606
- _classCallCheck(this, TimeAgo);
2607
-
2608
- // Convert `locales` to an array.
2609
- if (typeof locales === 'string') {
2610
- locales = [locales];
2611
- } // Choose the most appropriate locale
2612
- // from the list of `locales` added by the user.
2613
- // For example, new TimeAgo("en-US") -> "en".
2614
-
2615
-
2616
- this.locale = chooseLocale(locales.concat(TimeAgo.getDefaultLocale()), getLocaleData);
2617
-
2618
- if (typeof Intl !== 'undefined') {
2619
- // Use `Intl.NumberFormat` for formatting numbers (when available).
2620
- if (Intl.NumberFormat) {
2621
- this.numberFormat = new Intl.NumberFormat(this.locale);
2622
- }
2623
- } // Some people have requested the ability to use native
2624
- // `Intl.RelativeTimeFormat` and `Intl.PluralRules`
2625
- // instead of the polyfills.
2626
- // https://github.com/catamphetamine/javascript-time-ago/issues/21
2627
-
2628
-
2629
- if (polyfill === false) {
2630
- this.IntlRelativeTimeFormat = Intl.RelativeTimeFormat;
2631
- this.IntlPluralRules = Intl.PluralRules;
2632
- } else {
2633
- this.IntlRelativeTimeFormat = RelativeTimeFormat;
2634
- this.IntlPluralRules = RelativeTimeFormat.PluralRules;
2635
- } // Cache `Intl.RelativeTimeFormat` instance.
2636
-
2637
-
2638
- this.relativeTimeFormatCache = new Cache(); // Cache `Intl.PluralRules` instance.
2639
-
2640
- this.pluralRulesCache = new Cache();
2641
- }
2642
- /**
2643
- * Formats relative date/time.
2644
- *
2645
- * @param {(number|Date)} input — A `Date` or a javascript timestamp.
2646
- *
2647
- * @param {(string|object)} style — Date/time formatting style. Either one of the built-in style names or a "custom" style definition object having `steps: object[]` and `labels: string[]`.
2648
- *
2649
- * @param {number} [options.now] - Sets the current date timestamp.
2650
- *
2651
- * @param {boolean} [options.future] — Tells how to format value `0`:
2652
- * as "future" (`true`) or "past" (`false`).
2653
- * Is `false` by default, but should have been `true` actually,
2654
- * in order to correspond to `Intl.RelativeTimeFormat`
2655
- * that uses `future` formatting for `0` unless `-0` is passed.
2656
- *
2657
- * @param {string} [options.round] — Rounding method. Overrides the style's one.
2658
- *
2659
- * @param {boolean} [options.getTimeToNextUpdate] — Pass `true` to return `[formattedDate, timeToNextUpdate]` instead of just `formattedDate`.
2660
- *
2661
- * @return {string} The formatted relative date/time. If no eligible `step` is found, then an empty string is returned.
2662
- */
2663
-
2664
-
2665
- _createClass(TimeAgo, [{
2666
- key: "format",
2667
- value: function format(input, style, options) {
2668
- if (!options) {
2669
- if (style && !isStyle(style)) {
2670
- options = style;
2671
- style = undefined;
2672
- } else {
2673
- options = {};
2674
- }
2675
- }
2676
-
2677
- if (!style) {
2678
- style = defaultStyle;
2679
- }
2680
-
2681
- if (typeof style === 'string') {
2682
- style = getStyleByName(style);
2683
- }
2684
-
2685
- var timestamp = getTimestamp(input); // Get locale messages for this type of labels.
2686
- // "flavour" is a legacy name for "labels".
2687
-
2688
- var _this$getLabels = this.getLabels(style.flavour || style.labels),
2689
- labels = _this$getLabels.labels,
2690
- labelsType = _this$getLabels.labelsType;
2691
-
2692
- var now; // Can pass a custom `now`, e.g. for testing purposes.
2693
- //
2694
- // Legacy way was passing `now` in `style`.
2695
- // That way is deprecated.
2696
-
2697
- if (style.now !== undefined) {
2698
- now = style.now;
2699
- } // The new way is passing `now` option to `.format()`.
2700
-
2701
-
2702
- if (now === undefined && options.now !== undefined) {
2703
- now = options.now;
2704
- }
2705
-
2706
- if (now === undefined) {
2707
- now = Date.now();
2708
- } // how much time has passed (in seconds)
2709
-
2710
-
2711
- var secondsPassed = (now - timestamp) / 1000; // in seconds
2712
-
2713
- var future = options.future || secondsPassed < 0;
2714
- var nowLabel = getNowLabel(labels, getLocaleData(this.locale).now, getLocaleData(this.locale)["long"], future); // `custom` – A function of `{ elapsed, time, date, now, locale }`.
2715
- //
2716
- // Looks like `custom` function is deprecated and will be removed
2717
- // in the next major version.
2718
- //
2719
- // If this function returns a value, then the `.format()` call will return that value.
2720
- // Otherwise the relative date/time is formatted as usual.
2721
- // This feature is currently not used anywhere and is here
2722
- // just for providing the ultimate customization point
2723
- // in case anyone would ever need that. Prefer using
2724
- // `steps[step].format(value, locale)` instead.
2725
- //
2726
-
2727
- if (style.custom) {
2728
- var custom = style.custom({
2729
- now: now,
2730
- date: new Date(timestamp),
2731
- time: timestamp,
2732
- elapsed: secondsPassed,
2733
- locale: this.locale
2734
- });
2735
-
2736
- if (custom !== undefined) {
2737
- // Won't return `timeToNextUpdate` here
2738
- // because `custom()` seems deprecated.
2739
- return custom;
2740
- }
2741
- } // Get the list of available time interval units.
2742
-
2743
-
2744
- var units = getTimeIntervalMeasurementUnits( // Controlling `style.steps` through `style.units` seems to be deprecated:
2745
- // create a new custom `style` instead.
2746
- style.units, labels, nowLabel); // // If no available time unit is suitable, just output an empty string.
2747
- // if (units.length === 0) {
2748
- // console.error(`None of the "${units.join(', ')}" time units have been found in "${labelsType}" labels for "${this.locale}" locale.`)
2749
- // return ''
2750
- // }
2751
-
2752
- var round = options.round || style.round; // Choose the appropriate time measurement unit
2753
- // and get the corresponding rounded time amount.
2754
-
2755
- var _getStep = getStep( // "gradation" is a legacy name for "steps".
2756
- // For historical reasons, "approximate" steps are used by default.
2757
- // In the next major version, there'll be no default for `steps`.
2758
- style.gradation || style.steps || defaultStyle.steps, secondsPassed, {
2759
- now: now,
2760
- units: units,
2761
- round: round,
2762
- future: future}),
2763
- _getStep2 = _slicedToArray(_getStep, 3),
2764
- prevStep = _getStep2[0],
2765
- step = _getStep2[1],
2766
- nextStep = _getStep2[2];
2767
-
2768
- var formattedDate = this.formatDateForStep(timestamp, step, secondsPassed, {
2769
- labels: labels,
2770
- labelsType: labelsType,
2771
- nowLabel: nowLabel,
2772
- now: now,
2773
- future: future,
2774
- round: round
2775
- }) || '';
2776
-
2777
- if (options.getTimeToNextUpdate) {
2778
- var timeToNextUpdate = getTimeToNextUpdate(timestamp, step, {
2779
- nextStep: nextStep,
2780
- prevStep: prevStep,
2781
- now: now,
2782
- future: future,
2783
- round: round
2784
- });
2785
- return [formattedDate, timeToNextUpdate];
2786
- }
2787
-
2788
- return formattedDate;
2789
- }
2790
- }, {
2791
- key: "formatDateForStep",
2792
- value: function formatDateForStep(timestamp, step, secondsPassed, _ref2) {
2793
- var _this = this;
2794
-
2795
- var labels = _ref2.labels,
2796
- labelsType = _ref2.labelsType,
2797
- nowLabel = _ref2.nowLabel,
2798
- now = _ref2.now,
2799
- future = _ref2.future,
2800
- round = _ref2.round;
2801
-
2802
- // If no step matches, then output an empty string.
2803
- if (!step) {
2804
- return;
2805
- }
2806
-
2807
- if (step.format) {
2808
- return step.format(timestamp, this.locale, {
2809
- formatAs: function formatAs(unit, value) {
2810
- // Mimicks `Intl.RelativeTimeFormat.format()`.
2811
- return _this.formatValue(value, unit, {
2812
- labels: labels,
2813
- future: future
2814
- });
2815
- },
2816
- now: now,
2817
- future: future
2818
- });
2819
- } // "unit" is now called "formatAs".
2820
-
2821
-
2822
- var unit = step.unit || step.formatAs;
2823
-
2824
- if (!unit) {
2825
- throw new Error("[javascript-time-ago] Each step must define either `formatAs` or `format()`. Step: ".concat(JSON.stringify(step)));
2826
- } // `Intl.RelativeTimeFormat` doesn't operate in "now" units.
2827
- // Therefore, threat "now" as a special case.
2828
-
2829
-
2830
- if (unit === 'now') {
2831
- return nowLabel;
2832
- } // Amount in units.
2833
-
2834
-
2835
- var amount = Math.abs(secondsPassed) / getStepDenominator(step); // Apply granularity to the time amount
2836
- // (and fallback to the previous step
2837
- // if the first level of granularity
2838
- // isn't met by this amount)
2839
- //
2840
- // `granularity` — (advanced) Time interval value "granularity".
2841
- // For example, it could be set to `5` for minutes to allow only 5-minute increments
2842
- // when formatting time intervals: `0 minutes`, `5 minutes`, `10 minutes`, etc.
2843
- // Perhaps this feature will be removed because there seem to be no use cases
2844
- // of it in the real world.
2845
- //
2846
-
2847
- if (step.granularity) {
2848
- // Recalculate the amount of seconds passed based on granularity
2849
- amount = getRoundFunction(round)(amount / step.granularity) * step.granularity;
2850
- }
2851
-
2852
- var valueForFormatting = -1 * Math.sign(secondsPassed) * getRoundFunction(round)(amount); // By default, this library formats a `0` in "past" mode,
2853
- // unless `future: true` option is passed.
2854
- // This is different to `relative-time-format`'s behavior
2855
- // which formats a `0` in "future" mode by default, unless it's a `-0`.
2856
- // So, convert `0` to `-0` if `future: true` option wasn't passed.
2857
- // `=== 0` matches both `0` and `-0`.
2858
-
2859
- if (valueForFormatting === 0) {
2860
- if (future) {
2861
- valueForFormatting = 0;
2862
- } else {
2863
- valueForFormatting = -0;
2864
- }
2865
- }
2866
-
2867
- switch (labelsType) {
2868
- case 'long':
2869
- case 'short':
2870
- case 'narrow':
2871
- // Format the amount using `Intl.RelativeTimeFormat`.
2872
- return this.getFormatter(labelsType).format(valueForFormatting, unit);
2873
-
2874
- default:
2875
- // Format the amount.
2876
- // (mimicks `Intl.RelativeTimeFormat` behavior for other time label styles)
2877
- return this.formatValue(valueForFormatting, unit, {
2878
- labels: labels,
2879
- future: future
2880
- });
2881
- }
2882
- }
2883
- /**
2884
- * Mimicks what `Intl.RelativeTimeFormat` does for additional locale styles.
2885
- * @param {number} value
2886
- * @param {string} unit
2887
- * @param {object} options.labels — Relative time labels.
2888
- * @param {boolean} [options.future] — Tells how to format value `0`: as "future" (`true`) or "past" (`false`). Is `false` by default, but should have been `true` actually.
2889
- * @return {string}
2890
- */
2891
-
2892
- }, {
2893
- key: "formatValue",
2894
- value: function formatValue(value, unit, _ref3) {
2895
- var labels = _ref3.labels,
2896
- future = _ref3.future;
2897
- return this.getFormattingRule(labels, unit, value, {
2898
- future: future
2899
- }).replace('{0}', this.formatNumber(Math.abs(value)));
2900
- }
2901
- /**
2902
- * Returns formatting rule for `value` in `units` (either in past or in future).
2903
- * @param {object} formattingRules — Relative time labels for different units.
2904
- * @param {string} unit - Time interval measurement unit.
2905
- * @param {number} value - Time interval value.
2906
- * @param {boolean} [options.future] — Tells how to format value `0`: as "future" (`true`) or "past" (`false`). Is `false` by default.
2907
- * @return {string}
2908
- * @example
2909
- * // Returns "{0} days ago"
2910
- * getFormattingRule(en.long, "day", -2, 'en')
2911
- */
2912
-
2913
- }, {
2914
- key: "getFormattingRule",
2915
- value: function getFormattingRule(formattingRules, unit, value, _ref4) {
2916
- var future = _ref4.future;
2917
- // Passing the language is required in order to
2918
- // be able to correctly classify the `value` as a number.
2919
- this.locale;
2920
- formattingRules = formattingRules[unit]; // Check for a special "compacted" rules case:
2921
- // if formatting rules are the same for "past" and "future",
2922
- // and also for all possible `value`s, then those rules are
2923
- // stored as a single string.
2924
-
2925
- if (typeof formattingRules === 'string') {
2926
- return formattingRules;
2927
- } // Choose either "past" or "future" based on time `value` sign.
2928
- // If "past" is same as "future" then they're stored as "other".
2929
- // If there's only "other" then it's being collapsed.
2930
-
2931
-
2932
- var pastOrFuture = value === 0 ? future ? 'future' : 'past' : value < 0 ? 'past' : 'future';
2933
- var quantifierRules = formattingRules[pastOrFuture] || formattingRules; // Bundle size optimization technique.
2934
-
2935
- if (typeof quantifierRules === 'string') {
2936
- return quantifierRules;
2937
- } // Quantify `value`.
2938
-
2939
-
2940
- var quantifier = this.getPluralRules().select(Math.abs(value)); // "other" rule is supposed to always be present.
2941
- // If only "other" rule is present then "rules" is not an object and is a string.
2942
-
2943
- return quantifierRules[quantifier] || quantifierRules.other;
2944
- }
2945
- /**
2946
- * Formats a number into a string.
2947
- * Uses `Intl.NumberFormat` when available.
2948
- * @param {number} number
2949
- * @return {string}
2950
- */
2951
-
2952
- }, {
2953
- key: "formatNumber",
2954
- value: function formatNumber(number) {
2955
- return this.numberFormat ? this.numberFormat.format(number) : String(number);
2956
- }
2957
- /**
2958
- * Returns an `Intl.RelativeTimeFormat` for a given `labelsType`.
2959
- * @param {string} labelsType
2960
- * @return {object} `Intl.RelativeTimeFormat` instance
2961
- */
2962
-
2963
- }, {
2964
- key: "getFormatter",
2965
- value: function getFormatter(labelsType) {
2966
- // `Intl.RelativeTimeFormat` instance creation is (hypothetically) assumed
2967
- // a lengthy operation so the instances are cached and reused.
2968
- return this.relativeTimeFormatCache.get(this.locale, labelsType) || this.relativeTimeFormatCache.put(this.locale, labelsType, new this.IntlRelativeTimeFormat(this.locale, {
2969
- style: labelsType
2970
- }));
2971
- }
2972
- /**
2973
- * Returns an `Intl.PluralRules` instance.
2974
- * @return {object} `Intl.PluralRules` instance
2975
- */
2976
-
2977
- }, {
2978
- key: "getPluralRules",
2979
- value: function getPluralRules() {
2980
- // `Intl.PluralRules` instance creation is (hypothetically) assumed
2981
- // a lengthy operation so the instances are cached and reused.
2982
- return this.pluralRulesCache.get(this.locale) || this.pluralRulesCache.put(this.locale, new this.IntlPluralRules(this.locale));
2983
- }
2984
- /**
2985
- * Gets localized labels for this type of labels.
2986
- *
2987
- * @param {(string|string[])} labelsType - Relative date/time labels type.
2988
- * If it's an array then all label types are tried
2989
- * until a suitable one is found.
2990
- *
2991
- * @returns {Object} Returns an object of shape { labelsType, labels }
2992
- */
2993
-
2994
- }, {
2995
- key: "getLabels",
2996
- value: function getLabels() {
2997
- var labelsType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
2998
-
2999
- // Convert `labels` to an array.
3000
- if (typeof labelsType === 'string') {
3001
- labelsType = [labelsType];
3002
- } // Supports legacy "tiny" and "mini-time" label styles.
3003
-
3004
-
3005
- labelsType = labelsType.map(function (labelsType) {
3006
- switch (labelsType) {
3007
- case 'tiny':
3008
- case 'mini-time':
3009
- return 'mini';
3010
-
3011
- default:
3012
- return labelsType;
3013
- }
3014
- }); // "long" labels type is the default one.
3015
- // (it's always present for all languages)
3016
-
3017
- labelsType = labelsType.concat('long'); // Find a suitable labels type.
3018
-
3019
- var localeData = getLocaleData(this.locale);
3020
-
3021
- for (var _iterator = _createForOfIteratorHelperLoose(labelsType), _step; !(_step = _iterator()).done;) {
3022
- var _labelsType = _step.value;
3023
-
3024
- if (localeData[_labelsType]) {
3025
- return {
3026
- labelsType: _labelsType,
3027
- labels: localeData[_labelsType]
3028
- };
3029
- }
3030
- }
3031
- }
3032
- }]);
3033
-
3034
- return TimeAgo;
3035
- }();
3036
- var defaultLocale = 'en';
3037
- /**
3038
- * Gets default locale.
3039
- * @return {string} locale
3040
- */
3041
-
3042
- TimeAgo.getDefaultLocale = function () {
3043
- return defaultLocale;
3044
- };
3045
- /**
3046
- * Sets default locale.
3047
- * @param {string} locale
3048
- */
3049
-
3050
-
3051
- TimeAgo.setDefaultLocale = function (locale) {
3052
- return defaultLocale = locale;
3053
- };
3054
- /**
3055
- * Adds locale data for a specific locale and marks the locale as default.
3056
- * @param {Object} localeData
3057
- */
3058
-
3059
-
3060
- TimeAgo.addDefaultLocale = function (localeData) {
3061
- if (defaultLocaleHasBeenSpecified) {
3062
- return console.error('[javascript-time-ago] `TimeAgo.addDefaultLocale()` can only be called once. To add other locales, use `TimeAgo.addLocale()`.');
3063
- }
3064
-
3065
- defaultLocaleHasBeenSpecified = true;
3066
- TimeAgo.setDefaultLocale(localeData.locale);
3067
- TimeAgo.addLocale(localeData);
3068
- };
3069
-
3070
- var defaultLocaleHasBeenSpecified;
3071
- /**
3072
- * Adds locale data for a specific locale.
3073
- * @param {Object} localeData
3074
- */
3075
-
3076
- TimeAgo.addLocale = function (localeData) {
3077
- addLocaleData(localeData);
3078
- RelativeTimeFormat.addLocale(localeData);
3079
- };
3080
- /**
3081
- * (legacy alias)
3082
- * Adds locale data for a specific locale.
3083
- * @param {Object} localeData
3084
- * @deprecated
3085
- */
3086
-
3087
-
3088
- TimeAgo.locale = TimeAgo.addLocale;
3089
- /**
3090
- * Adds custom labels to locale data.
3091
- * @param {string} locale
3092
- * @param {string} name
3093
- * @param {object} labels
3094
- */
3095
-
3096
- TimeAgo.addLabels = function (locale, name, labels) {
3097
- var localeData = getLocaleData(locale);
3098
-
3099
- if (!localeData) {
3100
- addLocaleData({
3101
- locale: locale
3102
- });
3103
- localeData = getLocaleData(locale); // throw new Error(`[javascript-time-ago] No data for locale "${locale}"`)
3104
- }
3105
-
3106
- localeData[name] = labels;
3107
- }; // Normalizes `.format()` `time` argument.
3108
-
3109
-
3110
- function getTimestamp(input) {
3111
- if (input.constructor === Date || isMockedDate(input)) {
3112
- return input.getTime();
3113
- }
3114
-
3115
- if (typeof input === 'number') {
3116
- return input;
3117
- } // For some weird reason istanbul doesn't see this `throw` covered.
3118
-
3119
- /* istanbul ignore next */
3120
-
3121
-
3122
- throw new Error("Unsupported relative time formatter input: ".concat(_typeof(input), ", ").concat(input));
3123
- } // During testing via some testing libraries `Date`s aren't actually `Date`s.
3124
- // https://github.com/catamphetamine/javascript-time-ago/issues/22
3125
-
3126
-
3127
- function isMockedDate(object) {
3128
- return _typeof(object) === 'object' && typeof object.getTime === 'function';
3129
- } // Get available time interval measurement units.
3130
-
3131
-
3132
- function getTimeIntervalMeasurementUnits(allowedUnits, labels, nowLabel) {
3133
- // Get all time interval measurement units that're available
3134
- // in locale data for a given time labels style.
3135
- var units = Object.keys(labels); // `now` unit is handled separately and is shipped in its own `now.json` file.
3136
- // `now.json` isn't present for all locales, so it could be substituted with
3137
- // ".second.current".
3138
- // Add `now` unit if it's available in locale data.
3139
-
3140
- if (nowLabel) {
3141
- units.push('now');
3142
- } // If only a specific set of available time measurement units can be used
3143
- // then only those units are allowed (if they're present in locale data).
3144
-
3145
-
3146
- if (allowedUnits) {
3147
- units = allowedUnits.filter(function (unit) {
3148
- return unit === 'now' || units.indexOf(unit) >= 0;
3149
- });
3150
- }
3151
-
3152
- return units;
3153
- }
3154
-
3155
- function getNowLabel(labels, nowLabels, longLabels, future) {
3156
- var nowLabel = labels.now || nowLabels && nowLabels.now; // Specific "now" message form extended locale data (if present).
3157
-
3158
- if (nowLabel) {
3159
- // Bundle size optimization technique.
3160
- if (typeof nowLabel === 'string') {
3161
- return nowLabel;
3162
- } // Not handling `value === 0` as `localeData.now.current` here
3163
- // because it wouldn't make sense: "now" is a moment,
3164
- // so one can't possibly differentiate between a
3165
- // "previous" moment, a "current" moment and a "next moment".
3166
- // It can only be differentiated between "past" and "future".
3167
-
3168
-
3169
- if (future) {
3170
- return nowLabel.future;
3171
- } else {
3172
- return nowLabel.past;
3173
- }
3174
- } // Use ".second.current" as "now" message.
3175
-
3176
-
3177
- if (longLabels && longLabels.second && longLabels.second.current) {
3178
- return longLabels.second.current;
3179
- }
3180
- }
3181
-
3182
- function isStyle(variable) {
3183
- return typeof variable === 'string' || isStyleObject(variable);
3184
- }
3185
-
3186
- var en = {
3187
- "locale": "en",
3188
- "long": {
3189
- "year": {
3190
- "previous": "last year",
3191
- "current": "this year",
3192
- "next": "next year",
3193
- "past": {
3194
- "one": "{0} year ago",
3195
- "other": "{0} years ago"
3196
- },
3197
- "future": {
3198
- "one": "in {0} year",
3199
- "other": "in {0} years"
3200
- }
3201
- },
3202
- "quarter": {
3203
- "previous": "last quarter",
3204
- "current": "this quarter",
3205
- "next": "next quarter",
3206
- "past": {
3207
- "one": "{0} quarter ago",
3208
- "other": "{0} quarters ago"
3209
- },
3210
- "future": {
3211
- "one": "in {0} quarter",
3212
- "other": "in {0} quarters"
3213
- }
3214
- },
3215
- "month": {
3216
- "previous": "last month",
3217
- "current": "this month",
3218
- "next": "next month",
3219
- "past": {
3220
- "one": "{0} month ago",
3221
- "other": "{0} months ago"
3222
- },
3223
- "future": {
3224
- "one": "in {0} month",
3225
- "other": "in {0} months"
3226
- }
3227
- },
3228
- "week": {
3229
- "previous": "last week",
3230
- "current": "this week",
3231
- "next": "next week",
3232
- "past": {
3233
- "one": "{0} week ago",
3234
- "other": "{0} weeks ago"
3235
- },
3236
- "future": {
3237
- "one": "in {0} week",
3238
- "other": "in {0} weeks"
3239
- }
3240
- },
3241
- "day": {
3242
- "previous": "yesterday",
3243
- "current": "today",
3244
- "next": "tomorrow",
3245
- "past": {
3246
- "one": "{0} day ago",
3247
- "other": "{0} days ago"
3248
- },
3249
- "future": {
3250
- "one": "in {0} day",
3251
- "other": "in {0} days"
3252
- }
3253
- },
3254
- "hour": {
3255
- "current": "this hour",
3256
- "past": {
3257
- "one": "{0} hour ago",
3258
- "other": "{0} hours ago"
3259
- },
3260
- "future": {
3261
- "one": "in {0} hour",
3262
- "other": "in {0} hours"
3263
- }
3264
- },
3265
- "minute": {
3266
- "current": "this minute",
3267
- "past": {
3268
- "one": "{0} minute ago",
3269
- "other": "{0} minutes ago"
3270
- },
3271
- "future": {
3272
- "one": "in {0} minute",
3273
- "other": "in {0} minutes"
3274
- }
3275
- },
3276
- "second": {
3277
- "current": "now",
3278
- "past": {
3279
- "one": "{0} second ago",
3280
- "other": "{0} seconds ago"
3281
- },
3282
- "future": {
3283
- "one": "in {0} second",
3284
- "other": "in {0} seconds"
3285
- }
3286
- }
3287
- },
3288
- "short": {
3289
- "year": {
3290
- "previous": "last yr.",
3291
- "current": "this yr.",
3292
- "next": "next yr.",
3293
- "past": "{0} yr. ago",
3294
- "future": "in {0} yr."
3295
- },
3296
- "quarter": {
3297
- "previous": "last qtr.",
3298
- "current": "this qtr.",
3299
- "next": "next qtr.",
3300
- "past": {
3301
- "one": "{0} qtr. ago",
3302
- "other": "{0} qtrs. ago"
3303
- },
3304
- "future": {
3305
- "one": "in {0} qtr.",
3306
- "other": "in {0} qtrs."
3307
- }
3308
- },
3309
- "month": {
3310
- "previous": "last mo.",
3311
- "current": "this mo.",
3312
- "next": "next mo.",
3313
- "past": "{0} mo. ago",
3314
- "future": "in {0} mo."
3315
- },
3316
- "week": {
3317
- "previous": "last wk.",
3318
- "current": "this wk.",
3319
- "next": "next wk.",
3320
- "past": "{0} wk. ago",
3321
- "future": "in {0} wk."
3322
- },
3323
- "day": {
3324
- "previous": "yesterday",
3325
- "current": "today",
3326
- "next": "tomorrow",
3327
- "past": {
3328
- "one": "{0} day ago",
3329
- "other": "{0} days ago"
3330
- },
3331
- "future": {
3332
- "one": "in {0} day",
3333
- "other": "in {0} days"
3334
- }
3335
- },
3336
- "hour": {
3337
- "current": "this hour",
3338
- "past": "{0} hr. ago",
3339
- "future": "in {0} hr."
3340
- },
3341
- "minute": {
3342
- "current": "this minute",
3343
- "past": "{0} min. ago",
3344
- "future": "in {0} min."
3345
- },
3346
- "second": {
3347
- "current": "now",
3348
- "past": "{0} sec. ago",
3349
- "future": "in {0} sec."
3350
- }
3351
- },
3352
- "narrow": {
3353
- "year": {
3354
- "previous": "last yr.",
3355
- "current": "this yr.",
3356
- "next": "next yr.",
3357
- "past": "{0}y ago",
3358
- "future": "in {0}y"
3359
- },
3360
- "quarter": {
3361
- "previous": "last qtr.",
3362
- "current": "this qtr.",
3363
- "next": "next qtr.",
3364
- "past": "{0}q ago",
3365
- "future": "in {0}q"
3366
- },
3367
- "month": {
3368
- "previous": "last mo.",
3369
- "current": "this mo.",
3370
- "next": "next mo.",
3371
- "past": "{0}mo ago",
3372
- "future": "in {0}mo"
3373
- },
3374
- "week": {
3375
- "previous": "last wk.",
3376
- "current": "this wk.",
3377
- "next": "next wk.",
3378
- "past": "{0}w ago",
3379
- "future": "in {0}w"
3380
- },
3381
- "day": {
3382
- "previous": "yesterday",
3383
- "current": "today",
3384
- "next": "tomorrow",
3385
- "past": "{0}d ago",
3386
- "future": "in {0}d"
3387
- },
3388
- "hour": {
3389
- "current": "this hour",
3390
- "past": "{0}h ago",
3391
- "future": "in {0}h"
3392
- },
3393
- "minute": {
3394
- "current": "this minute",
3395
- "past": "{0}m ago",
3396
- "future": "in {0}m"
3397
- },
3398
- "second": {
3399
- "current": "now",
3400
- "past": "{0}s ago",
3401
- "future": "in {0}s"
3402
- }
3403
- },
3404
- "now": {
3405
- "now": {
3406
- "current": "now",
3407
- "future": "in a moment",
3408
- "past": "just now"
3409
- }
3410
- },
3411
- "mini": {
3412
- "year": "{0}yr",
3413
- "month": "{0}mo",
3414
- "week": "{0}wk",
3415
- "day": "{0}d",
3416
- "hour": "{0}h",
3417
- "minute": "{0}m",
3418
- "second": "{0}s",
3419
- "now": "now"
3420
- },
3421
- "short-time": {
3422
- "year": "{0} yr.",
3423
- "month": "{0} mo.",
3424
- "week": "{0} wk.",
3425
- "day": {
3426
- "one": "{0} day",
3427
- "other": "{0} days"
3428
- },
3429
- "hour": "{0} hr.",
3430
- "minute": "{0} min.",
3431
- "second": "{0} sec."
3432
- },
3433
- "long-time": {
3434
- "year": {
3435
- "one": "{0} year",
3436
- "other": "{0} years"
3437
- },
3438
- "month": {
3439
- "one": "{0} month",
3440
- "other": "{0} months"
3441
- },
3442
- "week": {
3443
- "one": "{0} week",
3444
- "other": "{0} weeks"
3445
- },
3446
- "day": {
3447
- "one": "{0} day",
3448
- "other": "{0} days"
3449
- },
3450
- "hour": {
3451
- "one": "{0} hour",
3452
- "other": "{0} hours"
3453
- },
3454
- "minute": {
3455
- "one": "{0} minute",
3456
- "other": "{0} minutes"
3457
- },
3458
- "second": {
3459
- "one": "{0} second",
3460
- "other": "{0} seconds"
3461
- }
3462
- }
3463
- };
3464
-
3465
- TimeAgo.addDefaultLocale(en);
3466
- const useTimeAgo = () => {
3467
- const timeAgo = new TimeAgo('en-US');
3468
- return timeAgo;
3469
- };
3470
-
3471
- const useTransition = ({ container, animateIn, animateOut, duration = 300 }) => {
3472
- const Animated = styled(container) `
3473
- animation-name: ${({ $isEntering, $isLeaving }) => ($isEntering ? animateIn : $isLeaving ? animateOut : 'none')};
3474
- animation-duration: ${duration}ms;
3475
- animation-fill-mode: forwards;
3476
- `;
3477
- // !! Do not deprecate this "useCallback" hook, it is necessary for the transition to work properly
3478
- const Transition = useCallback(({ children, enter, ...props }) => {
3479
- const [mounted, setMounted] = useState(false);
3480
- useEffect(() => {
3481
- const t = setTimeout(() => setMounted(enter), duration + 50); // +50ms to ensure the animation is finished
3482
- return () => clearTimeout(t);
3483
- }, [enter, duration]);
3484
- if (!enter && !mounted)
3485
- return null;
3486
- return (React.createElement(Animated, { "$isEntering": enter, "$isLeaving": !enter && mounted, ...props }, children));
3487
- },
3488
- // !! Do not add dependencies here, it will cause re-renders which we want to avoid
3489
- []);
3490
- return Transition;
3491
- };
3492
-
3493
- export { useCopy as a, useGenericForm as b, useInstrumentationRuleFormData as c, useKeyDown as d, useOnClickOutside as e, useTimeAgo as f, useTransition as g, useContainerSize as u };