="time-since" title="Sat, 16 Sep 2023 07:03:00 UTC">2 years ago lowerFirst.js 30f7226d9a first commit 2 years ago lt.js 30f7226d9a first commit 2 years ago lte.js 30f7226d9a first commit 2 years ago map.js 30f7226d9a first commit 2 years ago mapKeys.js 30f7226d9a first commit 2 years ago mapValues.js 30f7226d9a first commit 2 years ago matches.js 30f7226d9a first commit 2 years ago matchesProperty.js 30f7226d9a first commit 2 years ago math.js 30f7226d9a first commit 2 years ago max.js 30f7226d9a first commit 2 years ago maxBy.js 30f7226d9a first commit 2 years ago mean.js 30f7226d9a first commit 2 years ago meanBy.js 30f7226d9a first commit 2 years ago memoize.js 30f7226d9a first commit 2 years ago merge.js 30f7226d9a first commit 2 years ago mergeWith.js 30f7226d9a first commit 2 years ago method.js 30f7226d9a first commit 2 years ago methodOf.js 30f7226d9a first commit 2 years ago min.js 30f7226d9a first commit 2 years ago minBy.js 30f7226d9a first commit 2 years ago mixin.js 30f7226d9a first commit 2 years ago multiply.js 30f7226d9a first commit 2 years ago negate.js 30f7226d9a first commit 2 years ago next.js 30f7226d9a first commit 2 years ago noop.js 30f7226d9a first commit 2 years ago now.js 30f7226d9a first commit 2 years ago nth.js 30f7226d9a first commit 2 years ago nthArg.js 30f7226d9a first commit 2 years ago number.js 30f7226d9a first commit 2 years ago object.js 30f7226d9a first commit 2 years ago omit.js 30f7226d9a first commit 2 years ago omitBy.js 30f7226d9a first commit 2 years ago once.js 30f7226d9a first commit 2 years ago orderBy.js 30f7226d9a first commit 2 years ago over.js 30f7226d9a first commit 2 years ago overArgs.js 30f7226d9a first commit 2 years ago overEvery.js 30f7226d9a first commit 2 years ago overSome.js 30f7226d9a first commit 2 years ago package.json 30f7226d9a first commit 2 years ago pad.js 30f7226d9a first commit 2 years ago padEnd.js 30f7226d9a first commit 2 years ago padStart.js 30f7226d9a first commit 2 years ago parseInt.js 30f7226d9a first commit 2 years ago partial.js 30f7226d9a first commit 2 years ago partialRight.js 30f7226d9a first commit 2 years ago partition.js 30f7226d9a first commit 2 years ago pick.js 30f7226d9a first commit 2 years ago pickBy.js 30f7226d9a first commit 2 years ago plant.js 30f7226d9a first commit 2 years ago property.js 30f7226d9a first commit 2 years ago propertyOf.js 30f7226d9a first commit 2 years ago pull.js 30f7226d9a first commit 2 years ago pullAll.js 30f7226d9a first commit 2 years ago pullAllBy.js 30f7226d9a first commit 2 years ago pullAllWith.js 30f7226d9a first commit 2 years ago pullAt.js 30f7226d9a first commit 2 years ago random.js 30f7226d9a first commit 2 years ago range.js 30f7226d9a first commit 2 years ago rangeRight.js 30f7226d9a first commit 2 years ago rearg.js 30f7226d9a first commit 2 years ago reduce.js 30f7226d9a first commit 2 years ago reduceRight.js 30f7226d9a first commit 2 years ago reject.js 30f7226d9a first commit 2 years ago release.md 30f7226d9a first commit 2 years ago remove.js 30f7226d9a first commit 2 years ago repeat.js 30f7226d9a first commit 2 years ago replace.js 30f7226d9a first commit 2 years ago rest.js 30f7226d9a first commit 2 years ago result.js 30f7226d9a first commit 2 years ago reverse.js 30f7226d9a first commit 2 years ago round.js 30f7226d9a first commit 2 years ago sample.js 30f7226d9a first commit 2 years ago sampleSize.js 30f7226d9a first commit 2 years ago seq.js 30f7226d9a first commit 2 years ago set.js 30f7226d9a first commit 2 years ago setWith.js 30f7226d9a first commit 2 years ago shuffle.js 30f7226d9a first commit 2 years ago size.js 30f7226d9a first commit 2 years ago slice.js 30f7226d9a first commit 2 years ago snakeCase.js 30f7226d9a first commit 2 years ago some.js 30f7226d9a first commit 2 years ago sortBy.js 30f7226d9a first commit 2 years ago sortedIndex.js 30f7226d9a first commit 2 years ago sortedIndexBy.js 30f7226d9a first commit 2 years ago sortedIndexOf.js 30f7226d9a first commit 2 years ago sortedLastIndex.js 30f7226d9a first commit 2 years ago sortedLastIndexBy.js 30f7226d9a first commit 2 years ago sortedLastIndexOf.js 30f7226d9a first commit 2 years ago sortedUniq.js 30f7226d9a first commit 2 years ago sortedUniqBy.js 30f7226d9a first commit 2 years ago split.js 30f7226d9a first commit 2 years ago spread.js 30f7226d9a first commit 2 years ago startCase.js 30f7226d9a first commit 2 years ago startsWith.js 30f7226d9a first commit 2 years ago string.js 30f7226d9a first commit 2 years ago stubArray.js 30f7226d9a first commit 2 years ago stubFalse.js 30f7226d9a first commit 2 years ago stubObject.js 30f7226d9a first commit 2 years ago stubString.js 30f7226d9a first commit 2 years ago stubTrue.js 30f7226d9a first commit 2 years ago subtract.js 30f7226d9a first commit 2 years ago sum.js 30f7226d9a first commit 2 years ago sumBy.js 30f7226d9a first commit 2 years ago tail.js 30f7226d9a first commit 2 years ago take.js 30f7226d9a first commit 2 years ago takeRight.js 30f7226d9a first commit 2 years ago takeRightWhile.js 30f7226d9a first commit 2 years ago takeWhile.js 30f7226d9a first commit 2 years ago tap.js 30f7226d9a first commit 2 years ago template.js 30f7226d9a first commit 2 years ago templateSettings.js 30f7226d9a first commit 2 years ago throttle.js 30f7226d9a first commit 2 years ago thru.js 30f7226d9a first commit 2 years ago times.js 30f7226d9a first commit 2 years ago toArray.js 30f7226d9a first commit 2 years ago toFinite.js 30f7226d9a first commit 2 years ago toInteger.js 30f7226d9a first commit 2 years ago toIterator.js 30f7226d9a first commit 2 years ago toJSON.js 30f7226d9a first commit 2 years ago toLength.js 30f7226d9a first commit 2 years ago toLower.js 30f7226d9a first commit 2 years ago toNumber.js 30f7226d9a first commit 2 years ago toPairs.js 30f7226d9a first commit 2 years ago toPairsIn.js 30f7226d9a first commit 2 years ago toPath.js 30f7226d9a first commit 2 years ago toPlainObject.js 30f7226d9a first commit 2 years ago toSafeInteger.js 30f7226d9a first commit 2 years ago toString.js 30f7226d9a first commit 2 years ago toUpper.js 30f7226d9a first commit 2 years ago transform.js 30f7226d9a first commit 2 years ago trim.js 30f7226d9a first commit 2 years ago trimEnd.js 30f7226d9a first commit 2 years ago trimStart.js 30f7226d9a first commit 2 years ago truncate.js 30f7226d9a first commit 2 years ago unary.js 30f7226d9a first commit 2 years ago unescape.js 30f7226d9a first commit 2 years ago union.js 30f7226d9a first commit 2 years ago unionBy.js 30f7226d9a first commit 2 years ago unionWith.js 30f7226d9a first commit 2 years ago uniq.js 30f7226d9a first commit 2 years ago uniqBy.js 30f7226d9a first commit 2 years ago uniqWith.js 30f7226d9a first commit 2 years ago uniqueId.js 30f7226d9a first commit 2 years ago unset.js 30f7226d9a first commit 2 years ago unzip.js 30f7226d9a first commit 2 years ago unzipWith.js 30f7226d9a first commit 2 years ago update.js 30f7226d9a first commit 2 years ago updateWith.js 30f7226d9a first commit 2 years ago upperCase.js 30f7226d9a first commit 2 years ago upperFirst.js 30f7226d9a first commit 2 years ago util.js 30f7226d9a first commit 2 years ago value.js 30f7226d9a first commit 2 years ago valueOf.js 30f7226d9a first commit 2 years ago values.js 30f7226d9a first commit 2 years ago valuesIn.js 30f7226d9a first commit 2 years ago without.js 30f7226d9a first commit 2 years ago words.js 30f7226d9a first commit 2 years ago wrap.js 30f7226d9a first commit 2 years ago wrapperAt.js 30f7226d9a first commit 2 years ago wrapperChain.js 30f7226d9a first commit 2 years ago wrapperLodash.js 30f7226d9a first commit 2 years ago wrapperReverse.js 30f7226d9a first commit 2 years ago wrapperValue.js 30f7226d9a first commit 2 years ago xor.js 30f7226d9a first commit 2 years ago xorBy.js 30f7226d9a first commit 2 years ago xorWith.js 30f7226d9a first commit 2 years ago zip.js 30f7226d9a first commit 2 years ago zipObject.js 30f7226d9a first commit 2 years ago zipObjectDeep.js 30f7226d9a first commit 2 years ago zipWith.js 30f7226d9a first commit 2 years ago

