How to use utf8-byte-length - 7 common examples

To help you get started, we’ve selected a few utf8-byte-length 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 Netflix / pollyjs / packages / @pollyjs / persister / src / har / request.js View on Github external
const keys = [];
  const values = [];

  request.headers.forEach(({ name, value }) => {
    keys.push(name);
    values.push(value);
  });

  const headersString =
    request.method + request.url + keys.join() + values.join();

  // startline: [method] [url] HTTP/1.1\r\n = 12
  // endline: \r\n = 2
  // every header + \r\n = * 2
  // add 2 for each combined header
  return getByteLength(headersString) + keys.length * 2 + 2 + 12 + 2;
}
github Netflix / pollyjs / packages / @pollyjs / persister / src / har / response.js View on Github external
function headersSize(response) {
  const keys = [];
  const values = [];

  response.headers.forEach(({ name, value }) => {
    keys.push(name);
    values.push(value);
  });

  const headersString = keys.join() + values.join();

  // endline: \r\n = 2
  // every header + \r\n = * 2
  // add 2 for each combined header
  return getByteLength(headersString) + keys.length * 2 + 2 + 2;
}
github TylerBarnes / wordsby / src / components / InstantPublish / index.js View on Github external
const limit = 1024 * 1024 * 5; // 5 MB
    const usedSpace = unescape(
      encodeURIComponent(JSON.stringify(sessionStorage))
    ).length;
    const remSpace = limit - usedSpace;

    this.log(`session storage bytes in use: ${usedSpace}`);
    this.log(`remaining bytes available: ${remSpace}`);

    // get a string of our data.
    const jsonString = JSON.stringify({
      data: { wordsbyCollections: liveData },
      latestPublishTime: latestPublishTime
    });

    const dataLength = getLength(jsonString);

    // if our string takes more storage than what's left, clear the storage
    if (dataLength > remSpace) sessionStorage.clear();

    // store data in session storage so that reloads dont require more http requests.
    sessionStorage.setItem(storageName, jsonString);
    this.log(`session data stored in key: ${storageName}`);
  }
github Tencent / bk-cmdb / src / ui / src / setup / validate.js View on Github external
validate: (value) => {
            const nameList = value.split('\n').filter(name => name)
            for (const name of nameList) {
                if (stringLength(name) > 256) return false
            }
            return true
        }
    },
github Netflix / pollyjs / packages / @pollyjs / persister / src / har / response.js View on Github external
this.content = {
      mimeType: getFirstHeader(response, 'Content-Type') || 'text/plain'
    };

    if (response.body && typeof response.body === 'string') {
      this.content.text = response.body;
    }

    const contentLength = getFirstHeader(response, 'Content-Length');

    if (contentLength) {
      this.content.size = parseInt(contentLength, 10);
    } else {
      this.content.size = this.content.text
        ? getByteLength(this.content.text)
        : 0;
    }

    this.bodySize = this.content.size;
  }
}
github Netflix / pollyjs / packages / @pollyjs / persister / src / har / request.js View on Github external
params: []
      };

      if (typeof request.body === 'string') {
        this.postData.text = request.body;
      }
    }

    const contentLength = getFirstHeader(request, 'Content-Length');

    if (contentLength) {
      this.bodySize = parseInt(contentLength, 10);
    } else {
      this.bodySize =
        this.postData && this.postData.text
          ? getByteLength(this.postData.text)
          : 0;
    }
  }
}
github Tencent / bk-cmdb / src / ui / src / setup / validate.js View on Github external
validate: (value, [length]) => {
            return stringLength(value) <= length
        }
    },

utf8-byte-length

Get utf8 byte length of string

WTFPL
Latest version published 7 months ago

Package Health Score

73 / 100
Full package analysis

Popular utf8-byte-length functions