How to use stable - 10 common examples

To help you get started, we’ve selected a few stable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chanzuckerberg / czi-prosemirror / src / patchStyleElements.js View on Github external
if (selectorText.indexOf(',') > -1) {
        selectorText.split(/\s*,\s*/).forEach(st => {
          buildSelectorTextToCSSText(selectorTextToCSSTexts, st, cssText);
        });
      } else {
        buildSelectorTextToCSSText(
          selectorTextToCSSTexts,
          selectorText,
          cssText
        );
      }
    });
  });

  // Sort selector by
  stable(selectorTextToCSSTexts, sortBySpecificity)
    .reduce(buildElementToCSSTexts.bind(null, doc), new Map())
    .forEach(applyInlineStyleSheetCSSTexts);
}
github godaddy / kubernetes-client / examples / using-crds.js View on Github external
//
    // Create the CRD with the Kubernetes API
    //
    const create = await client.apis['apiextensions.k8s.io'].v1beta1.customresourcedefinitions.post({ body: crd })
    console.log('Create: ', create)

    //
    // Add endpoints to our client
    //
    client.addCustomResourceDefinition(crd)

    //
    // List all the resources of the new type
    //
    const all = await client.apis['stable.example.com'].v1.namespaces('default').crontabs.get()
    console.log('All: ', all)

    //
    // Get a specific resources.
    //
    const one = await client.apis['stable.example.com'].v1.namespaces('default').crontabs('foo').get()
    console.log('One: ', one)
  } catch (err) {
    console.error('Error: ', err)
  }
}
github strongloop / loopback-workspace / common / models / middleware.js View on Github external
// Find regular middleware entries
    const middleware = instances.filter(function(m) {
      return !m.isPhasePlaceHolder;
    });

    // Sort the entries to keep the order
    stableSortInPlace(phases, compareByOrder);

    // Build a map for phase orders (phaseName --> phaseOrder)
    const phaseOrders = {};
    phases.forEach(function(p) {
      phaseOrders[p.phase] = p.order;
    });

    stableSortInPlace(middleware, function(m1, m2) {
      // First by phase
      let delta = phaseOrders[m1.phase] - phaseOrders[m2.phase];
      if (delta !== 0) return (delta > 0 ? 1 : -1);
      // by subPhase
      delta = compareBySubPhase(m1, m2);
      if (delta !== 0) return (delta > 0 ? 1 : -1);
      // By order
      return compareByOrder(m1, m2);
    });
    return {
      phases: phases,
      middleware: middleware,
    };
  }