README.md

lodash v4.17.21

The Lodash library exported as Node.js modules.

Installation

Using npm:

$ npm i -g npm
$ npm i --save lodash

In Node.js:

// Load the full build.
var _ = require('lodash');
// Load the core build.
var _ = require('lodash/core');
// Load the FP build for immutable auto-curried iteratee-first data-last methods.
var fp = require('lodash/fp');

// Load method categories.
var array = require('lodash/array');
var object = require('lodash/fp/object');

// Cherry-pick methods for smaller browserify/rollup/webpack bundles.
var at = require('lodash/at');
var curryN = require('lodash/fp/curryN');

See the package source for more details.

Note:
Install n_ for Lodash use in the Node.js < 6 REPL.

Support

Tested in Chrome 74-75, Firefox 66-67, IE 11, Edge 18, Safari 11-12, & Node.js 8-12.
Automated browser & CI test runs are available.

golf/tge - Gogs: Simplico Git Service

Keine Beschreibung

YAMLMap.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. 'use strict';
  2. var stringifyCollection = require('../stringify/stringifyCollection.js');
  3. var addPairToJSMap = require('./addPairToJSMap.js');
  4. var Collection = require('./Collection.js');
  5. var Node = require('./Node.js');
  6. var Pair = require('./Pair.js');
  7. var Scalar = require('./Scalar.js');
  8. function findPair(items, key) {
  9. const k = Node.isScalar(key) ? key.value : key;
  10. for (const it of items) {
  11. if (Node.isPair(it)) {
  12. if (it.key === key || it.key === k)
  13. return it;
  14. if (Node.isScalar(it.key) && it.key.value === k)
  15. return it;
  16. }
  17. }
  18. return undefined;
  19. }
  20. class YAMLMap extends Collection.Collection {
  21. static get tagName() {
  22. return 'tag:yaml.org,2002:map';
  23. }
  24. constructor(schema) {
  25. super(Node.MAP, schema);
  26. this.items = [];
  27. }
  28. /**
  29. * Adds a value to the collection.
  30. *
  31. * @param overwrite - If not set `true`, using a key that is already in the
  32. * collection will throw. Otherwise, overwrites the previous value.
  33. */
  34. add(pair, overwrite) {
  35. let _pair;
  36. if (Node.isPair(pair))
  37. _pair = pair;
  38. else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
  39. // In TypeScript, this never happens.
  40. _pair = new Pair.Pair(pair, pair?.value);
  41. }
  42. else
  43. _pair = new Pair.Pair(pair.key, pair.value);
  44. const prev = findPair(this.items, _pair.key);
  45. const sortEntries = this.schema?.sortMapEntries;
  46. if (prev) {
  47. if (!overwrite)
  48. throw new Error(`Key ${_pair.key} already set`);
  49. // For scalars, keep the old node & its comments and anchors
  50. if (Node.isScalar(prev.value) && Scalar.isScalarValue(_pair.value))
  51. prev.value.value = _pair.value;
  52. else
  53. prev.value = _pair.value;
  54. }
  55. else if (sortEntries) {
  56. const i = this.items.findIndex(item => sortEntries(_pair, item) < 0);
  57. if (i === -1)
  58. this.items.push(_pair);
  59. else
  60. this.items.splice(i, 0, _pair);
  61. }
  62. else {
  63. this.items.push(_pair);
  64. }
  65. }
  66. delete(key) {
  67. const it = findPair(this.items, key);
  68. if (!it)
  69. return false;
  70. const del = this.items.splice(this.items.indexOf(it), 1);
  71. return del.length > 0;
  72. }
  73. get(key, keepScalar) {
  74. const it = findPair(this.items, key);
  75. const node = it?.value;
  76. return (!keepScalar && Node.isScalar(node) ? node.value : node) ?? undefined;
  77. }
  78. has(key) {
  79. return !!findPair(this.items, key);
  80. }
  81. set(key, value) {
  82. this.add(new Pair.Pair(key, value), true);
  83. }
  84. /**
  85. * @param ctx - Conversion context, originally set in Document#toJS()
  86. * @param {Class} Type - If set, forces the returned collection type
  87. * @returns Instance of Type, Map, or Object
  88. */
  89. toJSON(_, ctx, Type) {
  90. const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};
  91. if (ctx?.onCreate)
  92. ctx.onCreate(map);
  93. for (const item of this.items)
  94. addPairToJSMap.addPairToJSMap(ctx, map, item);
  95. return map;
  96. }
  97. toString(ctx, onComment, onChompKeep) {
  98. if (!ctx)
  99. return JSON.stringify(this);
  100. for (const item of this.items) {
  101. if (!Node.isPair(item))
  102. throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
  103. }
  104. if (!ctx.allNullValues && this.hasAllNullValues(false))
  105. ctx = Object.assign({}, ctx, { allNullValues: true });
  106. return stringifyCollection.stringifyCollection(this, ctx, {
  107. blockItemPrefix: '',
  108. flowChars: { start: '{', end: '}' },
  109. itemIndent: ctx.indent || '',
  110. onChompKeep,
  111. onComment
  112. });
  113. }
  114. }
  115. exports.YAMLMap = YAMLMap;
  116. exports.findPair = findPair;