github xivanalysis / xivanalysis / src / parser / core / modules / AdditionalEvents.js View on Github external
const playerIds = [
			this.parser.player.guid,
			...this.parser.player.pets.map(pet => pet.guid),
		].join(',')
		filter =  `(${filter}) and source.id not in (${playerIds})`

		// Request the new events
		const newEvents = await getFflogsEvents(
			this.parser.report.code,
			this.parser.fight,
			{filter},
		)

		// Add them onto the end, then sort. Using stable to ensure order is kept, as it can be sensitive sometimes.
		events.push(...newEvents)
		stable.inplace(events, (a, b) => {
			if (a.timestamp === b.timestamp) {
				const aTypeOrder = EVENT_TYPE_ORDER[a.type] || EVENT_TYPE_ORDER.default
				const bTypeOrder = EVENT_TYPE_ORDER[b.type] || EVENT_TYPE_ORDER.default
				return aTypeOrder - bTypeOrder
			}
			return a.timestamp - b.timestamp
		})

		return events
	}
}
github strongloop / loopback / lib / server-app.js View on Github external
proto._sortLayersByPhase = function() {
  if (this._skipLayerSorting) return;

  const phaseOrder = {};
  this._requestHandlingPhases.forEach(function(name, ix) {
    phaseOrder[name + ':before'] = ix * 3;
    phaseOrder[name] = ix * 3 + 1;
    phaseOrder[name + ':after'] = ix * 3 + 2;
  });

  const router = this._router;
  stableSortInPlace(router.stack, compareLayers);

  function compareLayers(left, right) {
    const leftPhase = left.phase;
    const rightPhase = right.phase;

    if (leftPhase === rightPhase) return 0;

    // Builtin middleware is always first
    if (leftPhase === BUILTIN_MIDDLEWARE) return -1;
    if (rightPhase === BUILTIN_MIDDLEWARE) return 1;

    // Layers registered via app.use and app.route
    // are executed as the first items in `routes` phase
    if (leftPhase === undefined) {
      if (rightPhase === 'routes')
        return -1;
github pelias / api / middleware / sortResponseData.js View on Github external
function middleware(req, res, next) {
    // bail early if req/res don't pass conditions for execution or there's no data to sort
    if (!should_execute(req, res) || _.isEmpty(res.data)) {
      return next();
    }

    // capture the pre-sort order
    const presort_order = res.data.map(_.property('_id'));

    // stable operates on array in place
    stable.inplace(res.data, comparator(req.clean));

    // capture the post-sort order
    const postsort_order = res.data.map(_.property('_id'));

    // log it for debugging purposes
    logger.debug([
      `req.clean: ${JSON.stringify(req.clean)}`,
      `pre-sort: [${presort_order}]`,
      `post-sort: [${postsort_order}]`
    ].join(', '));

    next();
  }
github thegazelle-ad / gazelle-server / src / lib / db.js View on Github external
// eslint-disable-next-line no-param-reassign
                  currentPost.categoryInCommon =
                    currentPost.category_id === post.category_id;
                });

                const ranking = Object.keys(articles).filter(
                  currentSlug =>
                    articles[currentSlug].issue_id === latestIssueId &&
                    currentSlug !== post.slug,
                );
                if (ranking.length < 3) {
                  throw new Error(
                    'Less than three articles to qualify as related articles',
                  );
                }
                stable.inplace(ranking, (slugA, slugB) => {
                  const a = articles[slugA];
                  const b = articles[slugB];
                  if (a.tagsInCommon !== b.tagsInCommon) {
                    // This puts a before b if a has more tags in common
                    return b.tagsInCommon - a.tagsInCommon;
                  }
                  if (a.categoryInCommon !== b.categoryInCommon) {
                    if (a.categoryInCommon) {
                      return -1;
                    }
                    return 1;
                  }
                  return 0;
                });
                // since the sort is stable we know we should always get the
                // same values, also if there are no articles with related tags
github xivanalysis / xivanalysis / src / components / Analyse / pipeline / mergeEvents.ts View on Github external
export function mergeEvents(existing: Fflogs.Event[], incoming: Fflogs.Event[]) {
	// Create a new array with the incoming events at the end
	const events = existing.concat(incoming)

	// Sort them in place
	stable.inplace(events, (a, b) => {
		if (a.timestamp === b.timestamp) {
			const aTypeOrder = EVENT_TYPE_ORDER[a.type as string] || EVENT_TYPE_ORDER.default
			const bTypeOrder = EVENT_TYPE_ORDER[b.type as string] || EVENT_TYPE_ORDER.default
			return aTypeOrder - bTypeOrder
		}
		return a.timestamp - b.timestamp
	})

	return events
}
github strongloop / loopback-workspace / common / models / middleware.js View on Github external
function sortMiddleware(instances) {
    // Find all phases
    const phases = instances.filter(function(m) {
      return m.isPhasePlaceHolder;
    });

    // Find regular middleware entries
    const middleware = instances.filter(function(m) {
      return !m.isPhasePlaceHolder;
    });

    // Sort the entries to keep the order
    stableSortInPlace(phases, compareByOrder);

    // Build a map for phase orders (phaseName --> phaseOrder)
    const phaseOrders = {};
    phases.forEach(function(p) {
      phaseOrders[p.phase] = p.order;
    });

    stableSortInPlace(middleware, function(m1, m2) {
      // First by phase
      let delta = phaseOrders[m1.phase] - phaseOrders[m2.phase];
      if (delta !== 0) return (delta > 0 ? 1 : -1);
      // by subPhase
      delta = compareBySubPhase(m1, m2);
      if (delta !== 0) return (delta > 0 ? 1 : -1);
      // By order
      return compareByOrder(m1, m2);
github Opentrons / opentrons / discovery-client / src / service-list.js View on Github external
result.seenIps[ip] = true
      result.unique.push(cleanedService)

      return result
    },
    { unique: [], seenIps: {} }
  ).unique

  const dedupedWithoutIp = differenceBy(
    uniqBy(listWithoutIp, 'name'),
    sanitizedWithIp,
    'name'
  )

  // use a stable sort because core-js polyfills can mess with Array.sort order
  return stableSort(sanitizedWithIp.concat(dedupedWithoutIp), compareServices)
}

stable

A stable array sort for JavaScript

MIT
Latest version published 7 years ago

Package Health Score

55 / 100
Full package analysis